if (FALSE) {
# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")
# Model specification
model <- 'level: 1
fw =~ y1 + y2 + y3
fw ~ x1 + x2 + x3
level: 2
fb =~ y1 + y2 + y3
fb ~ w1 + w2'
#-------------------------------------------------------------------------------
# Example 1: Model estimation with estimator = "ML"
fit1 <- lavaan::sem(model = model, data = Demo.twolevel, cluster = "cluster",
estimator = "ML")
# Simultaneous and level-specific multilevel model fit information
ls.fit1 <- multilevel.fit(fit1)
# Write results into a text file
multilevel.fit(fit1, write = "LS-Fit1.txt")
# Write results into an Excel file
write.result(ls.fit1, "LS-Fit1.xlsx")
# Example 2: Model estimation with estimator = "MLR"
fit2 <- lavaan::sem(model = model, data = Demo.twolevel, cluster = "cluster",
estimator = "MLR")
# Simultaneous and level-specific multilevel model fit information
# Write results into an Excel file
multilevel.fit(fit2, write = "LS-Fit2.xlsx")
}
Run the code above in your browser using DataLab