nice_regression_table.RdThis function creates a nicely formatted table comparing the results from one or more regression models (e.g., linear models, generalized linear models, mixed-effects models). It extracts key statistics such as estimates, standard errors, t-values, and p-values, and organizes them into a clear tabular format. Additional model parameters (e.g., R-squared, ICC) can also be included at the bottom of the table for easy comparison.
One or more model objects (e.g., objects of class lm, glm,
lme, lmerModLmerTest, glmerMod).
Number of decimal places to round numeric values.
Character vector with labels for each model. If NULL, the model formula is used.
A named list to rename predictor labels.
A named list to rename column names.
Either column number or column names to be removed from the output table.
If TRUE, common column names are automatically renamed (e.g., "Std. Error" to "SE", "Pr (>|t|)" to "p", etc.).
If provided, the resulting table is also written to the specified file (e.g., an Excel file).
If TRUE, the estimators are assumed to be logits and are exponentiated to yield odds ratios.
If TRUE, p values are formatted nicely with significance stars.
Title of the table.
Footnote of the table.
A data frame with the regression results formatted as a nice table.
The function supports various model types, including lm, glm,
lme (from the nlme package), and lmerModLmerTest (from the lmerTest
package). It automatically extracts relevant statistics and formats them
for presentation. Users can customize the output by renaming predictor labels
and column names, removing specific columns, and adding titles and footnotes.
The resulting table can be exported to a file (e.g., Excel) for reporting
purposes.
lm(mpg ~ am + disp + hp, data = mtcars) |>
nice_regression_table()
Table
Regression model
Estimate
SE
t
p
Model
nice_regression_table(
nlme::lme(mpg~disp, data = mtcars, random = ~1|am),
nlme::lme(mpg~disp + hp, data = mtcars, random = ~1|am)
)
Table
Regression model
Estimate
SE
DF
t
p-value
Estimate
SE
DF
t
p-value
Model
nice_regression_table(
model_lmer_1, model_lmer_2,
rename_labels = list(
"EffectTrend" = "Trend", "EffectSlope" = "Slope", "TimePost" = "Post",
"ConditionTraining" = "Training", "id_subject" = "Subject"),
rename_cols = list("Estimate" = "B", "SE" = "se"),
labels_models = c("Only pretest", "Pre- and posttest")
)
#> Loading required namespace: lmerTest
Table
Regression model
B
se
df
t
p
B
se
df
t
p
Model