multilevel_R2: Multilevel R squared for two-level models

multilevel_r2R Documentation

Multilevel R squared for two-level models

Description

Calculates the multilevel R squared for two-level models.

Usage

multilevel_r2(model1, model2, n = table(model1$groups))

Arguments

model1

The first model.

model2

The second model.

n

Optional vector of group sizes for level 2.

Value

A list with the following components:

r2_l1

The R squared value for level 1.

r2_l2

The R squared value for level 2.

r2_l1_2

The combined R squared value for levels 1 and 2.

r2_l2_2

The adjusted R squared value for levels 1 and 2 (with optional group sizes).

n

The harmonic mean of the group sizes (if provided).

References

Snijders, T. A. B., & Bosker, R. J. (1994). Modeled Variance in Two-Level Models. Sociological Methods & Research, 22(3), 342-363.

Examples

data(sleepstudy, package = "lme4")
model1 <- nlme::lme(Reaction ~ 1, data = sleepstudy, random =~ 1|Subject)
model2 <- nlme::lme(Reaction ~ Days, data = sleepstudy, random =~ 1|Subject)
multilevel_r2(model1, model2, table(sleepstudy$Subject))

jazznbass/wmisc documentation built on Oct. 29, 2024, 5:42 p.m.