Hi lavaan-ers,
I have a longitudinal CFA (two time points = two factors) and a couple of categorical items. To ease the explanation of my question, I simulated some data (as attached; please note the data does not fit the model well, but should be sufficient for demonstrative purposes), namely three categorical items for each of the two time points.
I now would like to 'replicate' the invariance models (see below) I would get if I would use the longInvariance() package and (naively) would treat my variables as normal.
```{r}
library("lavaan")
library("semTools")
#1: specify model
Model_c <- 'Factor_t1 =~ x1t1 + x2t1 + x3t1
Factor_t2 =~ x1t2 + x2t2 + x3t2'
#2: Create list of variables
var1 <- c("x1t1", "x2t1", "x3t1")
var2 <- c("x1t2", "x2t2", "x3t2")
constrainedVar <- list(var1, var2)
#3: fit the models
fit_c <- longInvariance(Model_c, varList = constrainedVar, auto = "all", constrainAuto = TRUE, data =
mydata, estimator="MLR", strict = TRUE,
std.lv = TRUE)
#4: results
#1: configural model
results_c1 <- summary(fit_c$fit.configural, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE, modindices=TRUE)
#fixed (both latent factor variances)
#2:fixed loadings model
results_c1 <- summary(fit_c$fit.loadings, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE, modindices=TRUE)
#fixed (first (not both!) latent factor variance(s), loadings)
#3: fixed loadings and intercepts model
results_c1 <- summary(fit_c$fit.intercepts, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE, modindices=TRUE)
#fixed (first (not both!) latent factor variance(s), loadings, intercepts)
#4: fixed loadings intercept and item variances model
results_c1 <- summary(fit_c$fit.residuals, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE, modindices=TRUE)
#fixed (first (not both!) latent factor variance(s), loadings, intercepts, item variances)
```
As I'd rather not want to treat my variables as normal but as categorical ordered (ordinal), and would like to apply autocorrelations and equating item variances for the two time points, I cannot use the measurementInvarianceCat()package. I thus tried to write the necessary code manually to 'replicate' the above results in the categorical way. In short, I get a problem with equating the item variances for the two time points, which I will shed light on in a bit more detail below the code.
```{r}
#1: configural model
Model1 <- 'Factor_t1 =~ NA*x1t1 + x2t1 + x3t1
Factor_t2 =~ NA*x1t2 + x2t2 + x3t2
Factor_t1 ~~ 1*Factor_t1
Factor_t2 ~~ 1*Factor_t2
x1t1 ~~ x1t2
x2t1 ~~ x2t2
x3t1 ~~ x3t2'
fit1 <- cfa(Model1, data = mydata, estimator="WLSMV", ordered=c("x1t1", "x2t1", "x3t1",
"x1t2", "x2t2", "x3t2"))
results1 <- summary(fit1, fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
#fixed (both latent factor variances)
#2: fixed loadings model
Model2 <- 'Factor_t1 =~ NA*x1t1 + aa*x1t1 + bb*x2t1 + cc*x3t1
Factor_t2 =~ NA*x1t2 + aa*x1t2 + bb*x2t2 + cc*x3t2
Factor_t1 ~~ 1*Factor_t1
x1t1 ~~ x1t2
x2t1 ~~ x2t2
x3t1 ~~ x3t2'
fit2 <- cfa(Model2, data = mydata, estimator="WLSMV", ordered=c("x1t1", "x2t1", "x3t1",
"x1t2", "x2t2", "x3t2"))
results2 <- summary(fit2, fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
#fixed (first (not both!) latent factor variance(s), loadings)
#3: fixed loadings and thresholds model
Model3 <- 'Factor_t1 =~ NA*x1t1 + aa*x1t1 + bb*x2t1 + cc*x3t1
Factor_t2 =~ NA*x1t2 + aa*x1t2 + bb*x2t2 + cc*x3t2
Factor_t1 ~~ 1*Factor_t1
x1t1 ~~ x1t2
x2t1 ~~ x2t2
x3t1 ~~ x3t2
x1t1 | c(a)*t1 + c(b)*t2 + c(c)*t3
x1t2 | c(a)*t1 + c(b)*t2 + c(c)*t3
x2t1 | c(d)*t1 + c(e)*t2 + c(f)*t3
x2t2 | c(d)*t1 + c(e)*t2 + c(f)*t3
x3t1 | c(i)*t1 + c(j)*t2 + c(k)*t3
x3t2 | c(i)*t1 + c(j)*t2 + c(k)*t3'
fit3 <- cfa(Model3, data = mydata, estimator="WLSMV", ordered=c("x1t1", "x2t1", "x3t1",
"x1t2", "x2t2", "x3t2"))
results3 <- summary(fit3, fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
#fixed (first (not both!) latent factor variance(s), loadings, thresholds)
#4: fixed loadings thresholds and item variances model --> fix factor variance
#lavaan recognizes the variance modifiers (dd,ee,ff) but does not equate them, why?
Model4 <- 'Factor_t1 =~ NA*x1t1 + aa*x1t1 + bb*x2t1 + cc*x3t1
Factor_t2 =~ NA*x1t2 + aa*x1t2 + bb*x2t2 + cc*x3t2
Factor_t1 ~~ 1*Factor_t1
x1t1 ~~ x1t2
x2t1 ~~ x2t2
x3t1 ~~ x3t2
x1t1 | c(a)*t1 + c(b)*t2 + c(c)*t3
x1t2 | c(a)*t1 + c(b)*t2 + c(c)*t3
x2t1 | c(d)*t1 + c(e)*t2 + c(f)*t3
x2t2 | c(d)*t1 + c(e)*t2 + c(f)*t3
x3t1 | c(i)*t1 + c(j)*t2 + c(k)*t3
x3t2 | c(i)*t1 + c(j)*t2 + c(k)*t3
x1t1 ~~ dd*x1t1
x1t2 ~~ dd*x1t2
x2t1 ~~ ee*x2t1
x2t2 ~~ ee*x2t2
x3t1 ~~ ff*x3t1
x3t2 ~~ ff*x3t2'
fit4 <- cfa(Model4, data = mydata, estimator="WLSMV", ordered=c("x1t1", "x2t1", "x3t1",
"x1t2", "x2t2", "x3t2"))
results4 <- summary(fit4, fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
#fixed (first (not both!) latent factor variance(s), loadings, thresholds, --> not item variance why?)
#4B: fixed loadings thresholds and item variances model --> fix item variance
#lavaan recognizes the variance modifiers (dd,ee,ff) but does not equate them, why?
Model4B <- 'Factor_t1 =~ aa*x1t1 + bb*x2t1 + cc*x3t1
Factor_t2 =~ aa*x1t2 + bb*x2t2 + cc*x3t2
x1t1 ~~ x1t2
x2t1 ~~ x2t2
x3t1 ~~ x3t2
x1t1 | c(a)*t1 + c(b)*t2 + c(c)*t3
x1t2 | c(a)*t1 + c(b)*t2 + c(c)*t3
x2t1 | c(d)*t1 + c(e)*t2 + c(f)*t3
x2t2 | c(d)*t1 + c(e)*t2 + c(f)*t3
x3t1 | c(i)*t1 + c(j)*t2 + c(k)*t3
x3t2 | c(i)*t1 + c(j)*t2 + c(k)*t3
x1t1 ~~ dd*x1t1
x1t2 ~~ dd*x1t2
x2t1 ~~ ee*x2t1
x2t2 ~~ ee*x2t2
x3t1 ~~ ff*x3t1
x3t2 ~~ ff*x3t2'
fit4B <- cfa(Model4B, data = mydata, estimator="WLSMV", ordered=c("x1t1", "x2t1", "x3t1",
"x1t2", "x2t2", "x3t2"))
results4B <- summary(fit4B, fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
#fixed (both first item variances, loadings, thresholds, --> not item variance why?)
#4C: fixed loadings thresholds and item variances model --> fix both factor variances
#when fixing two factors (which I actually think may be redundant as the modifier "aa" for the first items loadings needs to be estimated only once), I do get the fixed variances for the modifiers (dd,ee,ff).
Model4C <- 'Factor_t1 =~ NA*x1t1 + aa*x1t1 + bb*x2t1 + cc*x3t1
Factor_t2 =~ NA*x1t2 + aa*x1t2 + bb*x2t2 + cc*x3t2
Factor_t1 ~~ 1*Factor_t1
Factor_t2 ~~ 1*Factor_t2
x1t1 ~~ x1t2
x2t1 ~~ x2t2
x3t1 ~~ x3t2
x1t1 | c(a)*t1 + c(b)*t2 + c(c)*t3
x1t2 | c(a)*t1 + c(b)*t2 + c(c)*t3
x2t1 | c(d)*t1 + c(e)*t2 + c(f)*t3
x2t2 | c(d)*t1 + c(e)*t2 + c(f)*t3
x3t1 | c(i)*t1 + c(j)*t2 + c(k)*t3
x3t2 | c(i)*t1 + c(j)*t2 + c(k)*t3
x1t1 ~~ dd*x1t1
x1t2 ~~ dd*x1t2
x2t1 ~~ ee*x2t1
x2t2 ~~ ee*x2t2
x3t1 ~~ ff*x3t1
x3t2 ~~ ff*x3t2'
fit4C <- cfa(Model4C, data = mydata, estimator="WLSMV", ordered=c("x1t1", "x2t1", "x3t1",
"x1t2", "x2t2", "x3t2"))
results4C <- summary(fit4C, fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
#fixed (both (!) latent factor variances, loadings, thresholds, item variances, R-squares)
```
Lavaan does seem to recognize my variance modifiers (dd,ee,ff), as it correctly prints
them in the results output, yet, even though they are recognized, they
are not equal for the two time points.
My question now is, whether anyone knows or can advice me on how I can specify model 4 (either A, B or C) correctly, so that the item variances in those models
belonging to the identifiers (dd,ee,ff) will have the same variance per
identifier (without having to fix both factor variances to 1, as I did in model 4C)?
Is that
possible at all with ordinal data?
Thank you very much for helping me,
Jes