View source: R/mlm_variance_decomp.R
| mlm_variance_decomp | R Documentation |
In a random-slope model, the uncertainty around a simple slope has two
distinct sources that standard mlm_probe() collapses into one SE:
mlm_variance_decomp(
model,
pred,
modx,
modx.values = c("mean-sd", "quartiles", "tertiles", "custom"),
at = NULL,
conf.level = 0.95
)
model |
An |
pred |
Character scalar. Focal predictor name. |
modx |
Character scalar. Moderator name. |
modx.values |
Strategy for moderator values. See |
at |
Optional numeric vector of custom moderator values. |
conf.level |
Confidence level for fixed-effect CIs. Default |
Fixed-effect uncertainty – imprecision in the estimated average
slope (\beta_1 + \beta_3 \cdot w), captured by the fixed-effect
variance-covariance matrix.
Random-slope variance – genuine between-cluster heterogeneity in
the slope of pred (\tau_{11}), which is not estimation error
but real variation in effects across clusters.
These answer different questions:
Fixed-effect uncertainty: "How precisely do we know the average slope at this moderator value?"
Random-slope variance: "How much does the slope actually vary across clusters, regardless of what the moderator does?"
The function also reports a prediction interval for the slope in a new (unobserved) cluster, which combines both sources and is the appropriate uncertainty interval for making cluster-level predictions.
Random-slope variance (\tau_{11}) interpretation:
If tau11 is large relative to the fixed slope, the effect of pred
varies substantially across clusters even after accounting for the
moderator. This is important: a significant interaction does not mean
the moderator fully explains between-cluster slope heterogeneity.
Prediction interval interpretation:
The prediction interval answers: "For a randomly sampled new cluster at
this moderator value, what range of slopes should we expect?" It will
always be wider than the confidence interval because it incorporates
\tau_{11}.
Percentage of variance from random effects:
\% \text{random} = \frac{\tau_{11}}{\tau_{11} + \text{Var}(\hat{\beta}_{\text{simple slope}})} \times 100
An object of class mlm_variance_decomp (a list) with:
decomp: data frame with columns modx_value, slope,
se_fixed (SE from fixed-effect vcov only),
tau11 (random-slope SD, if estimable),
se_total (combined SE for prediction in new cluster),
ci_lower, ci_upper (fixed-effect CI),
pi_lower, pi_upper (prediction interval for new cluster),
pct_random (% of total slope variance from random effects).
tau11: the random-slope variance (\tau_{11}).
has_random_slope: logical – does the model include a random slope
for pred?
Metadata: pred, modx, conf.level.
set.seed(1)
dat <- data.frame(
y = rnorm(200), x = rnorm(200),
m = rep(rnorm(20), each = 10),
grp = factor(rep(1:20, each = 10))
)
dat$y <- dat$y + dat$x * dat$m
mod <- lme4::lmer(y ~ x * m + (1 + x | grp), data = dat,
control = lme4::lmerControl(optimizer = "bobyqa"))
vd <- mlm_variance_decomp(mod, pred = "x", modx = "m")
print(vd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.