Learn R Programming

DMAR (version 1.0.0)

print_summary: Print a Model Summary With DMAR p-value Formatting

Description

Pretty-print a model summary (the output of summary.lm, summary.glm, or summary on an lme4 or lmerTest fit) with p-values formatted at a fixed number of decimal places (default 4) and with a “< 10^(-digits_p)” floor for values too small to express. The default print.summary.lm / print.summary.merMod routes p-values through stats::format.pval, which applies its own digit rule and switches to scientific notation for tiny values. print_summary() sidesteps that by converting the p-value columns to character strings up front and printing as a data frame.

Usage

print_summary(fit, digits_p = 4L)

Value

The model summary, invisibly and unchanged.

Arguments

fit

A fitted model object with a summary method that returns coefficients via coef(summary(fit)), including a Pr(...) column. Tested with lm, glm, lme4::lmer, and lmerTest::lmer.

digits_p

Integer number of decimal places for the p-value column(s). Default 4L.

Author

Ken Kelley

Details

For a linear model, the function prints the coefficient table, the residual standard error and degrees of freedom, the multiple and adjusted \(R^2\), and the omnibus F test and its p-value. For a mixed-effects model fit through lme4 / lmerTest, the function prints the random-effect variances (from lme4::VarCorr) and the fixed-effect coefficient table.

The returned object is the model summary, invisibly and unchanged: the underlying numeric p-values retain full precision and can still be indexed (for example as coef(summary(fit))[, "Pr(>|t|)"]).

See Also

format_p, print_anova.

Examples

Run this code
fit_lm <- lm(weight ~ Time + Diet, data = ChickWeight)
print_summary(fit_lm)

fit_lmer <- lme4::lmer(weight ~ Time + (1 | Chick), data = ChickWeight)
print_summary(fit_lmer)

# Underlying numeric p-values are untouched:
sm <- summary(fit_lm)
sm$coefficients[, "Pr(>|t|)"]   # full-precision doubles

Run the code above in your browser using DataLab