if (requireNamespace("lme4", quietly = TRUE)) {
library(lme4)
sleep_fit <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
vcovCR(sleep_fit, type = "CR2")
}
pkgs_available <-
requireNamespace("lme4", quietly = TRUE) &
requireNamespace("mlmRev", quietly = TRUE)
if (pkgs_available) {
data(egsingle, package = "mlmRev")
subset_ids <- levels(egsingle$schoolid)[1:10]
math_model <- lmer(math ~ year * size + female + black + hispanic
+ (1 | schoolid) + (1 | childid),
data = egsingle, subset = schoolid %in% subset_ids)
vcovCR(math_model, type = "CR2")
}
Run the code above in your browser using DataLab