lavaan warning message: some estimated variances are negative

6,584 views
Skip to first unread message

Chan Jun Han

unread,
Feb 22, 2016, 10:04:44 AM2/22/16
to lavaan
Hi all,

I'm relatively new to lavaan and was running a sem model as follows:

optimism_model_1B = '#latent variables
                     social_well_being =~ 1*faces_total_sa + faces_total_sc
                     optimism =~ 1*opt_total_s
                     stress_in_life =~ 1*les_total_s
                     mental_health =~ 1*ghq_total_s
                     #Regression
                     mental_health ~ social_well_being + optimism + stress_in_life
                     optimism ~ social_well_being 
                     # residual variances of manifest variables
                     faces_total_sa ~~ faces_total_sa
                     faces_total_sc ~~ faces_total_sc
                     opt_total_s ~~ opt_total_s
                     les_total_s ~~ les_total_s
                     ghq_total_s ~~ ghq_total_s
                     # factor variances
                     social_well_being ~~ 1*social_well_being
                     optimism ~~ 1*optimism
                     stress_in_life ~~ 1*stress_in_life
                     mental_health ~~ 1*mental_health
                     # factor covariances 
                     faces_total_sa ~~ faces_total_sc
                     faces_total_sa ~~ les_total_s'

fit = lavaan(optimism_model_1B, data = student, estimator ="MLM", likelihood = "wishart", int.ov.free=TRUE, int.lv.free=FALSE)

summary(fit, fit.measures = TRUE, standardized=TRUE)

However I received the following warning messages in lavaan:

Warning messages:
1: In lav_object_post_check(lavobject) :
  lavaan WARNING: some estimated variances are negative
2: In lav_object_post_check(lavobject) :
  lavaan WARNING: observed variable error term matrix (theta) is not positive definite; use inspect(fit,"theta") to investigate.

The output of lavaan is given below:

lavaan (0.5-20) converged normally after  28 iterations

  Number of observations                          1918

  Estimator                                         ML      Robust
  Minimum Function Test Statistic                6.264       5.976
  Degrees of freedom                                 3           3
  P-value (Chi-square)                           0.099       0.113
  Scaling correction factor                                  1.048
    for the Satorra-Bentler correction

Model test baseline model:

  Minimum Function Test Statistic             2720.645    2216.119
  Degrees of freedom                                10          10
  P-value                                        0.000       0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.999       0.999
  Tucker-Lewis Index (TLI)                       0.996       0.996

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -12249.722  -12249.722
  Loglikelihood unrestricted model (H1)     -12246.588  -12246.588

  Number of free parameters                         17          17
  Akaike (AIC)                               24533.444   24533.444
  Bayesian (BIC)                             24627.939   24627.939
  Sample-size adjusted Bayesian (BIC)        24573.929   24573.929

Root Mean Square Error of Approximation:

  RMSEA                                          0.024       0.023
  90 Percent Confidence Interval          0.000  0.050       0.000  0.049
  P-value RMSEA <= 0.05                          0.947       0.958

Standardized Root Mean Square Residual:

  SRMR                                           0.018       0.018

Parameter Estimates:

  Information                                 Expected
  Standard Errors                           Robust.sem

Latent Variables:
                       Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  social_well_being =~                                                      
    faces_total_sa        1.000                               1.000    0.998
    faces_total_sc        1.175    0.049   23.987    0.000    1.175    1.175
  optimism =~                                                               
    opt_total_s           1.000                               1.042    1.042
  stress_in_life =~                                                         
    les_total_s           1.000                               1.000    1.000
  mental_health =~                                                          
    ghq_total_s           1.000                               1.146    1.148

Regressions:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  mental_health ~                                                       
    social_wll_bng    0.224    0.022   10.259    0.000    0.195    0.195
    optimism          0.435    0.024   18.361    0.000    0.395    0.395
    stress_in_life    0.042    0.019    2.232    0.026    0.037    0.037
  optimism ~                                                            
    social_wll_bng    0.291    0.024   12.075    0.000    0.280    0.280

Covariances:
                    Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  faces_total_sa ~~                                                      
    faces_total_sc    -0.418    0.063   -6.635    0.000   -0.418  -10.061
    les_total_s       -0.066    0.014   -4.583    0.000   -0.066  -97.005

