Hello all,
I am a newcomer to multilevel analysis and I am looking to use lavaan to account for data gathered across many sites within a given region (i.e. data clustered by site). I want to see how well the model holds across the many sites, while accounting for the random variation between sites. That is, the model of interest is the same between as within, but I'd like to account for site-level clustering. The structural model is relatively straightforward (see code below) with two factors and one mediating variable all predicting the DV.
lav.model <- "
F1 =~ NA*y1 + y2 + y3
F2 =~ NA*y4 + y5
F1 ~~ 1*F1
F2 ~~ 1*F2
F1 ~~ F2
M1 ~ a*F1 + c*F2
DV ~ b*F1 + d*F2 + e*M1
"
lav.fit <- sem(lav.model, data=mlm.data, std.ov=TRUE, missing="ML", cluster="site")
summary(lav.fit, fit.measures=TRUE)
I had a bit of trouble getting it to run, but when I used the EM optimization method suggested
here, I get the following error:
"Error in lavaan::lavaan(model = lav.model, data = mlm.data, cluster = "site", : lavdata@nlevels > 1L is not TRUE"
The "nlevels > 1L is not TRUE" is confusing because I thought I had a lower level (cluster="site") specified.
Is this model specified correctly? Am I answering the question I think I am answering?
I am very appreciative of whatever insights you all can provide.