Learn R Programming

misty (version 0.4.5)

multilevel.descript: Multilevel Descriptive Statistics

Description

This function computes descriptive statistics for multilevel data, e.g. average cluster size, variance components, intraclass correlation coefficient, design effect, and effective sample size.

Usage

multilevel.descript(x, cluster, method = c("aov", "lme4", "nlme"), REML = TRUE,
                    digits = 2, icc.digits = 3, as.na = NULL, check = TRUE,
                    output = TRUE)

Arguments

x

a vector, matrix or data frame.

cluster

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

method

a character string indicating the method used to estimate intraclass correlation coefficients, i.e., "aov" ICC estimated using the aov function, "lme4" (default) ICC estimated using the lmer function in the lme4 package, "nlme" ICC estimated using the lme function in the nlme package.

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.

digits

an integer value indicating the number of decimal places to be used.

icc.digits

an integer indicating the number of decimal places to be used for displaying intraclass correlation coefficients.

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.

output

logical: if TRUE, output is shown on the console.

Value

Returns an object of class misty.object, which is a list with following entries: function call (call), type of analysis type, matrix or data frame specified in x (data), specification of function arguments (args), and list with results (result).

Details

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

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.cor, multilevel.icc, multilevel.indirect, multilevel.r2, write.result,

Examples

Run this code
# NOT RUN {
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))

# Multilevel descriptive statistics for x1
multilevel.descript(dat$x1, cluster = dat$cluster)

# Multilevel descriptive statistics for x1, print ICC with 5 digits
multilevel.descript(dat$x1, cluster = dat$cluster, icc.digits = 5)

# Multilevel descriptive statistics for x1, convert value 1 to NA
multilevel.descript(dat$x1, cluster = dat$cluster, as.na = 1)

# Multilevel descriptive statistics for x1,
# use lme() function in the nlme package to estimate ICC
multilevel.descript(dat$x1, cluster = dat$cluster, method = "nlme")

# Multilevel descriptive statistics for x1, x2, and x3
multilevel.descript(dat[, c("x1", "x2", "x3")], cluster = dat$cluster)

# }
# NOT RUN {
# Write Results into a Excel file
result <- multilevel.descript(dat[, c("x1", "x2", "x3")], cluster = dat$cluster,
                              output = FALSE)
write.result(result, "Multilevel_Descript.xlsx") 
# }

Run the code above in your browser using DataLab