Intercepts:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
    faces_total_sa   -0.000    0.023   -0.000    1.000   -0.000   -0.000
    faces_total_sc   -0.000    0.023   -0.000    1.000   -0.000   -0.000
    opt_total_s       0.000    0.023    0.000    1.000    0.000    0.000
    les_total_s      -0.000    0.023   -0.000    1.000   -0.000   -0.000
    ghq_total_s       0.000    0.023    0.000    1.000    0.000    0.000
    social_wll_bng    0.000                               0.000    0.000
    optimism          0.000                               0.000    0.000
    stress_in_life    0.000                               0.000    0.000
    mental_health     0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
    faces_total_sa    0.005    0.035    0.129    0.897    0.005    0.005
    faces_total_sc   -0.381    0.119   -3.208    0.001   -0.381   -0.381
    opt_total_s      -0.085    0.033   -2.580    0.010   -0.085   -0.085
    les_total_s      -0.000    0.051   -0.002    0.998   -0.000   -0.000
    ghq_total_s      -0.317    0.024  -13.013    0.000   -0.317   -0.318
    social_wll_bng    1.000                               1.000    1.000
    optimism          1.000                               0.922    0.922
    stress_in_life    1.000                               1.000    1.000
    mental_health     1.000                               0.761    0.761

Would appreciate if anyone can point out what's wrong with my analysis such that I have the error messages as prompted by lavaan.

Thank you.

Edward Rigdon

unread,
Feb 22, 2016, 11:40:10 AM2/22/16
to lav...@googlegroups.com
     Both of the warning messages are tied to the parameter estimates listed under "Variances" in the output.  Note that the (residual) variance estimates for several of your observed variables are negative.  Even one negative variance will typically make the matrix of residual covariances be not positive definite,so both messages are really telling you about the same thing.
    There is a conflict in your syntax.  You specify that the first loading for each factor must be fixed at 1, as in:
                     social_well_being =~ 1*faces_total_sa + faces_total_sc
.  This constrains the variance of the associated factor to be equal to variance(y) - residual variance(y), where y is the observed variable whose loading is fixed to 1. But you also specify that the variance of each factor must be equal to 1, as in:
                     social_well_being ~~ 1*social_well_being
This is a conflict.  .Where the factor is dependent on another factor, this specification affects the residual variance of the factor, ratehr than the total variance, but it is still likely to be inconfict with the loading-fixed-to-1 specification.
     My advice is to delete the lines of code where you set factor variances (or residual variances) to 1:
                     # factor variances
                     social_well_being ~~ 1*social_well_being
                     optimism ~~ 1*optimism
                     stress_in_life ~~ 1*stress_in_life
                     mental_health ~~ 1*mental_health
Comment out those lines (or delete them), and I believe this particular issue will be removed.
--Ed Rigdon

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Chris

unread,
Feb 22, 2016, 9:45:30 PM2/22/16
to lavaan
Hi Edward,

Thank you for the reply. I tried to remove the factor variances like you suggested but end up with a different warning message instead,

optimism_model_1B = '#latent variables
                     social_well_being =~ 1*faces_total_sa + faces_total_sc
                     optimism =~ 1*opt_total_s
                     stress_in_life =~ 1*les_total_s
                     mental_health =~ 1*ghq_total_s
                     #Regression
                     mental_health ~ social_well_being + optimism + stress_in_life
                     optimism ~ social_well_being 
                     # residual variances of manifest variables
                     faces_total_sa ~~ faces_total_sa
                     faces_total_sc ~~ faces_total_sc
                     opt_total_s ~~ opt_total_s
                     les_total_s ~~ les_total_s
                     ghq_total_s ~~ ghq_total_s
                     # factor covariances 
                     faces_total_sa ~~ faces_total_sc
                     faces_total_sa ~~ les_total_s'

Warning messages:
1: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
  lavaan WARNING: could not compute standard errors!
  lavaan NOTE: this may be a symptom that the model is not identified.

