s1 <- sem(model, sleepstudy, meanstructure=TRUE, cluster = “Subject")
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/ca4fd6b7-7b75-40b1-8895-71ccc7836d3cn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/9f502c1b-9f3a-4565-a591-b74e4d2dc092n%40googlegroups.com.
how can I add the random intercepts for "Subject"?
mlm1 <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy)
summary(mlm1)model2 <- '
level: 1
Reaction ~ Days
level: 2
????
'
s2 <- sem(model2, sleepstudy, meanstructure=TRUE, cluster="Subject")
Estimate the Level-2 variance of Reaction (its Level-2 component is the random intercepts)
model2 <- '
level: 1
Reaction ~ Days
Reaction ~~ var.L1*Reactionlevel: 2
Reaction ~~ var.L2*Reaction
'
Note that by only include Days in the Level-1 model, you are estimating the conflated effect of Days, in both the MLM and MLSEM. In lmer(), decomposing the effects would require calculating cluster means for Days, then cluster-mean-centering Days (manifest covariate approach). But MLSEM can use the latent covariate approach, automatically decomposing Level-1 predictors into their level-specific components. Then you can define the contextual effect and test whether the effect differs across levels. Also, the R-squared at each level will then correspond to the pseudo-R-squared per level calculated from residual-variance reduction in MLM (although the Level-2 R-squared will be attenuated in MLM due to unreliability of cluster-mean estimates; Lüdtke et al., 2008, 2011).
model2 <- '
level: 1
Reaction ~ b1*Days
Reaction ~~ var.L1*Reactionlevel: 2
Reaction ~ b2*Days
Reaction ~~ var.L2*Reaction
contextual := b2 - b1 # contextual effect
‚
Error in S[1, 1] : incorrect number of dimensions
Any ideas?