Provides a user-friendly interpretation of a fitted lmer model's fixed and random effects.
Arguments
- model
A fitted model object from
lme4::lmer()
. Currently not supporting formula that contains shorthand.
, such asy ~ .
.- details
A character specifying which details to return:
"general"
(the default): a high-level summary of the model structure, fixed effects, and random effects with brief explanations."fixed"
: a more in-depth interpretation of fixed effects in the model context, with additional details on individual fixed effect estimates."random"
: a concise interpretation of each random term (including random intercept and slope), with insights from estimated variance components.
Value
A character string with the interpretation of the model. Additional structured outputs are stored as attributes and can be accessed as follows:
for
details = "fixed"
: useattr(, "fixed_details")
for individual fixed effect interpretation with model estimates; useattr(, "fixed_names")
for all fixed effect variable names.for
details = "random"
: useattr(, "var_details")
for insights regarding estimated variance components for random effects.
Examples
library(lme4)
#> Loading required package: Matrix
model <- lmer(math ~ math_old + cltype + (cltype | school_id), data = star)
# For high-level summary
explain_lmer(model)
#> This linear mixed-effects model examines how math_old, cltype affects math, while accounting for group-level variability across school_id.
#>
#> The model adjusts for fixed effect(s), including math_old, cltype, which estimate the overall relationship with math across the entire dataset. For more detailed interpretations of fixed effects, use `details = "fixed"`.
#>
#> The model includes the following random effects across grouping variables: cltype | school_id.
#> *The random intercept(s), school_id, account for variations in the intercept across different groups, allowing each group to have its own baseline value that deviates from the overall average.
#> *On top of the varying baselines, the model allows the effects of cltype on math to differ across their corresponding groups. This means that not only can each group start from a different baseline, but the strength and direction of the relationships between these variables and math can also vary from one group to another.
#> Check `details = 'random'` for more interpretation.
# For fixed-effect specific interpretation
fix <- explain_lmer(model, "fixed")
#> This model includes the following fixed effects: math_old, cltypesmall, cltyperegular+aide, along with the baseline estimate (Intercept).
#> Fixed effects estimate the average relationship between the predictors and the response variable `math` across all groups.
#> These effects reflect how changes in each predictor influence `math`, assuming all other variables are held constant and deviations from the baseline are measured accordingly.
#>
#> To interpret the estimates:
#> - The <Estimate> represents the expected change in `math` for a one-unit change in the predictor.
#> - The <Standard Error> reflects uncertainty around the estimate.
#> - The <t-value> measures the significance of the effect relative to its variability.
#> - The <Correlation> provides insight into the relationships between fixed effect predictors.
#>
#>
#> For detailed interpretations of each fixed effect, use: `attr(, 'fixed_details')[['variable_name']]` to view specific results. You can find the list of available fixed effect variable names using: `attr(, 'fixed_names')` to guide your extraction.
# Access individual fixed effect interpretation of model estimats
attr(fix, "fixed_details")[["(Intercept)"]]
#> [1] "The intercept estimate suggests that when all predictors are set to zero, the expected value of `math` is approximately 201.646. This serves as the baseline for evaluating the effects of other variables in the model."
# For random-effect specific interpretation
random <- explain_lmer(model, "random")
#> There is 1 random term you fit in the model:
#>
#> cltype | school_id: Your model assumes there is across-group heterogeneity in the baseline level of math across school_id (random intercepts), allowing each group to have its own starting point that deviates from the overall average. Additionally, the effects of cltype on math are allowed to vary within each school_id (random slopes), capturing differences in these relationships across groups.
#>
#> To explore variance contributions based on the model estimates, use: `attr(, 'var_details')`.
# Access variance component insights
attr(random, "var_details")
#> $high_var
#> [1] "The following terms explain a substantial proportion of the variance: Residual. This suggests that these random effects contribute meaningfully to capturing group-level heterogeneity. Note: The residual variance dominates, suggesting that within-group heterogeneity explains most of the variation. This could indicate a weak random effect structure."
#>
#> $low_var
#> [1] "The following terms explain a relatively small portion of the variance: NA, school_id - (Intercept). You might reconsider including these terms in your random effect structure if their contributions are negligible."
#>