yrosseel / lavaan

an R package for structural equation modeling and more
http://lavaan.org
438 stars 99 forks source link

ESEM in a SAM-Approach #272

Closed MaximilianFSchwarz closed 1 year ago

MaximilianFSchwarz commented 1 year ago

Within the SAM-Approach, I would like to fit a measurement model with an ESEM and then use it for a structural model to predict outcomes.

yrosseel commented 1 year ago

This now works. For example, using the Mplus example 5.25:

ex5_25 = read.table("ex5.25.dat")
names(ex5_25) = paste0("y",1:12)

model <- '
    # efa block 
    efa("efa1")*f1 + 
    efa("efa1")*f2 =~ y1 + y2 + y3 + y4 + y5 + y6

    # cfa block
    f3 =~ y7 + y8 + y9
    f4 =~ y10 + y11 + y12

    # regressions
    f3 ~ f1 + f2
    f4 ~ f3
'

# using ESEM
fit <- sem(model = model, data = ex5_25, rotation = "geomin")

# using SAM approach (ESAM?)
fit.sam <- sam(model = model, mm.list = list(block1 = c("f1", "f2"),
                                             block2 = c("f3", "f4")),
               data = ex5_25, rotation = "geomin")

It is important to use mm.list= to define the measurement blocks.