| apa_htest | R Documentation |
Runs t tests, Wilcoxon tests, correlation tests, or chi-square tests of
independence on the variables in a data frame and makes a table with one row
per outcome variable: descriptive statistics, the test statistic, its
degrees of freedom, the p-value, and an effect size with its confidence
interval. Tests come from the stats package (e.g., stats::t.test()), and
effect sizes are computed from the data with the effectsize package (e.g.,
effectsize::cohens_d()).
apa_htest(
data,
formula,
test = c("t", "wilcoxon", "cor", "chisq"),
effect_size = NULL,
ci = 0.95,
var_equal = FALSE,
mu = 0,
method = c("pearson", "spearman", "kendall"),
descriptives = TRUE,
pair_labels = NULL,
starred = NA,
bolded = NA,
column_formats = NULL,
...
)
data |
data frame, or test results already computed: an |
formula |
two-sided formula with outcome variables on the left and a
grouping or predictor variable on the right. Several outcomes are joined
with |
test |
type of test:
|
effect_size |
effect size to display. If For paired t tests, Cohen's d is d~av~ ( |
ci |
confidence level of the effect size interval (for correlation tests, the interval of Pearson's r). Intervals are two-sided. |
var_equal |
if |
mu |
value that one-sample tests compare each variable with (for two-group tests, the hypothesized difference in location) |
method |
correlation coefficient: |
descriptives |
if |
pair_labels |
for paired tests, labels of the first and second
variable of each pair, used as the headings above their descriptive
statistics (e.g., |
starred |
columns to star with significant p-values (e.g., |
bolded |
columns to bold, if significant |
column_formats |
column_formats object to format columns. If NULL, the default column_formats is used. |
... |
further arguments passed to the test function (e.g.,
|
Each test uses the rows in which both the outcome and the grouping (or predictor) variable are observed. For two-group tests, the grouping variable must have exactly two observed values, and differences are the first group (in factor level order) minus the second. Paired tests use the rows in which both variables of the pair are observed, and differences are the first variable minus the second.
Effect sizes are computed from the data rather than from the test statistic, so Cohen's d for Welch's test is exact rather than approximated from t.
Use apa_note() to write a table note that says which tests were done, how
the effect size was computed, and what the abbreviations stand for.
apa7_tbl (tibble)
htest objects keep the test statistic, its degrees of freedom, and the
p-value, but not the data, so formula and the arguments that control
the tests are not used, and effect sizes are computed from what the
objects keep:
One-sample and paired t tests: Cohen's d (d~z~ for paired tests)
is exactly t/\sqrt{n}, with an exact interval from the
noncentral t distribution.
Two-sample t tests: Cohen's d is approximated as
2t/\sqrt{df} (effectsize::t_to_d()), which assumes
groups of equal size, and the note says so. For exact values, give
apa_htest() the data instead.
Correlation tests: the correlation and, for Pearson's r, its interval and the sample size.
Chi-square tests of independence: Cramér's V, \phi, or
Cohen's w, computed from the observed table that the object keeps.
Wilcoxon tests and chi-square goodness-of-fit tests: no effect size, because the objects do not keep the sample sizes.
The rows are labeled by the list's names or, if unnamed, by the objects' data names (e.g., "mpg by am"). The table has no descriptive statistics.
Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, Article 863. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3389/fpsyg.2013.00863")}
# Welch's t tests with Cohen's d
d <- mtcars
d$am <- factor(d$am, labels = c("Automatic", "Manual"))
apa_htest(d, mpg + hp + qsec ~ am)
# Student's t test with Hedges' g
apa_htest(d, mpg ~ am, var_equal = TRUE, effect_size = "hedges_g")
# One-sample t test
apa_htest(d, mpg ~ 1, mu = 20)
# Paired t test with d_av
d_sleep <- data.frame(drug1 = sleep$extra[1:10], drug2 = sleep$extra[11:20])
apa_htest(d_sleep, Pair(drug1, drug2) ~ 1)
# Wilcoxon rank-sum tests with rank-biserial correlations
apa_htest(d, mpg + hp ~ am, test = "wilcoxon", exact = FALSE)
# Correlation tests
apa_htest(d, mpg + hp + qsec ~ wt, test = "cor")
# Chi-square tests of independence with Cramer's V
d$cyl <- factor(d$cyl)
d$vs <- factor(d$vs, labels = c("V-shaped", "Straight"))
tbl <- apa_htest(d, cyl + vs ~ am, test = "chisq")
tbl
apa_note(tbl)
# Test results already computed
apa_htest(t.test(mpg ~ am, data = d))
apa_htest(list(
Weight = cor.test(d$mpg, d$wt),
Displacement = cor.test(d$mpg, d$disp)
))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.