Learn R Programming

papaja (version 0.1.0.9054)

apa_print.htest: Format statistics (APA 6th edition)

Description

Takes htest objects from various statistical methods to create formated chraracter strings to report the results in accordance with APA manuscript guidelines.

Usage

"apa_print"(x, stat_name = NULL, est_name = NULL, n = NULL, ci = NULL, in_paren = FALSE, ...)

Arguments

x
htest object. See details.
stat_name
Character. If NULL (default) the name given in x (or a formally correct adaptation, such as $\chi^2$ instead of "x-squared") is used for the test statistic, otherwise the supplied name is used. See details.
est_name
Character. If NULL (default) the name given in x (or a formally correct adaptation, such as $r_S$ instead of "rho") is used for the estimate, otherwise the supplied name is used. See details.
n
Numeric. Size of the sample; required when reporting $\chi^2$ tests, otherwise this parameter is ignored.
ci
Numeric. If NULL (default) the function tries to obtain confidence intervals from x. Other confidence intervals can be supplied as a vector of length 2 (lower and upper boundary, respectively) with attribute conf.level, e.g., when calculating bootstrapped confidence intervals.
in_paren
Logical. Indicates if the formated string will be reported inside parentheses. See details.
...
Further arguments to pass to printnum to format the estimate.

Value

apa_print() returns a list containing the following components according to the input:

Details

The function should work on a wide range of htest objects. Due to the large number of functions that produce these objects and their idiosyncracies, the produced strings may sometimes be inaccurate. If you experience inaccuracies you may report these here (please include a reproducible example in your report!).

stat_name and est_name are placed in the output string and are thus passed to pandoc or LaTeX through kntir. Thus, to the extent it is supported by the final document type, you can pass LaTeX-markup to format the final text (e.g., \\tau yields $\tau$).

If in_paren is TRUE parentheses in the formated string, such as those surrounding degrees of freedom, are replaced with brackets.

See Also

Other apa_print: apa_print.Anova.mlm, apa_print.anova, apa_print.aov, apa_print.aovlist, apa_print.summary.aov, apa_print.summary.aovlist; apa_print.lm, apa_print.summary.lm; apa_print

Examples

Run this code
# Comparisions of central tendencies
t_stat <- t.test(extra ~ group, data = sleep)
apa_print(t_stat)
apa_print(t_stat, stat_name = "tee")

wilcox_stat <- wilcox.test(extra ~ group, data = sleep)
apa_print(wilcox_stat)

# Correlations
## Data from Hollander & Wolfe (1973), p. 187f.
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_stat <- cor.test(x, y, method = "spearman")
apa_print(cor_stat)

# Contingency tables
## Data from Fleiss (1981), p. 139.
smokers  <- c(83, 90, 129, 70)
patients <- c(86, 93, 136, 82)
prop_stat <- prop.test(smokers, patients)
apa_print(prop_stat, n = sum(patients))

Run the code above in your browser using DataLab