Description Usage Arguments Details Value Note References See Also Examples
This function calculates the intraclasscorrelation
(icc)  sometimes also called variance partition coefficient
(vpc)  for random intercepts of mixed effects models. Currently,
merMod
, glmmTMB
,
stanreg
and brmsfit
objects are supported.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  icc(x, ...)
## S3 method for class 'merMod'
icc(x, adjusted = FALSE, ...)
## S3 method for class 'glmmTMB'
icc(x, adjusted = FALSE, ...)
## S3 method for class 'stanreg'
icc(x, re.form = NULL, typical = "mean",
prob = 0.89, ppd = FALSE, ...)
## S3 method for class 'brmsfit'
icc(x, re.form = NULL, typical = "mean",
prob = 0.89, ppd = FALSE, ...)

x 
Fitted mixed effects model (of class 
... 
Currently not used. 
adjusted 
Logical, if 
re.form 
Formula containing grouplevel effects to be considered in
the prediction. If 
typical 
Character vector, naming the function that will be used as
measure of central tendency for the ICC. The default is "mean". See

prob 
Vector of scalars between 0 and 1, indicating the mass within
the credible interval that is to be estimated. See 
ppd 
Logical, if 
The ICC is calculated by dividing the betweengroupvariance (random
intercept variance) by the total variance (i.e. sum of betweengroupvariance
and withingroup (residual) variance).
The calculation of the ICC for generalized linear mixed models with binary outcome is based on
Wu et al. (2012). For other distributions (negative binomial, poisson, ...),
calculation is based on Nakagawa et al. 2017.
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
RabeHesketh and Skrondal (2012) it is also feasible to compute the ICC
for full models with covariates ("conditional models") and compare how
much a level2 variable explains the portion of variation in the grouping
structure (random intercept).
ICC for randomslope models
Caution: For models with random slopes and random intercepts,
the ICC would differ at each unit of the predictors. Hence, the ICC for these
kind of models cannot be understood simply as proportion of variance
(see Goldstein et al. 2010). For convenience reasons, as the
icc()
function also extracts the different random effects
variances, the ICC for randomslopeinterceptmodels is reported
nonetheless, but it is usually no meaningful summary of the
proportion of variances.
ICC for models with multiple or nested random effects
Caution: By default, for threelevelmodels, depending on the
nested structure of the model, or for models with multiple random effects,
icc()
only reports the proportion of variance explained for each
grouping level. Use adjusted = TRUE
to calculate the adjusted and
conditional ICC.
Adjusted and conditional ICC
If adjusted = TRUE
, an adjusted and conditional ICC are calculated,
which take all sources of uncertainty (of all random effects)
into account to report an "adjusted" ICC, as well as the conditional ICC.
The latter also takes the fixed effects variances into account (see
Nakagawa et al. 2017). If random effects are not nested and not
crossclassified, the adjusted (adjusted = TRUE
) and unadjusted
(adjusted = FALSE
) ICC are identical.
ICC for specific grouplevels
To calculate the proportion of variance for specific levels related to each
other (e.g., similarity of level1units within
level2units or level2units within level3units) must be computed
manually. Use get_re_var
to get the betweengroupvariances
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(get_re_var(fit)) / (sum(get_re_var(fit)) + get_re_var(fit, "sigma_2"))
or for the ICC between level 2 and 3:
get_re_var(fit)[2] / sum(get_re_var(fit))
ICC for Bayesian models
If ppd = TRUE
, 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 grouplevel
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 randomeffectvariances for nonGaussian models. It is then possible
to compare variances accross models, also by specifying different grouplevel
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 a more robust measure
to calculate the central tendency of the variances. For example, use
typical = "median"
.
A numeric vector with all random intercept intraclasscorrelationcoefficients.
Furthermore, if adjusted = FALSE
, between and withingroup variances
as well as randomslope variance are returned as attributes.
For stanreg
or brmsfit
objects, the HDI for each statistic
is also included as attribute.
Some notes on why the ICC is useful, based on GraceMartin:
It can help you determine whether or not a linear mixed model is even necessary. If you find that the correlation is zero, that means the observations within clusters are no more similar than observations from different clusters. Go ahead and use a simpler analysis technique.
It can be theoretically meaningful to understand how much of the overall variation in the response is explained simply by clustering. For example, in a repeated measures psychological study you can tell to what extent mood is a trait (varies among people, but not within a person on different occasions) or state (varies little on average among people, but varies a lot across occasions).
It can also be meaningful to see how the ICC (as well as the between and within cluster variances) changes as variable are added to the model.
In short, the ICC can be interpreted as “the proportion of the variance
explained by the grouping structure in the population” (Hox 2002: 15).
The random effect variances indicate the between and withingroup
variances as well as randomslope variance and randomslopeintercept
correlation. The components are denoted as following:
Withingroup (residual) variance: sigma_2
Betweengroupvariance: tau.00 (variation between individual intercepts and average intercept)
Randomslopevariance: tau.11 (variation between individual slopes and average slope)
RandomInterceptSlopecovariance: tau.01
RandomInterceptSlopecorrelation: rho.01
Aguinis H, Gottfredson RK, Culpepper SA. 2013. BestPractice Recommendations for Estimating CrossLevel Interaction Effects Using Multilevel Modeling. Journal of Management 39(6): 1490–1528 (doi: 10.1177/0149206313478188)
Goldstein H, Browne W, Rasbash J. 2010. Partitioning Variation in Multilevel Models. Understanding Statistics, 1:4, 223231 (doi: 10.1207/S15328031US0104_02)
GraceMartion K. The Intraclass Correlation Coefficient in Mixed Models, web
Hox J. 2002. Multilevel analysis: techniques and applications. Mahwah, NJ: Erlbaum
Nakagawa S, Johnson P, Schielzeth H (2017) The coefficient of determination R2 and intraclass correlation coefficient from generalized linear mixedeffects models revisted and expanded. J. R. Soc. Interface 14. doi: 10.1098/rsif.2017.0213
RabeHesketh S, Skrondal A. 2012. Multilevel and longitudinal modeling using Stata. 3rd ed. College Station, Tex: Stata Press Publication
Raudenbush SW, Bryk AS. 2002. Hierarchical linear models: applications and data analysis methods. 2nd ed. Thousand Oaks: Sage Publications
Wu S, Crespi CM, Wong WK. 2012. Comparison of methods for estimating the intraclass correlation coefficient for binary responses in cancer prevention cluster randomized trials. Contempory Clinical Trials 33: 869880 (doi: 10.1016/j.cct.2012.05.004)
Further helpful onlineressources:
CrossValidated (2012) Intraclass correlation (ICC) for an interaction?
CrossValidated (2014) Interpreting the random effect in a mixedeffect model
CrossValidated (2014) how to partition the variance explained at group level and individual level
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  library(lme4)
fit0 < lmer(Reaction ~ 1 + (1  Subject), sleepstudy)
icc(fit0)
# note: ICC for randomslopeintercept model usually not
# meaningful  see 'Note'.
fit1 < lmer(Reaction ~ Days + (Days  Subject), sleepstudy)
icc(fit1)
sleepstudy$mygrp < sample(1:45, size = 180, replace = TRUE)
fit2 < lmer(Reaction ~ Days + (1  mygrp) + (1  Subject), sleepstudy)
icc(fit2)
icc(fit2, adjusted = TRUE)
icc1 < icc(fit1)
icc2 < icc(fit2)
print(icc1, comp = "var")
print(icc2, comp = "var")
## Not run:
# compute ICC for Bayesian mixed model, with an ICC for each
# sample of the posterior. The print()method then shows
# the median ICC as well as 89% HDI for the ICC.
# Change interval with printmethod:
# print(icc(m, posterior = TRUE), prob = .5)
if (requireNamespace("brms", quietly = TRUE)) {
library(dplyr)
sleepstudy$mygrp < sample(1:5, size = 180, replace = TRUE)
sleepstudy < sleepstudy %>%
group_by(mygrp) %>%
mutate(mysubgrp = sample(1:30, size = n(), replace = TRUE))
m < brms::brm(
Reaction ~ Days + (1  mygrp / mysubgrp) + (1  Subject),
data = sleepstudy
)
# by default, 89% interval
icc(m)
# show 50% interval
icc(m, prob = .5)
# variances based on posterior predictive distribution
icc(m, ppd = TRUE)
}
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.