This function calculates the intraclass-correlation coefficient
(icc) - sometimes also called variance partition coefficient
(vpc) - for mixed effects models. The ICC is calculated for merMod
(lme4), glmmTMB
(glmmTMB), MixMod
(GLMMadpative),
lme
(nlme), mixed
(afex), and stanreg
(rstanarm) objects and can be interpreted as “the proportion
of the variance explained by the grouping structure in the population”
(Hox 2010: 15). For models fitted with the brms-package,
a variance decomposition based on the posterior predictive distribution
is calculated (see 'Details').
icc(model, ...)# S3 method for brmsfit
icc(model, re.form = NULL, robust = TRUE,
ci = 0.95, ...)
A mixed effects model of class merMod
, glmmTMB
,
MixMod
, lme
, mixed
, stanreg
or brmsfit
.
Currently not used.
Formula containing group-level effects to be considered in
the prediction. If NULL
(default), include all group-level effects.
Else, for instance for nested models, name a specific group-level effect
to calculate the variance decomposition for this group-level.
Logical, if TRUE
, the median instead of mean is used to
calculate the central tendency of the variances.
The Credible Interval level.
A list with two values, the adjusted and conditional ICC. For models
of class brmsfit
, a list with two values, the decomposed ICC as well
as the credible intervals for this ICC.
Calculation of the ICC
The ICC is calculated by dividing the random effect variance, , by the total variance, i.e. the sum of the random effect variance and the residual variance, .
Adjusted and conditional ICC
icc()
calculates an adjusted and conditional ICC, which take
all sources of uncertainty (i.e. of all random effects) into account. While
the adjusted ICC only relates to the random effects, the conditional ICC
also takes the fixed effects variances into account (see Nakagawa et al. 2017).
Typically, the adjusted ICC is of interest when the analysis of random
effects is of interest. icc()
returns a meaningful ICC also for more
complex random effects structures, like models with random slopes or nested
design (more than two levels) and is applicable for models with other distributions
than Gaussian. For more details on the computation of the variances, see
get_variance
.
ICC for unconditional and conditional models
Usually, the ICC is calculated for the null model ("unconditional model"). However, according to Raudenbush and Bryk (2002) or Rabe-Hesketh and Skrondal (2012) it is also feasible to compute the ICC for full models with covariates ("conditional models") and compare how much, e.g., a level-2 variable explains the portion of variation in the grouping structure (random intercept).
ICC for specific group-levels
The proportion of variance for specific levels related to each other
(e.g., similarity of level-1-units within level-2-units or level-2-units
within level-3-units) must be calculated manually. Use get_variance
to get the random intercept variances (between-group-variances) and residual
variance of the model, and calculate the ICC for the various level correlations.
For example, for the ICC between level 1 and 2:
sum(insight::get_variance_intercept(model)) /
(sum(insight::get_variance_intercept(model)) + insight::get_variance_residual(model))
For for the ICC between level 2 and 3:
insight::get_variance_intercept(model)[2] /
sum(insight::get_variance_intercept(model))
ICC for brms-models
If model
is of class brmsfit
, icc()
calculates a
variance decomposition based on the posterior predictive distribution. In
this case, first, the draws from the posterior predictive distribution
not conditioned on group-level terms (posterior_predict(..., re.form = NA)
)
are calculated as well as draws from this distribution conditioned
on all random effects (by default, unless specified else in re.form
)
are taken. Then, second, the variances for each of these draws are calculated.
The "ICC" is then the ratio between these two variances. This is the recommended
way to analyse random-effect-variances for non-Gaussian models. It is then possible
to compare variances accross models, also by specifying different group-level
terms via the re.form
-argument.
Sometimes, when the variance of the posterior predictive distribution is
very large, the variance ratio in the output makes no sense, e.g. because
it is negative. In such cases, it might help to use robust = TRUE
.
Hox, J. J. (2010). Multilevel analysis: techniques and applications (2nd ed). New York: Routledge.
Nakagawa, S., Johnson, P. C. D., & Schielzeth, H. (2017). The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. Journal of The Royal Society Interface, 14(134), 20170213. 10.1098/rsif.2017.0213
Rabe-Hesketh, S., & Skrondal, A. (2012). Multilevel and longitudinal modeling using Stata (3rd ed). College Station, Tex: Stata Press Publication.
Raudenbush, S. W., & Bryk, A. S. (2002). Hierarchical linear models: applications and data analysis methods (2nd ed). Thousand Oaks: Sage Publications.
# NOT RUN {
library(lme4)
model <- lme4::lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
icc(model)
# }
Run the code above in your browser using DataLab