Learn R Programming

cocoon (version 0.2.0)

format_stats: Format statistical results

Description

A generic function that takes objects from various statistical methods to create formatted character strings to insert into R Markdown or Quarto documents. Currently, the generic function works with the following objects:

  1. htest objects of correlations, t-tests, and Wilcoxon tests

  2. correlations from the {correlation} package.

  3. aov objects for ANOVAs

  4. Bayes factors from the {BayesFactor} package. The function invokes specific methods that depend on the class of the first argument.

Usage

format_stats(x, ...)

Value

A character string of statistical information formatted in Markdown or LaTeX.

Arguments

x

Statistical object.

...

Additional arguments passed to methods. For method-specific arguments, see format_stats.htest() for htest correlations, t-tests, and Wilcoxon tests, format_stats.easycorrelation() for easycorrelation correlations, format_stats.lm() for linear models, format_stats.merMod() and format_stats.lmerModLmerTest() for linear mixed models, and format_stats.BFBayesFactor() for Bayes factors from the {BayesFactor} package.

See Also

Other functions for printing statistical objects: format_bf(), format_corr(), format_stats.BFBayesFactor(), format_stats.aov(), format_stats.easycorrelation(), format_stats.htest(), format_stats.lm(), format_stats.lmerModLmerTest(), format_stats.merMod(), format_ttest()

Examples

Run this code
# Format cor.test() object
format_stats(cor.test(mtcars$mpg, mtcars$cyl))

# Format correlation::correlation() object
format_stats(correlation::correlation(data = mtcars, select = "mpg", select2 = "cyl"))

# Format t.test() object
format_stats(t.test(mtcars$vs, mtcars$am))

# Format aov() object
format_stats(aov(mpg ~ cyl * hp, data = mtcars), term = "cyl")

# Format lm() or glm() object
format_stats(lm(mpg ~ cyl * hp, data = mtcars), term = "cyl")
format_stats(glm(am ~ cyl * hp, data = mtcars, family = binomial), term = "cyl")

# Format lme4::lmer() or lme4::glmer() object
format_stats(lme4::lmer(mpg ~ hp + (1 | cyl), data = mtcars), term = "hp")
format_stats(lme4::glmer(am ~ hp + (1 | cyl), data = mtcars, family = binomial), term = "hp")

# Format lmerTest::lmer() object
format_stats(lmerTest::lmer(mpg ~ hp + (1 | cyl), data = mtcars), term = "hp")

# Format BFBayesFactor object from {BayesFactor} package
format_stats(BayesFactor::ttestBF(mtcars$vs, mtcars$am))

Run the code above in your browser using DataLab