## MK 9200 Spring 2025 Week 10 Syntax
## Ordinal data and multigroup analysis, following Wu & Estabrook
# load packages
library(lavaan)
library(semTools)
# use builtin Holzinger-Swineford (1939) data
data<-HolzingerSwineford1939
summary(data)
# select the 9 variables, leaving aside the grouping variable "school"
# in preparation for converting data to ordinal for this demonstration
# PS DON'T convert continuous data to ordinal except under
# special circumstances
HStri<-data[,c(7:15)]
# Reduce continuous data to ordinal with 3 response categories
HStri <- as.data.frame( lapply(HStri[,1:9], cut, 3, labels=F) )
# Bring back school grouping variable--did not want to corrupt that
HStri$school<-data$school
str(HStri)
# See what this turned x1 and x2 into
with(HStri,table(x1,x2))
# CFA model
HSbasemodel<-'
Spatial =~ x1 + x2 + x3
Verbal =~ x4 + x5 + x6
Speed =~ x7 + x8 + x9'
## Recall, original result, single group
originalone.out <- sem(model=HSbasemodel,data=data)
summary(originalone.out, fit=T)
# original result, multigroup by school
originalMG.out <- sem(model=HSbasemodel,data=data, group="school")
summary(originalMG.out,fit=T)
# Pretend it is continuous and homogeneous (single group)
cont.out <- sem(model=HSbasemodel,data=HStri)
summary(cont.out)
# Tell lavaan data are ordinal, still single-group
ord.out <- sem(model=HSbasemodel,data=HStri,
ordered=c(paste0("x",1:9)))
summary(ord.out)
# Use measEq.syntax for configural invariance--the long way
syntax.config <- measEq.syntax(configural.model = HSbasemodel, data = HStri,
ordered=c(paste0("x",1:9)),
parameterization = "delta",
ID.fac = "std.lv", ID.cat = "Wu.Estabrook.2016",
group = "school")
# Tell R that this syntax string is character data
HStri.config<-as.character(syntax.config)
# Look at it--not e the end of line markers
HStri.config
# Use that syntax as the model
# multigroup analysis with school as grouping variable
# delta parameterization
HStri.config.out<-cfa(model=HStri.config,data=HStri,group="school",
ordered=c(paste0("x",1:9)),
parameterization="delta")
summary(HStri.config.out)
# for the rest of these steps, do it the short way--create and run
# Invariance of thresholds
# Notice that DF does NOT change--
# new constraints are added while others are relaxed
# So invariance of thresholds is equivalent to configural invariance
fit.thresh <- measEq.syntax(configural.model = HSbasemodel, data = HStri,
parameterization = "delta",
ID.fac = "std.lv", ID.cat = "Wu.Estabrook.2016",
group = "school",
ordered=c(paste0("x",1:9)),
group.equal=c("thresholds"),return.fit=T)
summary(fit.thresh)
# Invariance of thresholds and loadings
fit.weak <- measEq.syntax(configural.model = HSbasemodel, data = HStri,
parameterization = "delta",
ID.fac = "std.lv", ID.cat = "Wu.Estabrook.2016",
ordered=c(paste0("x",1:9)),
group = "school",
group.equal=c("thresholds","loadings"),return.fit=T)
summary(fit.weak)
# Invariance of thresholds, lo9adings and intercepts
fit.strong <- measEq.syntax(configural.model = HSbasemodel, data = HStri,
parameterization = "delta",
ID.fac = "std.lv", ID.cat = "Wu.Estabrook.2016",
ordered=c(paste0("x",1:9)),
group = "school",
group.equal=c("thresholds","loadings","intercepts"),return.fit=T)
summary(fit.strong)
# Though the first two models are different, they are equivalent
anova(fit.thresh,HStri.config.out)
# Chi-square differences to assess the nested constraints
# We report robust chi-square, but difference tests are always
# based on un-modified chi-square statistics
anova(fit.strong,fit.weak,HStri.config.out)
--
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 visit https://groups.google.com/d/msgid/lavaan/f3104769-34e9-417e-bbc5-c1329dbdee4dn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lavaan/9b85f951-69e8-497e-8618-34b307f318e8n%40googlegroups.com.
I obtained the same Chi-square value and degrees of freedom for both the configural and thresholds models.
I'm currently unsure how to properly conduct measurement invariance testing for this type of mixed measurement model.
Terrence D. Jorgensen (he, him, his)