Can lavaan handle cross-level mediation for multilevel data?
Galo <- read.table("http://users.ugent.be/~yrosseel/lavaan/tubingen2017/Galo.dat")
names(Galo) <- c("school", "sex", "galo", "advice", "feduc", "meduc",
"focc", "denom")
# missing data
Galo[Galo == 999] <- NA
model <- '
level: within
wses =~ a*focc + b*meduc + c*feduc
advice ~ wc*wses + wb*galo
galo ~ wa*wses
# residual correlation
focc ~~ feduc
level: between
bses =~ a*focc + b*meduc + c*feduc
advice ~ bc*bses + bb*galo
galo ~ ba*bses + denom
feduc ~~ 0*feduc
# indirect effects
wi := wa * wb
bi := ba * bb
'
library(lavaan)
fit <- sem(model, data = Galo, cluster = "school", fixed.x = FALSE,
missing = "fiml", std.lv = TRUE, h1 = TRUE)
summary(fit, fit.measures = TRUE, standardized = TRUE)