These functions extracts random effect variances as well as
random-intercept-slope-correlation of mixed effects models.
Currently, merMod
, glmmTMB
,
stanreg
and brmsfit
objects are supported.
re_var(x, adjusted = FALSE)get_re_var(x, comp = c("tau.00", "tau.01", "tau.11", "rho.01",
"sigma_2"))
Fitted mixed effects model (of class merMod
, glmmTMB
,
stanreg
or brmsfit
). get_re_var()
also accepts
an object returned by the icc
function.
Name of the variance component to be returned. See 'Details'.
get_re_var()
returns the value of the requested variance component,
re_var()
returns all random effects variances.
The random effect variances indicate the between- and within-group
variances as well as random-slope variance and random-slope-intercept
correlation. Use following values for comp
to get the particular
variance component:
"sigma_2"
Within-group (residual) variance
"tau.00"
Between-group-variance (variation between individual intercepts and average intercept)
"tau.11"
Random-slope-variance (variation between individual slopes and average slope)
"tau.01"
Random-Intercept-Slope-covariance
"rho.01"
Random-Intercept-Slope-correlation
The within-group-variance is affected by factors at level one, i.e. by the lower-level direct effects. Level two factors (i.e. cross-level direct effects) affect the between-group-variance. Cross-level interaction effects are group-level factors that explain the variance in random slopes (Aguinis et al. 2013).
If adjusted = TRUE
, the variance of the fixed and random
effects as well as of the additive dispersion and
distribution-specific variance are returned (see Johnson et al. 2014
and Nakagawa et al. 2017):
"fixed"
variance attributable to the fixed effects
"random"
(mean) variance of random effects
"dispersion"
variance due to additive dispersion
"distribution"
distribution-specific variance
"residual"
sum of dispersion and distribution
Aguinis H, Gottfredson RK, Culpepper SA. 2013. Best-Practice Recommendations for Estimating Cross-Level Interaction Effects Using Multilevel Modeling. Journal of Management 39(6): 1490<U+2013>1528 (10.1177/0149206313478188)
Johnson PC, O'Hara RB. 2014. Extension of Nakagawa & Schielzeth's R2GLMM to random slopes models. Methods Ecol Evol, 5: 944-946. (10.1111/2041-210X.12225)
Nakagawa S, Johnson P, Schielzeth H (2017) The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisted and expanded. J. R. Soc. Interface 14. 10.1098/rsif.2017.0213
# NOT RUN {
library(lme4)
fit1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
# all random effect variance components
re_var(fit1)
re_var(fit1, adjusted = TRUE)
# just the rand. slope-intercept covariance
get_re_var(fit1, "tau.01")
sleepstudy$mygrp <- sample(1:45, size = 180, replace = TRUE)
fit2 <- lmer(Reaction ~ Days + (1 | mygrp) + (Days | Subject), sleepstudy)
re_var(fit2)
# }
Run the code above in your browser using DataLab