title: lavaan - measurement Invariance
body: <p>I want to test for metric equivalence by gender, but i get an error.</p>
  
  <p>I have the following correlation matrix:</p>
  
  <p>(How can I obtain an output in the console that gives me a reproducible covariance/correlation matrix with the sds)?</p>
  
  <pre><code>&gt; 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 &lt;- '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'
  </code></pre>
  
  <p>Now I want to assess if there is a difference in perception of trade unions between males and females. </p>
  
  <p>I both tried the command for measurement invariace and also did it manually. </p>
  
  <p>In both cases I get an error: </p>
  
  <pre><code>&gt; 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
  &gt; fit3.2b &lt;- 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
  </code></pre>
  
  <p>I have read that this is due to the negative covariance caused by my error covariance. But despite of removing the error covariances <code>V37 ~~ V</code> and <code>V37 ~~ V38</code> I get the same error. </p>
  
  <h1>Question:</h1>
  
  <p>How can I assess measurement invariance?</p>