Title: | Format Outputs of Statistical Tests According to APA Guidelines |
---|---|
Description: | Formatter functions in the 'apa' package take the return value of a statistical test function, e.g. a call to chisq.test() and return a string formatted according to the guidelines of the APA (American Psychological Association). |
Authors: | Daniel Gromer [aut, cre] |
Maintainer: | Daniel Gromer <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.3.4.9000 |
Built: | 2024-11-10 04:00:38 UTC |
Source: | https://github.com/dgromer/apa |
Report ANOVA in APA style
anova_apa( x, effect = NULL, sph_corr = c("greenhouse-geisser", "gg", "huynh-feldt", "hf", "none"), force_sph_corr = FALSE, es = c("petasq", "pes", "getasq", "ges"), format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
anova_apa( x, effect = NULL, sph_corr = c("greenhouse-geisser", "gg", "huynh-feldt", "hf", "none"), force_sph_corr = FALSE, es = c("petasq", "pes", "getasq", "ges"), format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
x |
A call to |
effect |
Character string indicating the name of the effect to display.
If is |
sph_corr |
Character string indicating the method used for correction if
the assumption of sphericity is violated (only applies to repeated-measures
and mixed design ANOVA). Can be one of |
force_sph_corr |
Logical indicating if sphericity correction should be
applied to all within factors regardless of what the result of Mauchly's
test of sphericity is (default is |
es |
Character string indicating the effect size to display in the
output, one of |
format |
Character string specifying the output format. One of
|
info |
Logical indicating whether to print a message on the used test
(default is |
print |
Logical indicating whether to print the formatted output via
|
# Using the ez package library(ez) data(ANT) x <- ezANOVA(ANT[ANT$error==0,], dv = rt, wid = subnum, within = c(cue, flank), between = group, detailed = TRUE) anova_apa(x) # Using the afex package library(afex) data(md_12.1) y <- aov_ez(id = "id", dv = "rt", data = md_12.1, within = c("angle", "noise")) anova_apa(y)
# Using the ez package library(ez) data(ANT) x <- ezANOVA(ANT[ANT$error==0,], dv = rt, wid = subnum, within = c(cue, flank), between = group, detailed = TRUE) anova_apa(x) # Using the afex package library(afex) data(md_12.1) y <- aov_ez(id = "id", dv = "rt", data = md_12.1, within = c("angle", "noise")) anova_apa(y)
A wrapper around the *_apa
functions, providing a convenient way to
use the formatters in inline code in RMarkdown documents.
apa(x, effect = NULL, format = "rmarkdown", print = FALSE, ...)
apa(x, effect = NULL, format = "rmarkdown", print = FALSE, ...)
x |
An R object. Must be a call to one of |
effect |
(only applicable if |
format |
Character string specifying the output format. One of
|
print |
Logical indicating whether to return the result as an R object
( |
... |
Further arguments passed to other methods |
anova_apa, chisq_apa, cor_apa, t_apa
Report Chi-squared test in APA style
chisq_apa( x, print_n = FALSE, format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
chisq_apa( x, print_n = FALSE, format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
x |
A call to |
print_n |
Logical indicating whether to show sample size in text |
format |
Character string specifying the output format. One of
|
info |
Logical indicating whether to print a message on the used test
(default is |
print |
Logical indicating whether to print the formatted output via
|
# Example data from ?chisq.test m <- rbind(c(762, 327, 468), c(484, 239, 477)) chisq_apa(chisq.test(m))
# Example data from ?chisq.test m <- rbind(c(762, 327, 468), c(484, 239, 477)) chisq_apa(chisq.test(m))
Calculate Cohen's d from raw data or a call to t_test
/t.test
.
cohens_d(...) ## Default S3 method: cohens_d( x, y = NULL, paired = FALSE, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... ) ## S3 method for class 'data.frame' cohens_d( data, dv, iv, paired = FALSE, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... ) ## S3 method for class 'formula' cohens_d( formula, data, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... ) ## S3 method for class 'htest' cohens_d(ttest, corr = c("none", "hedges_g", "glass_delta"), ...)
cohens_d(...) ## Default S3 method: cohens_d( x, y = NULL, paired = FALSE, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... ) ## S3 method for class 'data.frame' cohens_d( data, dv, iv, paired = FALSE, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... ) ## S3 method for class 'formula' cohens_d( formula, data, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... ) ## S3 method for class 'htest' cohens_d(ttest, corr = c("none", "hedges_g", "glass_delta"), ...)
... |
Further arguments passed to methods. |
x |
A (non-empty) numeric vector of data values. |
y |
An optional (non-empty) numeric vector of data values. |
paired |
A logical indicating whether Cohen's d should be calculated for a paired sample or two independent samples (default). Ignored when calculating Cohen's for one sample. |
corr |
Character specifying the correction applied to calculation of the
effect size: |
na.rm |
Logical. Should missing values be removed? |
data |
A data frame containing either the variables in the formula
|
dv |
Character indicating the name of the column in |
iv |
Character indicating the name of the column in |
formula |
A formula of the form |
ttest |
An object of class |
To calculate Cohen's d from summary statistics (M, SD, ..) use cohens_d_.
Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: a practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. doi:10.3389/fpsyg.2013.00863
# Calculate from raw data cohens_d(c(10, 15, 11, 14, 17), c(22, 18, 23, 25, 20)) # Methods when working with data frames cohens_d(sleep, dv = extra, iv = group, paired = TRUE) # or cohens_d(sleep, dv = "extra", iv = "group", paired = TRUE) # formula interface sleep2 <- reshape(sleep, direction = "wide", idvar = "ID", timevar = "group") cohens_d(Pair(extra.1, extra.2) ~ 1, sleep2, paired = TRUE) # Or pass a call to t_test or t.test cohens_d(t_test(Pair(extra.1, extra.2) ~ 1, sleep2))
# Calculate from raw data cohens_d(c(10, 15, 11, 14, 17), c(22, 18, 23, 25, 20)) # Methods when working with data frames cohens_d(sleep, dv = extra, iv = group, paired = TRUE) # or cohens_d(sleep, dv = "extra", iv = "group", paired = TRUE) # formula interface sleep2 <- reshape(sleep, direction = "wide", idvar = "ID", timevar = "group") cohens_d(Pair(extra.1, extra.2) ~ 1, sleep2, paired = TRUE) # Or pass a call to t_test or t.test cohens_d(t_test(Pair(extra.1, extra.2) ~ 1, sleep2))
Calculate Cohens'd from different statistics (see Details).
cohens_d_( m1 = NULL, m2 = NULL, sd1 = NULL, sd2 = NULL, n1 = NULL, n2 = NULL, t = NULL, n = NULL, paired = FALSE, one_sample = FALSE, corr = c("none", "hedges_g", "glass_delta") )
cohens_d_( m1 = NULL, m2 = NULL, sd1 = NULL, sd2 = NULL, n1 = NULL, n2 = NULL, t = NULL, n = NULL, paired = FALSE, one_sample = FALSE, corr = c("none", "hedges_g", "glass_delta") )
m1 |
Numeric, mean of the first group |
m2 |
Numeric, mean of the second group |
sd1 |
Numeric, standard deviation of the first group |
sd2 |
Numeric, standard deviation of the second group |
n1 |
Numeric, size of the first group |
n2 |
Numeric, size of the second group |
t |
Numeric, t-test statistic |
n |
Numeric, total sample size |
paired |
Logical indicating whether to calculate Cohen's d for
independent samples or one sample ( |
one_sample |
Logical indicating whether to calculate Cohen's d for
one sample ( |
corr |
Character specifying the correction applied to calculation of the
effect size: |
The following combinations of statistics are possible:
m1
, m2
, sd1
, sd2
, n1
and
n2
t
, n1
and n2
t
and n
Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: a practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. doi:10.3389/fpsyg.2013.00863
Report Correlation in APA style
cor_apa( x, r_ci = FALSE, format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
cor_apa( x, r_ci = FALSE, format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
x |
A call to |
r_ci |
Logical indicating whether to display the confidence interval
for the correlation coefficient (default is |
format |
Character string specifying the output format. One of
|
info |
Logical indicating whether to print a message on the used test
(default is |
print |
Logical indicating whether to print the formatted output via
|
# Example data from ?cor.test x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1) y <- c( 2.6, 3.1, 2.5, 5.0, 3.6, 4.0, 5.2, 2.8, 3.8) cor_apa(cor.test(x, y)) # Spearman's rho cor_apa(cor.test(x, y, method = "spearman")) # Kendall's tau cor_apa(cor.test(x, y, method = "kendall"))
# Example data from ?cor.test x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1) y <- c( 2.6, 3.1, 2.5, 5.0, 3.6, 4.0, 5.2, 2.8, 3.8) cor_apa(cor.test(x, y)) # Spearman's rho cor_apa(cor.test(x, y, method = "spearman")) # Kendall's tau cor_apa(cor.test(x, y, method = "kendall"))
Partial Eta Squared
petasq(x, effect)
petasq(x, effect)
x |
A call to |
effect |
Character string indicating the name of the effect for which the partial eta squared should be returned. |
Calculate the partial eta squared effect size from sum of squares.
petasq_(ss_effect, ss_error)
petasq_(ss_effect, ss_error)
ss_effect |
numeric, sum of squares of the effect |
ss_error |
numeric, sum of squares of the corresponding error |
Report t-Test in APA style
t_apa( x, es = c("cohens_d", "hedges_g", "glass_delta"), es_ci = FALSE, format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
t_apa( x, es = c("cohens_d", "hedges_g", "glass_delta"), es_ci = FALSE, format = c("text", "markdown", "rmarkdown", "html", "latex", "latex_math", "docx", "plotmath"), info = FALSE, print = TRUE )
x |
A call to |
es |
Character specifying the effect size to report. One of
|
es_ci |
Logical indicating whether to add the 95% confidence interval
for Cohen's d (experimental; default is |
format |
Character string specifying the output format. One of
|
info |
Logical indicating whether to print a message on the used test
(default is |
print |
Logical indicating whether to print the formatted output via
|
# Two independent samples t-test t_apa(t_test(1:10, y = c(7:20))) # Two dependent samples t-test sleep2 <- reshape(sleep, direction = "wide", idvar = "ID", timevar = "group") t_apa(t_test(Pair(extra.1, extra.2) ~ 1, sleep2))
# Two independent samples t-test t_apa(t_test(1:10, y = c(7:20))) # Two dependent samples t-test sleep2 <- reshape(sleep, direction = "wide", idvar = "ID", timevar = "group") t_apa(t_test(Pair(extra.1, extra.2) ~ 1, sleep2))
A wrapper for t.test
which includes the original data in the returned
object.
t_test(x, ...) ## Default S3 method: t_test( x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, var.equal = FALSE, conf.level = 0.95, ... ) ## S3 method for class 'formula' t_test(formula, data, subset, na.action, ...)
t_test(x, ...) ## Default S3 method: t_test( x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, var.equal = FALSE, conf.level = 0.95, ... ) ## S3 method for class 'formula' t_test(formula, data, subset, na.action, ...)
x |
a (non-empty) numeric vector of data values. |
... |
further arguments to be passed to or from methods. |
y |
an optional (non-empty) numeric vector of data values. |
alternative |
a character string specifying the alternative
hypothesis, must be one of |
mu |
a number indicating the true value of the mean (or difference in means if you are performing a two sample test). |
paired |
a logical indicating whether you want a paired t-test. |
var.equal |
a logical variable indicating whether to treat the
two variances as being equal. If |
conf.level |
confidence level of the interval. |
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function which indicates what should happen when
the data contain |