r2MLM R function description:
This function reads in raw data and multilevel model (MLM) parameter estimates and outputs all relevant measures and barchart decompositions. That is, when predictors are cluster-mean-centered, all R-squareds in Table 1 and decompositions in Figure 1 are outputted (see Rights & Sterba, in press). When predictors are not cluster-mean-centered, the total R-squareds from Table 5, as well as barchart 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.
Rights, J.D., & Sterba, S.K. (in press). Quantifying explained variance in multilevel models: An integrative framework for defining R-squared measures. Psychological Methods.
r2MLM R function input:
data – Dataset with rows denoting observations and columns denoting variables
within_covs – List of numbers corresponding to the columns in the dataset of the level-1 predictors used in the MLM (if none used, set to NULL)
between_covs – List of numbers corresponding to the columns in the dataset of the level-2 predictors used in the MLM (if none used, set to NULL)
random_covs – List of numbers corresponding to the columns in the dataset of the level-1 predictors that have random slopes in the MLM (if no random slopes, set to NULL)
gamma_w – Vector of fixed slope estimates for all level-1 predictors, to be entered in the order of the predictors listed by within_covs (if none, set to NULL)
gamma_b – Vector of fixed intercept estimate (if applicable; see has_intercept below) and fixed slope estimates for all level-2 predictors, to be entered intercept first (if applicable) followed by level-2 slopes in the order listed by between_covs (if none, set to NULL)
Tau – random effect covariance matrix; 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)
sigma2 – level-1 residual variance
has_intercept – if set to TRUE, the first element of gamma_b is assumed to be the fixed intercept estimate; if set to FALSE, the first element of gamma_b is assumed to be the first fixed level-2 predictor slope; set to TRUE by default
clustermeancentered – if set to TRUE, all level-1 predictors (indicated by the within_covs list) are assumed to be cluster-mean-centered and function will output all decompositions; if set to FALSE, function will output only total decompositions (see Description above); set to TRUE by default
r2MLM R function code and example input: