This method formats (generalized) linear mixed model statistics from the
class lmerMod
or glmerMod
from the
{lme4} package.
Only fixed effects can be extracted.
The default output is APA formatted, but this function allows
control over numbers of digits, leading zeros, italics,
and output format of Markdown or LaTeX.
Usage
# S3 method for class 'merMod'
format_stats(
x,
term = NULL,
digits = 3,
pdigits = 3,
pzero = FALSE,
full = TRUE,
italics = TRUE,
type = "md",
...
)
Arguments
- x
An
lmerMod
orglmerMod
object fromlme4::lmer()
orlme4::glmer()
.- term
Character string for row name of term to extract statistics for. This must be the exact string returned in the
summary()
output from thelmerMod
orglmerMod
object and can only be fixed effects.- 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.
- type
Type of formatting ("md" = markdown, "latex" = LaTeX).
- ...
Additional arguments passed to methods.
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.lm()
,
format_stats.lmerModLmerTest()
,
format_ttest()
Examples
test_lmer <- lme4::lmer(mpg ~ hp + (1 | cyl), data = mtcars)
test_glmer <- lme4::glmer(am ~ hp + (1 | cyl), data = mtcars, family = binomial)
# Format linear mixed model term statistics
format_stats(test_lmer, term = "hp")
#> [1] "_β_ = -0.030, SE = 0.015, _t_ = -2.088"
# Format generalized linear mixed model term statistics
format_stats(test_glmer, term = "hp")
#> [1] "_β_ = 0.022, SE = 0.017, _z_ = 1.300, _p_ = .194"
# Remove italics
format_stats(test_lmer, term = "hp", italics = FALSE)
#> [1] "β = -0.030, SE = 0.015, t = -2.088"
# Change digits and add leading zero to p-value
format_stats(test_lmer, term = "hp", digits = 3, pdigits = 4, pzero = TRUE)
#> [1] "_β_ = -0.030, SE = 0.015, _t_ = -2.088"
# Format for LaTeX
format_stats(test_lmer, term = "hp", type = "latex")
#> [1] "$\\beta$ = -0.030, SE = 0.015, $t$ = -2.088"