dat <- data.frame(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9),
cluster = c(1, 1, 1, 1, 2, 2, 3, 3, 3),
x1 = c(2, 3, 2, 2, 1, 2, 3, 4, 2),
x2 = c(3, 2, 2, 1, 2, 1, 3, 2, 5),
x3 = c(2, 1, 2, 2, 3, 3, 5, 2, 4))
# ICC(1) for x1
multilevel.icc(dat$x1, cluster = dat$cluster)
# ICC(1) for x1, convert value 1 to NA
multilevel.icc(dat$x1, cluster = dat$cluster, as.na = 1)
# ICC(2) for x1
multilevel.icc(dat$x1, cluster = dat$cluster, type = 2)
# ICC(1) for x1,
# use lmer() function in the lme4 package to estimate ICC
multilevel.icc(dat$x1, cluster = dat$cluster, method = "lme4")
# ICC(1) for x1, x2, and x3
multilevel.icc(dat[, c("x1", "x2", "x3")], cluster = dat$cluster)
Run the code above in your browser using DataLab