I think I could solve the problem myself. This code seems to work (I'm glad if somebody can verify it):
dta.ATI <- fscores.I0_I1 |>
dplyr::select("Pre_z", "Post","Lehrperson","SR3.theta","math.fscores","Gruppe") |>
na.omit()
dta.ATI$Gruppe <- droplevels(dta.ATI$Gruppe)
dta.ATI$Gruppe <- recode(dta.ATI$Gruppe,"'I0'=0; 'I1'=1") #Dummykodierung mit Zahlen
dta.ATI <-scale_ignore(dta.ATI,ignore=c("Lehrperson","Gruppe")) #Alle Variablen skalieren und zentrieren, damit lavaan sauber durchläuft
#Version 1, difference of bg2 and bg1
lavmodeldef <- "
Group: 1
level: 1
Post ~ Pre_z + bg1*SR3.theta +math.fscores
level: 2
Post ~ Pre_z + math.fscores
Group: 2
level: 1
Post ~ Pre_z + bg2*SR3.theta + math.fscores
level: 2
Post ~ Pre_z + math.fscores
fit <- sem(lavmodeldef, data = dta.ATI, cluster = "Lehrperson", estimator="MLR",group="Gruppe")
pe <- parameterEstimates(fit)
pe[pe$op == "~",]
pe[pe$op == ":=",]
#Version 2, nested models
lavmodeldef.uncon <- "
Group: 1
level: 1
Post ~ Pre_z + bg1*SR3.theta +math.fscores
level: 2
Post ~ Pre_z + math.fscores
Group: 2
level: 1
Post ~ Pre_z + bg2*SR3.theta + math.fscores
level: 2
Post ~ Pre_z + math.fscores
"
lavmodeldef.con <- "
Group: 1
level: 1
Post ~ Pre_z + bg1*SR3.theta +math.fscores
level: 2
Post ~ Pre_z + math.fscores
Group: 2
level: 1
Post ~ Pre_z + bg2*SR3.theta + math.fscores
level: 2
Post ~ Pre_z + math.fscores
bg1 == bg2
"
fit.uncon <- sem(lavmodeldef.uncon, data = dta.ATI, cluster = "Lehrperson", estimator="MLR",group="Gruppe")
fit.con <- sem(lavmodeldef.con, data = dta.ATI, cluster = "Lehrperson", estimator="MLR",group="Gruppe")
lavTestLRT(fit.uncon, fit.con)
---END OF CODE----
unfortunately, for me, both versions have p-values of around .99, so no significant difference (this interpretation is correct, isn't it?)
Thanks all the same, maybe the code is useful for somebody.
Kind regards, Martin