Package 'apaText'

Title: Create R Markdown Text for Results in the Style of the American Psychological Association (APA)
Description: Create APA style text from analyses for use within R Markdown documents. Descriptive statistics, confidence intervals, and cell sizes are reported.
Authors: David Stanley [aut, cre]
Maintainer: David Stanley <[email protected]>
License: MIT License + file LICENSE
Version: 0.1.7
Built: 2025-02-13 02:41:14 UTC
Source: https://github.com/dstanley4/apatext

Help Index


Report descriptive statistics for a set of values

Description

Report descriptive statistics for a set of values

Usage

apa.desc(
  .data,
  .dv = NULL,
  show.mean = NULL,
  show.sd = NULL,
  show.se = NULL,
  show.conf.interval = NULL,
  show.N = NULL,
  number.decimals = NULL
)

Arguments

.data

A data frame or data frame extension (e.g., tibble)

.dv

Name of the dependent variable column

show.mean

Show mean (Bool. Default TRUE)

show.sd

Show standard deviation (Bool. Default TRUE)

show.se

Show standard error (Bool. Default FALSE)

show.conf.interval

Show confidence interval (Bool. Default TRUE)

show.N

Show number of cases (Bool. Default TRUE)

number.decimals

Number of decimals in output

Value

R Markdown text

Examples

# 2-way ANOVA Example
if  (requireNamespace("apaTables", quietly = TRUE)){
    library(dplyr)
    goggles <- apaTables::goggles

    #Main Effect Means: Gender
    goggles %>% filter(gender == "Female") %>% apa.desc(attractiveness)
    goggles %>% filter(gender == "Male") %>% apa.desc(attractiveness)

    # Main Effect Means: Alcohol
    goggles %>% filter(alcohol == "None") %>% apa.desc(attractiveness)
    goggles %>% filter(alcohol == "2 Pints") %>% apa.desc(attractiveness)
    goggles %>% filter(alcohol == "4 Pints") %>% apa.desc(attractiveness)

    # Single Cell Mean
    goggles %>% filter(alcohol == "4 Pints", gender == "Female") %>%
                apa.desc(attractiveness)
}

Report descriptive statistics for a set of values

Description

Report descriptive statistics for a set of values

Usage

apa.ind.t.test(
  .data,
  .iv,
  .dv,
  bonferroni.multiplier = 1,
  show.mean.difference = TRUE,
  show.statistic = NULL,
  show.conf.interval = NULL,
  number.decimals = NULL,
  number.decimals.p = NULL,
  var.equal = TRUE,
  one.sided = FALSE
)

Arguments

.data

A data frame or data frame extension (e.g., tibble)

.iv

Name of the independent variable column (only 2 levels)

.dv

Name of the dependent variable column

bonferroni.multiplier

Multiply the p-value by this number to make a bonferroni adjustment

show.mean.difference

Show mean difference (Bool. Default TRUE)

show.statistic

Show t-value (Bool. Default TRUE)

show.conf.interval

Show CI for mean difference (Bool. Default TRUE)

number.decimals

Number of decimals used in output (excluding p-value)

number.decimals.p

Number of decimals used in p-value output

var.equal

(boolean) TRUE or FALSE for cell equal variances

one.sided

(boolean) TRUE or FALSE for conducting a one-sided test

Value

R Markdown text

Examples

if  (requireNamespace("apaTables", quietly = TRUE)){
    library(dplyr)
    goggles <- apaTables::goggles

    # one-sided test
    goggles %>%
      filter(alcohol == "None") %>%
      filter(gender == "Female" | gender == "Male") %>%
      apa.ind.t.test(gender, attractiveness,
                     var.equal = TRUE, one.sided = TRUE)
    #two-sided test
    goggles %>%
      filter(alcohol == "None") %>%
      filter(gender == "Female" | gender == "Male") %>%
      apa.ind.t.test(gender, attractiveness,
                      var.equal = TRUE, one.sided = FALSE)

    #two-sided test with Bonferroni correction (three exploratory tests)
    goggles %>%
      filter(alcohol == "None") %>%
      filter(gender == "Female" | gender == "Male") %>%
      apa.ind.t.test(gender, attractiveness,
                     var.equal = TRUE, one.sided = FALSE,
                      bonferroni.multiplier = 3)
 }

Report r(x,y) correlation in markdown APA style

Description

Report r(x,y) correlation in markdown APA style

Usage

apa.r(
  .data,
  .x,
  .y,
  alternative = "two.sided",
  method = "pearson",
  show.r = TRUE,
  show.conf.interval = NULL,
  show.N = NULL,
  show.p = NULL,
  show.statistic = NULL,
  number.decimals = NULL,
  number.decimals.p = NULL
)

Arguments

.data

A data frame or data frame extension (e.g., tibble)

.x

Name of column in data frame

.y

Name of column in data frame

alternative

Alternative hypothesis to pass to alternative argument of cor.test. Default is "two.sided"

method

Calculation method to pass to alternative argument of cor.test. Default is "pearson"

show.r

Show correlation or not (TRUE/FALSE)

show.conf.interval

Show confidence interval or not (TRUE/FALSE). Default behavior is TRUE.

