I have a dataset in which some, but not all, subjects participated at Time 2. I want to run a measurement invariance analysis across time and across groups. Of course, for those who participated at Time 1 only, Time 2 latent variables would not be estimated for them.
In lavaan
you can specify different weights for each variable within your model by prefixing it with a vector of weights. For example, c(0.5, 0.2) will give the first group a weight of 0.5 and the second group a weight of 0.2. The problem for me is that I cannot do this to the latent variables. My question: how do I tell lavaan
to estimate latent variables only for one group and not another?
Example code:
model <- '
# Measurement model ---
factor1_time1 =~ 1*var1_t1 + var2_t1 + var3_t1
factor2_time1 =~ 1*var4_t1 + var5_t1 + var6_t1
factor3_time1 =~ 1*var7_t1 + var9_t1 + var9_t1
# !! Note: I only want this to apply to one of the groups !!
factor1_time2 =~ 1*var1_t2 + var2_t2 + var3_t2
factor2_time2 =~ 1*var4_t2 + var5_t2 + var6_t2
factor3_time2 =~ 1*var7_t2 + var9_t2 + var9_t2
# Factor Covariances ---
# all time 1 factors with each other
factor1_time1 ~~ factor2_time1
factor1_time1 ~~ factor3_time1
factor2_time1 ~~ factor3_time1
# all time 2 factors with each other
factor1_time2 ~~ factor2_time2
factor1_time2 ~~ factor3_time2
factor2_time2 ~~ factor3_time2
# factor1_time1 with all Time 2 factors
factor1_time1 ~~ factor1_time2
factor1_time1 ~~ factor2_time2
factor1_time1 ~~ factor3_time2
# factor2_time1 with all Time 2 factors
factor2_time1 ~~ factor1_time2
factor2_time1 ~~ factor2_time2
factor2_time1 ~~ factor3_time2
# factor3_time1 with all Time 2 factors
factor3_time1 ~~ factor1_time2
factor3_time1 ~~ factor2_time2
factor3_time1 ~~ factor3_time2
# Lag item residuals ---
#factor1 items
var1_t1 ~~ var1_t2
var2_t1 ~~ var2_t2
var3_t1 ~~ var3_t2
#factor2 items
var4_t1 ~~ var4_t2
var5_t1 ~~ var5_t2
var6_t1 ~~ var6_t2
#factor 3 times
var7_t1 ~~ var7_t2
var8_t1 ~~ var8_t2
var9_t1 ~~ var9_t2
'
(Credit to this answer goes to Dr. Jorgensen from the University of Amsterdam)
library(lavaan)
HS.model <- '
group: 1
visual =~ x1 + a*x2 + b*x3
textual =~ x4 + x5 + x6
group: 2
visual =~ x1 + a*x2 + b*x3
speed =~ x7 + x8 + x9
'
fit <- cfa(HS.model, data=HolzingerSwineford1939, group="school")