r2MLMcomp
Appendix to accompany “New recommendations on the use of R-squared differences in multilevel model comparisons”: r2MLMcomp R function
r2MLMcomp R function Description:
This function reads in raw data and multilevel model (MLM) parameter estimates from two separate models under comparison (Model A and Model B) and outputs all R2 measures (reviewed and defined in the manuscript’s print Appendix A) for both models as well as all ΔR2 measures (defined in the manuscript’s Table 1). Additionally, the function produces side-by-side graphical comparisons of the R2 measures for Model A vs. B that can be used to visualize changes in each measure across models (see manuscript description of Figure 2 for an example illustration). This function assumes all level-1 predictors are cluster-mean-centered for reasons described in the manuscript. Any number of level-1 and/or level-2 predictors is supported and any of the level-1 predictors can have random slopes. This function can be used with either the hierarchical or the simultaneous model-building approach described in the manuscript (in which Model B is the more complex model for a given pairwise comparison). Our function can also be used with either nested non-nested model comparisons (in which R2 estimates for Model A are subtracted from those for Model B).
r2MLMcomp R function Input:
data – Dataset with rows denoting observations and columns denoting variables
within_covs_modA – List of numbers corresponding to the columns in the dataset of the level-1 predictors used in the Model A MLM (if none used, set to NULL)
between_covs_modA – List of numbers corresponding to the columns in the dataset of the level-2 predictors used in the Model A MLM (if none used, set to NULL)
random_covs_modA – List of numbers corresponding to the columns in the dataset of the level-1 predictors that have random slopes in the Model A MLM (if no random slopes, set to NULL)
gamma_w_modA – Vector of estimates of the fixed component of slopes for all level-1 predictors for Model A, to be entered in the order of the predictors listed by within_covs (if none, set to NULL)
gamma_b_modA – Vector of estimates of the fixed component of the intercept and slopes for all level-2 predictors for Model A, to be entered intercept first followed by level-2 slopes in the order listed by between_covs
Tau_modA – random effect covariance matrix for Model A; note that the first row/column denotes the intercept variance and covariances (if intercept is fixed, set all to 0) and each subsequent row/column denotes a given random slope’s variance and covariances (to be entered in the order listed by random_covs). Variances are on diagonal and covariances are on off-diagonal.
sigma2_modA – level-1 residual variance for Model A
within_covs_modB – List of numbers corresponding to the columns in the dataset of the level-1 predictors used in the Model B MLM (if none used, set to NULL)
between_covs_modB – List of numbers corresponding to the columns in the dataset of the level-2 predictors used in the Model B MLM (if none used, set to NULL)
random_covs_modB – List of numbers corresponding to the columns in the dataset of the level-1 predictors that have random slopes in the Model B MLM (if no random slopes, set to NULL)
gamma_w_modB – Vector of estimates of the fixed component of slopes for all level-1 predictors for Model B, to be entered in the order of the predictors listed by within_covs (if none, set to NULL)
gamma_b_modB – Vector of estimates of the fixed component of the intercept and slopes for all level-2 predictors for Model B, to be entered intercept first followed by level-2 slopes in the order listed by between_covs
Tau_modB – random effect covariance matrix for Model B; note that the first row/column denotes the intercept variance and covariances (if intercept is fixed, set all to 0) and each subsequent row/column denotes a given random slope’s variance and covariances (to be entered in the order listed by random_covs). Variances are on diagonal and covariances are on off-diagonal.
sigma2_modB – level-1 residual variance for Model B
r2MLMcomp R function code and example input:
Connect with Vanderbilt
©2024 Vanderbilt University ·
Site Development: University Web Communications