This function computes the pseudo R-square for mixed models by quantifying the reduction on the variance-covariance between a full model and a reduced model.
Value
A tibble with the following columns:
grp: The name of the grouping factorvar: The name of the variance componentr2: The pseudo R-square for that variance component
Details
Variance components are extracted from the 3 models, and where they match (groups and terms must match exactly), we compute:
$$R^2 = \frac{V_{full} - V_{restricted}}{V_{null}}$$
This gives the increase in variance explained by the full model compared to the reduced model. When the restricted model is the empty model, this is the same as:
$$R^2 = 1 - \frac{V_{full}}{V_{restricted}}$$
Examples
mod0 <- lme4::lmer(Reaction ~ 1 + (1 | Subject), data = lme4::sleepstudy)
mod1 <- lme4::lmer(Reaction ~ Days + (1 | Subject), data = lme4::sleepstudy)
mod2 <- lme4::lmer(Reaction ~ Days + (Days | Subject), data = lme4::sleepstudy)
r2_pseudo(mod1, mod0) # Residual variance explained by the fixed effect
#> # A tibble: 2 × 3
#> grp var r2
#> <chr> <chr> <dbl>
#> 1 Subject (Intercept) -0.0781
#> 2 Residual NA 0.510
r2_pseudo(mod2, mod1, mod0) # Residual variance explained by the random effects
#> # A tibble: 2 × 3
#> grp var r2
#> <chr> <chr> <dbl>
#> 1 Subject (Intercept) 0.599
#> 2 Residual NA 0.156
r2_pseudo(mod2, mod0) # Residual variance explained by the mixed effects
#> # A tibble: 2 × 3
#> grp var r2
#> <chr> <chr> <dbl>
#> 1 Subject (Intercept) 0.521
#> 2 Residual NA 0.666