multilevel.icc: Intraclass Correlation Coefficient, ICC(1) and ICC(2)

View source: R/multilevel.icc.R

multilevel.iccR Documentation

Intraclass Correlation Coefficient, ICC(1) and ICC(2)

Description

This function computes the intraclass correlation coefficient ICC(1), i.e., proportion of the total variance explained by the grouping structure, and ICC(2), i.e., reliability of aggregated variables.

Usage

multilevel.icc(x, cluster, type = 1, method = c("aov", "lme4", "nlme"), REML = TRUE,
               as.na = NULL, check = TRUE)

Arguments

x

a vector, matrix or data frame.

cluster

a vector representing the nested grouping structure (i.e., group or cluster variable).

type

numeric value indicating the type of intraclass correlation coefficient, i.e., type = 1 for ICC(1) and type = 2 for ICC(2).

method

a character string indicating the method used to estimate intraclass correlation coefficients, i.e., method = "aov" ICC estimated using the aov function, method = "lme4" (default) ICC estimated using the lmer function in the lme4 package, method = "nlme" ICC estimated using the lme function in the nlme package. Note that if the lme4 package is not installed, method = "aov" will be used.

REML

logical: if TRUE (default), restricted maximum likelihood is used to estimate the null model when using the lmer function in the lme4 package or the lme function in the nlme package.

as.na

a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis. Note that as.na() function is only applied to x but not to cluster.

check

logical: if TRUE, argument specification is checked.

Details

Note that this function is restricted to two-level models.

Value

Returns a numeric vector with intraclass correlation coefficient(s).

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Hox, J., Moerbeek, M., & van de Schoot, R. (2018). Multilevel analysis: Techniques and applications (3rd. ed.). Routledge.

Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel analysis: An introduction to basic and advanced multilevel modeling (2nd ed.). Sage Publishers.

See Also

multilevel.descript

Examples

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)

misty documentation built on Nov. 15, 2023, 1:06 a.m.

Related to multilevel.icc in misty...