format_stats.htest {cocoon} | R Documentation |
This method formats hypothesis test statistics from the class htest
.
Currently, this includes correlations from cor.test()
and t-tests and
Wilcoxon tests from t.test()
and wilcox.test()
. For correlations, the
function detects whether the object is from a Pearson,
Spearman, or Kendall correlation and reports the appropriate correlation
label (r, \tau
, \rho
). The default output is APA formatted, but
this function allows control over numbers of
digits, leading zeros, the presence of means and confidence intervals,
italics, degrees of freedom, and mean labels, and output format of
Markdown or LaTeX.
## S3 method for class 'htest'
format_stats(
x,
digits = NULL,
pdigits = 3,
pzero = FALSE,
full = TRUE,
italics = TRUE,
dfs = "par",
mean = "abbr",
type = "md",
...
)
x |
An |
digits |
Number of digits after the decimal for means, confidence intervals, and test statistics |
pdigits |
Number of digits after the decimal for p-values, ranging between 1-5 (also controls cutoff for small p-values) |
pzero |
Logical value (default = FALSE) for whether to include leading zero for p-values |
full |
Logical value (default = TRUE) for whether to include means and confidence intervals or just test statistic and p-value |
italics |
Logical value (default = TRUE) for whether p label should be italicized |
dfs |
Formatting for degrees of freedom ("par" = parenthetical, "sub" = subscript, "none" = do not print degrees of freedom) |
mean |
Formatting for mean label ("abbr" = M, "word" = Mean) |
type |
Type of formatting ("md" = markdown, "latex" = LaTeX) |
... |
Additional arguments passed to methods. |
A character string of statistical information formatted in Markdown or LaTeX.
Other functions for printing statistical objects:
format_bf()
,
format_corr()
,
format_stats()
,
format_stats.BFBayesFactor()
,
format_stats.easycorrelation()
,
format_ttest()
# Prepare statistical objects
test_corr <- cor.test(mtcars$mpg, mtcars$cyl)
test_corr2 <- cor.test(mtcars$mpg, mtcars$cyl, method = "kendall")
test_ttest <- t.test(mtcars$vs, mtcars$am)
test_ttest2 <- wilcox.test(mtcars$vs, mtcars$am)
# Format correlation
format_stats(test_corr)
# Remove confidence intervals and italics
format_stats(test_corr, full = FALSE, italics = FALSE)
# Change digits and add leading zero to p-value
format_stats(test_corr, digits = 3, pdigits = 4, pzero = TRUE)
# Format Kendall's tau
format_stats(test_corr2)
# Format t-test
format_stats(test_ttest)
# Remove mean and confidence interval
format_stats(test_ttest, full = FALSE)
# Remove degrees of freedom and spell out "Mean"
format_stats(test_ttest, dfs = "none", mean = "word")
# Format for LaTeX
format_stats(test_ttest2, type = "latex")