I’m facing a challenge with specifying a CFA model using lavaan in R. The model requires that an observed variable’s error is fixed to the sum of two different covariances between unique items.
For example, the error for y1,2 should equal the sum of its covariance with y1,3 and its covariance with y*2,3.
Below is a simplified version of my current lavaan code:
cfa_model <- '
C =~ C1_12*i1i2 + C1_13*i1i3 + C2_12*i4i5 + C2_13*i4i6 + C3_12*i7i8 + C3_13*i7i9
R =~ R1_12*i1i2 + R1_23*i2i3 + R2_12*i4i5 + R2_23*i5i6 + R3_12*i7i8 + R3_23*i8i9
O =~ O1_13*i1i3 + O1_23*i2i3 + O2_13*i4i6 + O2_23*i5i6 + O3_13*i7i9 + O3_23*i8i9
# Additional constraints and covariances
i1i2~~i1i3
i1i2~~i2i3
i1i3~~i2i3
'
How can I adjust the lavaan syntax to explicitly fix an error term as the sum of specific covariances? Any guidance is appreciated!
have u tried using phantom variables? they can help set error terms as covariance sums. basically create phantom vars for each covariance pair, set their variances to 1, fix covariances between phantoms and observed vars, then make a composite. might look like:
i1i2_ph1 =~ 0i1i2
i1i2_ph2 =~ 0i1i2
i1i2_ph1 ~~ 1i1i2_ph1
i1i2_ph2 ~~ 1i1i2_ph2
i1i2_ph1 ~~ ai1i3
i1i2_ph2 ~~ bi2i3
i1i2 =~ 1i1i2_ph1 + 1i1i2_ph2
hope this helps!
Hey there!
Your CFA model sounds super interesting! I’m curious, have you considered using equality constraints to achieve what you’re after? 
Something like this might work:
cfa_model <- '
# Your existing model spec
# ...
# Define error terms
i1i2 ~~ e1*i1i2
i1i3 ~~ e2*i1i3
i2i3 ~~ e3*i2i3
# Set error term as sum of covariances
e1 == cov1 + cov2
i1i2 ~~ cov1*i1i3
i1i2 ~~ cov2*i2i3
'
What do you think?
Have you tried something similar before? I’m really curious to hear more about your model and what you’re trying to achieve with it! What kind of data are you working with?
As someone who’s worked extensively with lavaan for CFA modeling, I can offer some insights into your problem. Setting error terms as the sum of exogenous correlations isn’t straightforward in lavaan’s standard syntax, but there’s a workaround using phantom variables.
Here’s an approach you could try:
- Create phantom variables for each pair of covariances you want to sum.
- Set the variances of these phantom variables to 1.
- Fix the covariances between the phantom variables and the observed variables to the desired values.
- Create a composite of these phantom variables and fix its loading to 1 for the target observed variable.
Your lavaan syntax might look something like this:
cfa_model <- '
# Your existing model specification
# ...
# Phantom variables
i1i2_ph1 =~ 0*i1i2
i1i2_ph2 =~ 0*i1i2
i1i2_ph1 ~~ 1*i1i2_ph1
i1i2_ph2 ~~ 1*i1i2_ph2
i1i2_ph1 ~~ a*i1i3
i1i2_ph2 ~~ b*i2i3
i1i2 =~ 1*i1i2_ph1 + 1*i1i2_ph2
'
This approach allows you to indirectly set the error term of i1i2 as the sum of its covariances with i1i3 and i2i3. You’d need to repeat this for each observed variable where you want to apply this constraint.