r2mlm: Compute R-squared values for multilevel models, automatically...

Description Usage Arguments Details Value See Also Examples

View source: R/r2mlm.R

Description

r2mlm reads in a multilevel model (MLM) object generated using lmer or nlme, and outputs all relevant R-squared measures from the Rights and Sterba (2019) framework of multilevel model R-squared measures, which can be visualized together as a set using the outputted bar chart decompositions of outcome variance. That is, when predictors are cluster-mean-centered, all R-squared measures from Rights & Sterba (2019) Table 1 and decompositions from Rights & Sterba (2019) Figure 1 are outputted. When predictors are not cluster-mean-centered, the total R-squared measures from Rights & Sterba (2019) Table 5, as well as bar chart decompositions are outputted. Any number of level-1 and/or level-2 predictors is supported. Any of the level-1 predictors can have random slopes.

Usage

1
r2mlm(model, bargraph = TRUE)

Arguments

model

A model generated using lmer or nlme. Note that models using lmer must specify random effects at the end of the model, like so: outcome ~ 1 + fixed_effects + (random_effects | cluster_variable). Anything else (e.g., outcome ~ 1 + (random_effects | cluster_variable) + fixed_effects) will not work.

bargraph

Optional bar graph output, default is TRUE.

Details

r2mlm first determines whether a given model was generated using lmer or nlme, then passes the model to helper functions that pull the raw data and parameter estimates from the model, and pass that information to r2mlm_manual.

Value

If the input is a valid model, then the output will be a list and associated graphical representation of R-squared decompositions. If the model is not valid, it will return an error prompting the user to input a valid model.

See Also

Rights, J. D., & Sterba, S. K. (2019). Quantifying explained variance in multilevel models: An integrative framework for defining R-squared measures. Psychological Methods, 24(3), 309–338. <doi:10.1037/met0000184>

Other r2mlm single model functions: r2mlm3_manual(), r2mlm_long_manual(), r2mlm_manual()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Using lme4 for your model

# The "bobyqa" optimizer is required for this particular model to converge

model_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"))

r2mlm(model_lme4)

# Using nlme for your model

model_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"))

r2mlm(model_nlme)

r2mlm documentation built on June 5, 2021, 1:05 a.m.