I am trying to run a mediation model examining country group differences in impression management. I am having some difficulty diagnosing the problem in my lavaan model.

I have three groups: country A (n = 300), country B (n = 325), and country C (n = 320), which are dummy coded into variables A and B.

I specified my mediation model as follows:

model<- '#Imp Mgmt Styles Factor
      sprom =~ IM_Sup08+IM_Pr28+IM_Sup27+IM_Pr08+IM_Pr28+IM_Pr27+IM_Sub08+IM_Sub28+IM_Sub27
      ingrt =~ IM_Sup14+IM_Sup15+IM_Sup19+IM_Pr14+IM_Pr15+IM_Pr19+IM_Sub14+IM_Sub15+IM_Sub19
      exemp =~ IM_Sup06+IM_Sup07+IM_Sup29+IM_Pr06+IM_Pr07+IM_Pr29+IM_Sub06+IM_Sub07+IM_Sub29

      #Target Factor
      super =~ IM_Sup08+IM_Sup28+IM_Sup27+IM_Sup14+IM_Sup15+IM_Sup19+IM_Sup06+IM_Sup07+IM_Sup29
      peer =~ IM_Pr08+IM_Pr28+IM_Pr27+IM_Pr14+IM_Pr15+IM_Pr19+IM_Pr06+IM_Pr07+IM_Pr29
      sub =~ IM_Sub08+IM_Sub28+IM_Sub27+IM_Sub14+IM_Sub15+IM_Sub19+IM_Sub06+IM_Sub07+IM_Sub29

      sprom ~ TrnvPssb
      ingrt ~ TrnvPssb
      exemp ~ TrnvPssb

      super ~ TrnvPssb
      peer ~ TrnvPssb
      sub ~ TrnvPssb

      TrnvPssb ~ A + B'

fit<-cfa(model = model, std.lv = TRUE, data = dt, estimator = "WLSMV")

When I attempt to run it, I get the error lavaan ERROR: sample covariance matrix is not positive-definite. I have dismantled and tested every other part of the model so I know that the problem is not with the other parts of the model. In fact, I can run it with just one of the dummy-coded variables (A or B) and it works perfectly.

I wonder if it is a shared variance issue with the grouping variable. How would I be able to test this and fix it?

Thank you for sharing your knowledge and expertise.


1 Answer 1


This is a general SEM problem, not a lavaan problem.

Something has gone wrong with your sample covariance matrix. It's hard to know what, but you can tell by looking at it. It shouldn't matter what your model looks like, this error is about your data.



If it's not clear from that, paste the output and come back.

  • 1
    $\begingroup$ Great advice, I took a closer look at the covariance matrix and found that the two dummy-coded variables had a strange negative covariance. There was an error in how the variables were constructed. Once I resolved the error it worked just fine. Thanks again for your help. $\endgroup$
    – Xander
    Dec 5, 2016 at 0:34
  • $\begingroup$ When I Use lavaan and gets "lavaan ERROR: sample covariance matrix is not positive-definite", I cannot use any lavaan stat because "fit" does not exists. Model was not run due to that error. $\endgroup$ Mar 1, 2019 at 21:09
  • $\begingroup$ There's a problem with your data. Check the correlation matrix. $\endgroup$ Mar 3, 2019 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.