2 min read

Intraclass correlation coefficient in Linear Mixed Effects Models

if (!requireNamespace("pacman")){
  install.packages("pacman")
}
## Loading required namespace: pacman
pacman::p_load(sjstats)
pacman::p_load(sjPlot)
pacman::p_load(lme4)
pacman::p_load(MASS)

Simulate Data

100 participants will be ranking 20 items based on importance simulated from a multivariate normal distribution.

n.participants <- 100
n.items <- 20

Sigma <- 0.9 ^ toeplitz(1:n.items)
diag(Sigma) <- 1

# Subject needs to be a factor for lmer
DT <- data.frame(Subject_ID = factor(rep(1:n.participants, each = n.items)),
                 Item = rep(1:n.items, n.participants),
                 Importance = as.vector(replicate(n.participants, mvrnorm(1, mu = rep(0,n.items), Sigma = Sigma))))

head(DT)
##   Subject_ID Item Importance
## 1          1    1  1.6680635
## 2          1    2  1.4818320
## 3          1    3  0.8447595
## 4          1    4  1.1937203
## 5          1    5  1.3669878
## 6          1    6  1.3405396
str(DT)
## 'data.frame':    2000 obs. of  3 variables:
##  $ Subject_ID: Factor w/ 100 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Item      : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Importance: num  1.668 1.482 0.845 1.194 1.367 ...

Calculate ICC

fit0 <- lme4::lmer(Importance ~ 1 + (1 | Subject_ID), data = DT)
sjPlot::tab_model(fit0)
  Importance
Predictors Estimates CI p
(Intercept) -0.06 -0.19 – 0.06 0.309
Random Effects
σ2 0.55
τ00 Subject_ID 0.37
ICC 0.40
N Subject_ID 100
Observations 2000
Marginal R2 / Conditional R2 0.000 / 0.400
performance::icc(fit0)
## # Intraclass Correlation Coefficient
## 
##      Adjusted ICC: 0.400
##   Conditional ICC: 0.400