Function to detect heteroscedasticity in two-level random intercept models.
Uses a generalization of the Breusch-Pagan-type (using squared residuals)
and Levene-type test (using the absolute value of residuals). Note: this will
not tell you if including random slopes are warranted (for that, use the
robust_mixed) function and compare differences in model-based and
robust standard errors.
Usage
ncvMLM(mx, bp = TRUE)
Value
A p-value (p < .05 suggests heteroskedasticity).
Arguments
mx
The lme or merMod model object.
bp
Computes a Breusch-Pagan-type test (TRUE). If FALSE computes a Levene-type test.
References
Huang, F., Wiedermann, W., & Zhang, B. (2022). Accounting for Heteroskedasticity Resulting from Between-group Differences in Multilevel Models. Multivariate Behavioral Research.
require(lme4)
data(sch25)
ncvMLM(lmer(math ~ byhomewk + male + ses + (1|schid), data = sch25)) #supportedncvMLM(lmer(math ~ byhomewk + male + ses + minority + (1|schid), data = sch25)) #hetero