2: In lav_model_test(lavmodel = lavmodel, lavpartable = lavpartable,  :
  lavaan WARNING: could not compute scaled test statistic

I also tried to not restrict the factor variances to 1 but rather letting the model freely estimate them. In that scenario, I obtain just 1 warning message.

optimism_model_1B = '#latent variables
                     social_well_being =~ 1*faces_total_sa + faces_total_sc
                     optimism =~ 1*opt_total_s
                     stress_in_life =~ 1*les_total_s
                     mental_health =~ 1*ghq_total_s
                     #Regression
                     mental_health ~ social_well_being + optimism + stress_in_life
                     optimism ~ social_well_being 
                     # residual variances of manifest variables
                     faces_total_sa ~~ faces_total_sa
                     faces_total_sc ~~ faces_total_sc
                     opt_total_s ~~ opt_total_s
                     les_total_s ~~ les_total_s
                     ghq_total_s ~~ ghq_total_s
                     # factor variances
                     social_well_being ~~ social_well_being
                     optimism ~~ optimism
                     stress_in_life ~~ stress_in_life
                     mental_health ~~ mental_health
                     # factor covariances 
                     faces_total_sa ~~ faces_total_sc
                     faces_total_sa ~~ les_total_s'

Warning message:
In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
  lavaan WARNING: could not compute standard errors!
  lavaan NOTE: this may be a symptom that the model is not identified.

I am just thinking whether it could be because I have a low number of indicator variables for each latent variable because I read somewhere that there is a recommended number of indicators per latent variable for proper solutions and model identification?

Edward Rigdon

unread,
Feb 22, 2016, 10:28:12 PM2/22/16
to lav...@googlegroups.com
Chris--
What function are you using?  If you are using the lavaan function, then you would nee to fix residual variances for the observed variables that are single indicators for their factors (the indicators for optimism, stress in life and mental health).  If you were using the sem function, then by default these residual variances would be fixed to 0--though you could set them to different values.  With the lavaan function, I can see how both fixing first loadings and fixing factor variances could conceal the identification problem.  But if you just switch to the sem function, I believe that will eliminate the warning about an identification problem.
--Ed Rigdon

Chris

unread,
Feb 23, 2016, 5:28:32 AM2/23/16
to lavaan
Hi Edward,

I was initially using the lavaan function, but tried to switch to the sem function as you suggested and left the residual variances specifications to the automated default by sem.

optimism_model_1B = '#latent variables
                      social_well_being =~ faces_total_sa + faces_total_sc
                      optimism =~ opt_total_s
                      stress_in_life =~ les_total_s
                      mental_health =~ ghq_total_s
                      #Regression
                      mental_health ~ social_well_being + optimism + stress_in_life
                      optimism ~ social_well_being'

fit = sem(optimism_model_1B, data = student, estimator ="MLM", likelihood = "wishart")

Initially the warning messages disappear, but as I tried to introduce some factor covariances through modification indices, one warning message struck back

optimism_model_1B = '#latent variables
                      social_well_being =~ faces_total_sa + faces_total_sc
                      optimism =~ opt_total_s
                      stress_in_life =~ les_total_s
                      mental_health =~ ghq_total_s
                      #Regression
                      mental_health ~ social_well_being + optimism + stress_in_life
                      optimism ~ social_well_being
                      #factor covariances
                      faces_total_sa ~~ les_total_s'

Warning message:
In lav_object_post_check(lavobject) :
  lavaan WARNING: observed variable error term matrix (theta) is not positive definite; use inspect(fit,"theta") to investigate.

Am I still doing something wrong in my model specification? Thanks so much for your help thus far.

Edward Rigdon

unread,
Feb 23, 2016, 9:28:39 AM2/23/16
to lav...@googlegroups.com
Chris--
In your new model syntax, the lines:
                     # factor covariances 
                     faces_total_sa ~~ faces_total_sc
                     faces_total_sa ~~ les_total_s'
refer to observed variables, not factors. In fact, since these variables are dependent on factors, these lines refer to the residual variances of these observed variables.   Your ability to allow free residual covariances is limited by the factor model that you are attempting to estimate. The only common factors in your model are social well being, optimism, stress in life and mental health. Some of the covariances or residual covariances among these common factors are free by default. Some cannot be freed without wrecking the regression relationships that you are trying to estimate.
--Ed Rigdon
Reply all
Reply to author
Forward
0 new messages