format_stats.lm {cocoon} | R Documentation |
Format linear model statistics
Description
This method formats (generalized) linear model statistics from the class
lm
or glm
. If no term is specified, overall model statistics are
returned. For linear models (lm
objects), this includes the R-squared,
F statistic, and p-value. For generalized linear models (glm
objects),
this includes deviance and AIC.
The default output is APA formatted, but this function allows
control over numbers of digits, leading zeros, italics, degrees of freedom,
and output format of Markdown or LaTeX.
Usage
## S3 method for class 'lm'
format_stats(
x,
term = NULL,
digits = 3,
pdigits = 3,
pzero = FALSE,
full = TRUE,
italics = TRUE,
dfs = "par",
type = "md",
...
)
Arguments
x |
An |
term |
Character string for row name of term to extract statistics for.
This must be the exact string returned in the |
digits |
Number of digits after the decimal for 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 extra info (e.g., standard errors and t-values or z-values for terms) or just test statistic and p-value. |
italics |
Logical value (default = TRUE) for whether statistics labels should be italicized. |
dfs |
Formatting for degrees of freedom ("par" = parenthetical, "sub" = subscript, "none" = do not print degrees of freedom). |
type |
Type of formatting ("md" = markdown, "latex" = LaTeX). |
... |
Additional arguments passed to methods. |
Value
A character string of statistical information formatted in Markdown or LaTeX.
See Also
Other functions for printing statistical objects:
format_bf()
,
format_corr()
,
format_stats()
,
format_stats.BFBayesFactor()
,
format_stats.aov()
,
format_stats.easycorrelation()
,
format_stats.htest()
,
format_stats.lmerModLmerTest()
,
format_stats.merMod()
,
format_ttest()
Examples
test_lm <- lm(mpg ~ cyl * hp, data = mtcars)
test_glm <- glm(am ~ cyl * hp, data = mtcars, family = binomial)
# Format linear model overall statistics
format_stats(test_lm)
# Format linear model term statistics
format_stats(test_lm, term = "cyl")
# Format generalized linear model overall statistics
format_stats(test_glm)
# Format generalized linear model term statistics
format_stats(test_glm, term = "cyl")
# Remove italics and make degrees of freedom subscripts
format_stats(test_lm, term = "cyl", italics = FALSE, dfs = "sub")
# Change digits and add leading zero to p-value
format_stats(test_lm, term = "hp", digits = 3, pdigits = 4, pzero = TRUE)
# Format for LaTeX
format_stats(test_lm, term = "hp", type = "latex")