1 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(lme4)

Simulate Data

500 participants will be ranking 90 items based on importance from 1-9.

n.participants <- 500
n.items <- 90

# 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 = rpois(n.participants * n.items, lambda = 5))

head(DT)
##   Subject_ID Item Importance
## 1          1    1          3
## 2          1    2          6
## 3          1    3          7
## 4          1    4          3
## 5          1    5          9
## 6          1    6          8
str(DT)
## 'data.frame':    45000 obs. of  3 variables:
##  $ Subject_ID: Factor w/ 500 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: int  3 6 7 3 9 8 7 3 6 2 ...

Calculate ICC

fit0 <- lme4::lmer(Importance ~ 1 + (1 | Subject_ID), data = DT)
sjstats::icc(fit0)
## # Intraclass Correlation Coefficient
## 
##      Adjusted ICC: 0.001
##   Conditional ICC: 0.001