# Using lme4 for your model
# The "bobyqa" optimizer is required for these particular models to converge
if (FALSE) # Model A, no "salary" components included
modelA_lme4 <- lmer(satisfaction ~ 1 + control_c + control_m + s_t_ratio + (1
+ control_c | schoolID), data = teachsat, REML = TRUE, control =
lmerControl(optimizer = "bobyqa"))
# Model B, full model with "salary" components included
modelB_lme4 <- lmer(satisfaction ~ 1 + salary_c + control_c + salary_m +
control_m + s_t_ratio + (1 + salary_c + control_c | schoolID), data =
teachsat, REML = TRUE, control = lmerControl(optimizer = "bobyqa"))
# Compare models
r2mlm_comp(modelA_lme4, modelB_lme4)
# Compare models, optional data argument specified
r2mlm_comp(modelA_lme4, modelB_lme4, teachsat)
# Using nlme for your model
# Model A, no "salary" components included
modelA_nlme <- lme(satisfaction ~ 1 + control_c + control_m + s_t_ratio,
random = ~ 1 + control_c | schoolID,
data = teachsat,
method = "REML",
control = lmeControl(opt = "optim"))
# Model B, full model with "salary" components included
modelB_nlme <- lme(satisfaction ~ 1 + salary_c + control_c + salary_m +
control_m + s_t_ratio,
random = ~ 1 + salary_c + control_c | schoolID,
data = teachsat,
method = "REML",
control = lmeControl(opt = "optim"))
# Compare models
r2mlm_comp(modelA_nlme, modelB_nlme)
# Compare models, optional data argument specified
r2mlm_comp(modelA_nlme, modelB_nlme, teachsat)
Run the code above in your browser using DataLab