Search code examples
rr-lavaanstructural-equation-model

lavaan - measurement Invariance


I want to test for metric equivalence by gender, but i get an error.

I have the following correlation matrix:

(How can I obtain an output in the console that gives me a reproducible covariance/correlation matrix with the sds)?

> cor(sub1, use="pairwise.complete.obs")
             V24          V25         V52          V53          V54         V37
V24  1.000000000  0.697521674  0.01568641  0.018252279  0.007213654  0.04335144
V25  0.697521674  1.000000000 -0.01564264  0.004665397 -0.015039173  0.04004168
V52  0.015686412 -0.015642643  1.00000000  0.546989009  0.340628957 -0.05174745
V53  0.018252279  0.004665397  0.54698901  1.000000000  0.438693604 -0.07044378
V54  0.007213654 -0.015039173  0.34062896  0.438693604  1.000000000 -0.08113154
V37  0.043351436  0.040041675 -0.05174745 -0.070443778 -0.081131539  1.00000000
V38  0.098512813  0.066579287 -0.05594164 -0.091231815 -0.024566416  0.37069002
V39  0.001098530  0.026309212 -0.06166382 -0.059972262 -0.076980805  0.43970024
V40  0.049227113  0.043209425 -0.04630234 -0.061524717 -0.011688956  0.23091762
SEX -0.041446974 -0.015998972  0.07623627  0.026067738  0.043030238 -0.03215834
            V38         V39         V40         SEX
V24  0.09851281  0.00109853  0.04922711 -0.04144697
V25  0.06657929  0.02630921  0.04320942 -0.01599897
V52 -0.05594164 -0.06166382 -0.04630234  0.07623627
V53 -0.09123182 -0.05997226 -0.06152472  0.02606774
V54 -0.02456642 -0.07698080 -0.01168896  0.04303024
V37  0.37069002  0.43970024  0.23091762 -0.03215834
V38  1.00000000  0.17530099  0.48481632  0.13427571
V39  0.17530099  1.00000000  0.23179996  0.01046066
V40  0.48481632  0.23179996  1.00000000  0.24838303
SEX  0.13427571  0.01046066  0.24838303  1.00000000


model3.2 <- 'union =~ V24 + V25
loyality =~ V52 + V53 + V54
experience =~ V37 + V38 + V39 + V40
union ~ loyality + experience
experience ~~ loyality
V37 ~~ V39
V37 ~~ V38
experience ~ SEX
loyality ~ SEX'

Now I want to assess if there is a difference in perception of trade unions between males and females.

I both tried the command for measurement invariace and also did it manually.

In both cases I get an error:

> measurementInvariance(model3.2, data = sub1, group = "SEX")
Error in lav_model_estimate(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  : 
  lavaan ERROR: initial model-implied matrix (Sigma) is not positive definite;
  check your model and/or starting parameters in group 1.
In addition: Warning messages:
1: In lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  :
  lavaan WARNING sample covariance matrix in group: 1 is not positive-definite
2: In lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  :
  lavaan WARNING sample covariance matrix in group: 2 is not positive-definite
> fit3.2b <- cfa(fit3.2 , data=sub1, group="SEX")
Error in Sigma.hat[[g]] : subscript out of bounds
In addition: Warning messages:
1: In lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  :
  lavaan WARNING sample covariance matrix in group: 1 is not positive-definite
2: In lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  :
  lavaan WARNING sample covariance matrix in group: 2 is not positive-definite

I have read that this is due to the negative covariance caused by my error covariance. But despite of removing the error covariances V37 ~~ V and V37 ~~ V38 I get the same error.

Question:

How can I assess measurement invariance?


Solution

  • If you simplify your model, this is what you have:

    model3.2 <- '
    

    Measurement model:

    union =~ V24 + V25
    loyality =~ V52 + V53 + V54
    experience =~ V37 + V38 + V39 + V40
    

    Structural model:

    experience ~ SEX
    loyality ~ SEX    
    union ~ loyality + experience
    

    (experience ~~ loyalty) is already implied when you have them simultaneously predicting the same thing. Try running it with and without that—you'll get the same thing.

    Correlated residuals:

    V37 ~~ V39
    V37 ~~ V38'
    

    So it is similar to a mediation model: Sex predicts experience, which in turn predicts union. At the same time, sex predicts loyality, which in turn predicts union.

    When you do measurement invariance, you are trying to see if the model is more or less the same across groups (depending on what type of invariance you are testing for). The issue is that, with the model you specified, you are already testing for group differences. You are testing to see if the mean of the latent constructs of experience and loyalty differ by sex. It is the same thing that you would try to do by testing for latent mean invariance.

    Your code is not reproducible (SEX is a group and thus cannot be recreated using a correlation matrix), but I believe that this model would work:

    model3.2 <- '
    # MEASUREMENT
    union =~ V24 + V25
    loyality =~ V52 + V53 + V54
    experience =~ V37 + V38 + V39 + V40
    
    # STRUCTURAL
    union ~ loyality + experience
    
    # CORRELATED RESIDUALS
    V37 ~~ V39
    V37 ~~ V38'
    

    Again, you could then test if the latent means for experience and loyality differ by sex when you get past measurement invariance and move on to testing invariance in the latent space.