if (FALSE) {
# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")
#-------------------------------------------------------------------------------
# Cluster variable specification
# Example 1a: Cluster variable 'cluster' in 'x'
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4", "cluster")], cluster = "cluster")
# Example 1b: Cluster variable 'cluster' not in 'x'
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")], cluster = Demo.twolevel$cluster)
# Example 1c: Alternative specification using the 'data' argument
multilevel.omega(y1:y4, data = Demo.twolevel, cluster = "cluster")
#-------------------------------------------------------------------------------
# Type of construct
# Example 2a: Within-Cluster Construct
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, const = "within")
# Example 2b: Shared Cluster-Level Construct
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, const = "shared")
# Example 2c: Configural Construct
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, const = "config")
#-------------------------------------------------------------------------------
# Residual covariance at the Within level and residual variance at the Between level
# Example 3a: Residual covariance between "y4" and "y5" at the Within level
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, const = "config",
rescov = c("y3", "y4"))
# Example 3b: Residual variances of 'y1' at the Between level fixed at 0
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, const = "config",
fix.resid = c("y1", "y2"), digits = 3)
#----------------------------------------------------------------------------
# Write results
# Example 4a: Write results into a text file
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, write = "Multilevel_Omega.txt")
# Example 4b: Write results into an Excel file
multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, write = "Multilevel_Omega.xlsx")
# Example 4b: Assign results into an object and write results into an Excel file
mod <- multilevel.omega(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, output = FALSE)
# Write results into an Excel file
write.result(mod, "Multilevel_Omega.xlsx")
}
Run the code above in your browser using DataLab