multilevelR2: Calculate R-squared measures for multilevel models

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/multilevelR2.R

Description

Calculates several measures for the proportion of explained variance in a fitted linear mixed-effects or multilevel model (or a list of fitted models).

Usage

1
multilevelR2(model, print = c("RB1", "RB2", "SB", "MVP"))

Arguments

model

Either a fitted linear mixed-effects model as produced by lme4 or nlme, or a list of fitted models as produced by with.mitml.list.

print

A character vector denoting which measures should be calculated (see details). Default is to printing all measures.

Details

This function calculates several measures of explained variance (R^2) for linear-mixed effects models. It can be used with a single model, as produced by the packages lme4 or nlme, or a list of fitted models produced by with.mitml.list. In the latter case, the R^2 measures are calculated separately for each imputed data set and then averaged across data sets.

Different R^2 measures can be requested using the print argument. Specifying RB1 and RB2 returns the explained variance at level 1 and level 2, respectively, according to Raudenbush and Bryk (2002, pp. 74 and 79). Specifying SB returns the total variance explained according to Snijders and Bosker (2012, p. 112). Specifying MVP returns the total variance explained based on “multilevel variance partitioning” as proposed by LaHuis, Hartman, Hakoyama, and Clark (2014).

Value

A numeric vector containing the R^2 measures requested in print.

Note

Calculating R^2 measures is currently only supported for two-level models with a single cluster variable.

Author(s)

Simon Grund

References

LaHuis, D. M., Hartman, M. J., Hakoyama, S., & Clark, P. C. (2014). Explained variance measures for multilevel models. Organizational Research Methods, 17, 433-451.

Raudenbush, S. W., & Bryk, A. S. (2002). Hierarchical linear models: Applications and data analysis methods (2nd ed.). Thousand Oaks, CA: Sage.

Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel analysis: An introduction to basic and advanced multilevel modeling. Thousand Oaks, CA: Sage.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
require(lme4)
data(studentratings)

fml <- MathAchiev + ReadAchiev + CognAbility ~ 1 + (1|ID)
imp <- panImpute(studentratings, formula = fml, n.burn = 1000, n.iter = 100, m = 5)

implist <- mitmlComplete(imp)

fit <- with(implist, lmer(MathAchiev ~ 1 + CognAbility + (1|ID)))
multilevelR2(fit)

Example output

*** This is beta software. Please report any bugs!
*** See the NEWS file for recent changes.
Loading required package: lme4
Loading required package: Matrix
Running burn-in phase ...
Creating imputed data set ( 1 / 5 ) ...
Creating imputed data set ( 2 / 5 ) ...
Creating imputed data set ( 3 / 5 ) ...
Creating imputed data set ( 4 / 5 ) ...
Creating imputed data set ( 5 / 5 ) ...
Done!
        RB1         RB2          SB         MVP 
 0.34132988 -0.05908676  0.33037596  0.33343776 

mitml documentation built on Oct. 5, 2021, 5:07 p.m.