Adam K - 6 months ago 37

R Question

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`

`lavaan`

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

'

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

(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")
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**