Report Statistical Regression Model Output, report_mod_out_knitr
Purpose
This function automates the generation of clean regression model outputs with coefficient values, 95% CIs and p-values.
Key Features
Incorporates coefficient interpretation by generating draft conclusions for each coefficient and describing positive/negative associations with appropriate language
Produces publication-ready tables using
knitrandkableExtraR packages for formatting
Parameter Details
| Parameter | Type | Description | Example |
|---|---|---|---|
model | Regression object | Fitted model (lm, glm, etc.) | lm(y ~ x1 + x2, data) |
exp | Logical | Exponentiate estimates (for log models) | TRUE for Poisson/logistic |
params | Character string | Parameters’ labels in output table | "Experience", "Edcuation"… etc. |
n_digits | Integer | Decimal precision in output | 3 for 0.123 |
caption_input | Character | User-defined output label | Default to none |
knitr_output | Logical | Produces publication-quality outputs | TRUE for knitting |
Example Applications
# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/regression/report_mod_out_knitr.R")
# Fit regression model
linear_model <- lm(formula = salary ~ experience + education,
data = salary_data)
# Run function
report_mod_out_knitr(
model = linear_model,
exp = FALSE, # since the model is linear
params = c("Experience", "Edcuation"),
n_digits = 2,
caption_input = "Association between salary, experience and education",
knitr_output = TRUE # for knitted outputs
)