show.N

Show sample size or not (TRUE/FALSE). Default behavior is TRUE.

show.p

Show p-value or not (TRUE/FALSE). Default behavior is TRUE.

show.statistic

Show test statistic or not (TRUE/FALSE). Default behavior is TRUE.

number.decimals

Number of decimals used in output (excluding p-value)

number.decimals.p

Number of decimals used in output for p-value

Value

R Markdown text

Examples

library(dplyr)
attitude %>% apa.r(rating, advance)

Report difference between correlations in markdown APA style from different samples

Description

Report difference between correlations in markdown APA style from different samples

Usage

apa.r.compare.across.samples(
  formula,
  data1,
  data2,
  alternative = "two.sided",
  show.conf.interval = NULL,
  show.N = NULL,
  show.p = NULL,
  show.statistic = NULL
)

Arguments

formula

Formula for comparing correlations

data1

Project data frame 1 name

data2

Project data frame 2 name

alternative

Alternative hypothesis to pass to alternative argument of cocor.indep.groups. Default is "two.sided"

show.conf.interval

Show confidence interval or not (TRUE/FALSE). Default behavior is TRUE.

show.N

Show sample size or not (TRUE/FALSE). Default behavior is TRUE.

show.p

Show p-value or not (TRUE/FALSE). Default behavior is TRUE.

show.statistic

Show test statistic or not (TRUE/FALSE). Default behavior is TRUE.

Value

R Markdown text

Examples

# Test difference between r(rating, learning) from dataset: attitude
# and r(weight, height) from dataset: women

apa.r.compare.across.samples(formula = ~ rating + learning | height + weight,
                             data1 = attitude,
                             data2 = women)

Report difference between correlations in markdown APA style from different samples

Description

Report difference between correlations in markdown APA style from different samples

Usage

apa.r.compare.across.samples.from.descriptive(
  r1,
  r2,
  n1,
  n2,
  alternative = "two.sided",
  show.conf.interval = NULL,
  show.N = NULL,
  show.p = NULL,
  show.statistic = NULL
)

Arguments

r1

Correlation in sample 1

r2

Correlation in sample 2

n1

Sample size for sample 1

n2

Sample size for sample 2

alternative

Alternative hypothesis to pass to alternative argument of cocor.indep.groups. Default is "two.sided"

show.conf.interval

Show confidence interval or not (TRUE/FALSE). Default behavior is TRUE.

show.N

Show sample size or not (TRUE/FALSE). Default behavior is TRUE.

show.p

Show p-value or not (TRUE/FALSE). Default behavior is TRUE.

show.statistic

Show test statistic or not (TRUE/FALSE). Default behavior is TRUE.

Value

R Markdown text

Examples

apa.r.compare.across.samples.from.descriptive(r1 = .3, r2 =.6, n1 = 70, n2 =80)

Report difference in markdown APA style between between correlations within a sample

Description

Report difference in markdown APA style between between correlations within a sample

Usage

apa.r.compare.within.sample(
  formula,
  data,
  test = "pearson1898",
  alternative = "two.sided",
  show.conf.interval = NULL,
  show.N = NULL,
  show.p = NULL,
  show.statistic = NULL
)

Arguments

formula

Formula for comparing correlations

data

Project data frame name

test

Type of significance test. If non-overlapping variables use one of "pearson1898", "dunn1969", "steiger1980", "raghunathan1996", or "silver2004". If overlapping variables use one of pearson1898, hotelling1940, hendrickson1970, williams1959, olkin1967, dunn1969, steiger1980, meng1992, hittner2003. Default is pearson1898.

alternative

Alternative hypothesis to pass to alternative argument of cor.test. Default is "two.sided"

show.conf.interval

Show confidence interval or not (TRUE/FALSE). Default behavior is TRUE.

show.N

Show sample size or not (TRUE/FALSE). Default behavior is TRUE.

show.p

Show p-value or not (TRUE/FALSE). Default behavior is TRUE.

show.statistic

Show test statistic or not (TRUE/FALSE). Default behavior is TRUE.

Value

R Markdown text

Examples

# non-overlappling variables example
apa.r.compare.within.sample(data = attitude,
  formula = ~ rating + complaints | privileges + learning)

# overlappling variables example
apa.r.compare.within.sample(data = attitude,
  formula = ~ rating + complaints | rating + learning)

Create R Markdown Text for Results in the Style of the American Psychological Association (APA)

Description

Create APA style text from analyses for use within R Markdown documents. Descriptive statistics, confidence intervals, and cell sizes are reported.

Package: apaText
Type: Package
Version: 0.1.7
Date: 2023-05-23
License: MIT

Author(s)

Author: David J. Stanley [email protected]
Maintainer: David J. Stanley [email protected]

Create apaText default options for showing confidence intervals etc.. These options will be used unless overridden by local function arguments

Description

Create apaText default options for showing confidence intervals etc.. These options will be used unless overridden by local function arguments

Usage

set.apa.default.options()

Value

A list with options object for apaText

Examples

# You must create an object called apa.default.options
# for options to be used, as per below.

apa.options <- set.apa.default.options()