warnings when attempting to fit CFA model to imputed data

2,572 views
Skip to first unread message

garc...@unlv.nevada.edu

unread,
Jul 23, 2018, 6:06:53 PM7/23/18
to lavaan
Hello, 

I am currently working on a project where I am fitting several CFA models to imputed data. I am running into an issue where I get warnings when attempting to fit the models even though, according to the output, they seem to be converging normally.

Here is the syntax I am running: 

# Model B- Two factor (noncompliance & negative affect)
# Specify Model B
mod.b2 <- 'NonComp.f =~ odd1sc + odd2sc + odd3sc + odds4sc + odds5sc + odds6sc
          NA.f  =~ odds1sc + odds2sc + odds3sc
          NonComp.f ~~ NA.f'
# Fit Model B
fit.mod.b2.wlsmvs.mi <- runMI(model = mod.b2, data = bag.sem, fun = "cfa", 
                              estimator = "WLSMVS", std.lv = TRUE, verbose = TRUE, control = list(rel.tol = 1e-4), 
                              ordered = c("odd1sc", "odd2sc", "odd3sc", "odds1sc", "odds2sc", 
                                          "odds3sc", "odds4sc", "odds5sc", "odds6sc"))

Here is the output:

lavaan.mi object based on 30 imputed data sets. 
See class?lavaan.mi help page for available methods. 

Convergence information:
The model converged on 30 imputed data sets 

Rubin's (1987) rules were used to pool point and SE estimates across 30 imputed data sets, and to calculate degrees of freedom for each parameter's t test and CI.

Parameter Estimates:

  Information                                 Expected
  Information saturated (h1) model        Unstructured
  Standard Errors                           Robust.sem

Latent Variables:
                   Estimate  Std.Err  t-value       df  P(>|t|)
  NonComp.f =~                                                 
    odd1sc            0.841    0.020   41.949      Inf    0.000
    odd2sc            0.851    0.018   46.639      Inf    0.000
    odd3sc            0.795    0.022   36.032      Inf    0.000
    odds4sc           0.495    0.037   13.320  730.651    0.000
    odds5sc           0.638    0.031   20.569 1093.553    0.000
    odds6sc           0.679    0.029   23.579 1050.360    0.000
  NA.f =~                                                      
    odds1sc           0.815    0.021   39.312  785.371    0.000
    odds2sc           0.902    0.015   59.176  789.892    0.000
    odds3sc           0.694    0.029   23.941  713.587    0.000

Covariances:
                   Estimate  Std.Err  t-value       df  P(>|t|)
  NonComp.f ~~                                                 
    NA.f              0.950    0.016   60.938  660.708    0.000

Intercepts:
                   Estimate  Std.Err  t-value       df  P(>|t|)
   .odd1sc            0.000                                    
   .odd2sc            0.000                                    
   .odd3sc            0.000                                    
   .odds4sc           0.000                                    
   .odds5sc           0.000                                    
   .odds6sc           0.000                                    
   .odds1sc           0.000                                    
   .odds2sc           0.000                                    
   .odds3sc           0.000                                    
    NonComp.f         0.000                                    
    NA.f              0.000                                    

Thresholds:
                   Estimate  Std.Err  t-value       df  P(>|t|)
    odd1sc|t1        -0.710    0.051  -13.877      Inf    0.000
    odd1sc|t2        -0.102    0.047   -2.185      Inf    0.029
    odd2sc|t1        -0.722    0.051  -14.070      Inf    0.000
    odd2sc|t2        -0.027    0.047   -0.580      Inf    0.562
    odd3sc|t1        -0.668    0.051  -13.196      Inf    0.000
    odd3sc|t2        -0.011    0.047   -0.229      Inf    0.819
    odds4sc|t1       -0.143    0.047   -3.050 1261.238    0.002
    odds4sc|t2        0.521    0.049   10.637 2043.255    0.000
    odds5sc|t1       -0.541    0.049  -10.985 2409.018    0.000
    odds5sc|t2        0.100    0.047    2.144 3309.839    0.032
    odds6sc|t1       -0.708    0.051  -13.838  754.554    0.000
    odds6sc|t2       -0.013    0.047   -0.281      Inf    0.778
    odds1sc|t1       -0.636    0.050  -12.665 1664.714    0.000
    odds1sc|t2        0.027    0.047    0.578      Inf    0.563
    odds2sc|t1       -0.434    0.048   -8.997 2695.879    0.000
    odds2sc|t2        0.217    0.047    4.622      Inf    0.000
    odds3sc|t1       -0.362    0.048   -7.582 1167.343    0.000
    odds3sc|t2        0.344    0.048    7.212 6106.076    0.000

Variances:
                   Estimate  Std.Err  t-value       df  P(>|t|)
   .odd1sc            0.293                                    
   .odd2sc            0.276                                    
   .odd3sc            0.368                                    
   .odds4sc           0.754                                    
   .odds5sc           0.593                                    
   .odds6sc           0.539                                    
   .odds1sc           0.336                                    
   .odds2sc           0.186                                    
   .odds3sc           0.519                                    
    NonComp.f         1.000                                    
    NA.f              1.000                                    

Scales y*:
                   Estimate  Std.Err  t-value       df  P(>|t|)
    odd1sc            1.000                                    
    odd2sc            1.000                                    
    odd3sc            1.000                                    
    odds4sc           1.000                                    
    odds5sc           1.000                                    
    odds6sc           1.000                                    
    odds1sc           1.000                                    
    odds2sc           1.000                                    
    odds3sc           1.000  

And here are the warnings:

Warning messages:
1: In lavaan::lavaan(model = "NonComp.f =~ odd1sc + odd2sc + odd3sc + odds4sc + odds5sc + odds6sc\n          NA.f  =~ odds1sc + odds2sc + odds3sc\n          NonComp.f ~~ NA.f",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
2: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
3: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
4: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
5: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
6: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
7: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
8: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
9: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
10: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
11: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
12: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
13: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
14: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
15: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
16: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
17: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
18: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
19: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
20: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
21: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
22: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
23: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
24: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
25: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
26: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
27: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate
28: In lavaan(slotOptions = structure(list(model.type = "cfa",  ... :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate

Given that I am new to R/lavaan and my knowledge base for SEM is moderate at best, I am hoping someone is able to explain these warning messages to me and whether they are something I should be concerned about. 

Thank you in advance!


Terrence Jorgensen

unread,
Jul 24, 2018, 8:35:42 AM7/24/18
to lavaan
I am hoping someone is able to explain these warning messages to me and whether they are something I should be concerned about. 

Warnings indicate there might be a problem, not necessarily that there is one.  It is up to the user to figure that out.  If you want to look into the information suggested by the warning, you can add a user-defined function to your lavaan.mi object using the FUN= argument.  See the ordered-categorical example at the bottom of the ?runMI help page to see how you can extract lavInspect() (or other) output from each imputation and inspect results afterward.  Instead of "zero.cell.tables" in the example, you could just request "optim.gradient".

But the SEs are all small relative to the estimates, so I am guessing there isn't a problem.  If there were a problem, I would imagine different local minima would be found using different imputations (although maybe the fraction of missing information is low), which would increase the between-imputation variance and inflate the SEs.  You could also try fitting the model to the unimputed data with missing = "pairwise" to see if those estimates differ greatly from the pooled results over imputations (although differences could be expected if data are MAR rather than MCAR.

Terrence D. Jorgensen
Postdoctoral Researcher, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

garc...@unlv.nevada.edu

unread,
Jul 25, 2018, 6:16:50 PM7/25/18
to lavaan
Hello Dr. Jorgensen,

Thank you for your response!

I did as was suggested by both you and the warnings I received and tried the lavInspect(object, what = "optim.gradient") function to attempt to find out more information about what the warnings are telling me. However this returns an error that says "Error in lavListInspect(object = object, what = what, add.labels = add.labels,  : object 'optim.gradient' not found". 

Additionally, I tried both lavInspect(object, what = "optim") and lavInspect(object, what = "gradient"). Both returned the similar error messages saying that object'optim' and object'gradient' could not be found. 

Here is the code I ran:
lavInspect(fit.mod.b2.wlsmvs.mi, what = "optim.gradient")

The fit.mod object is the object I used to fit my model. Is it something on my end that I am doing wrong? Any advice would be much appreciated.

Thank you,
Breanna Garcia 

Terrence Jorgensen

unread,
Jul 29, 2018, 6:29:15 PM7/29/18
to lavaan
"Error ...  : object 'optim.gradient' not found". 

That sounds like you forgot to put "optim.gradient" in quotation marks, like this:

example(cfa)
lavInspect
(fit, optim.gradient)

Message has been deleted

Yves Rosseel

unread,
Jul 31, 2018, 5:14:34 AM7/31/18
to lav...@googlegroups.com
>  Error in lavListInspect(object = object, what = what, add.labels =
> add.labels,  :
>  unknown `what' argument in inspect function: `optim.gradient'

Indeed, this will not work (yet, 0.6-2). The lavListInspect() function
only offers a tiny subset of the lavInspect() options. The reason is
that the semList() function does not store 'full' lavaan objects, as
this would not scale (if the number of datasets gets large).

For your setting, I would run one imputed dataset at a time, using
regular sem(), and use the lavInspect(fit, "optim.gradient") to check
the gradient afterwards.

Yves.

Shimon Sarraf

unread,
Nov 13, 2018, 1:43:51 PM11/13/18
to lavaan

I encountered a similar warning message while running a growth curve model with squared and cubed slopes. The variances of s2 and s3 (the squared and cubed slopes in my model) are both negative. Is this the reason for the error message? I understand that negative variances generally speaking are problematic but want to confirm in this case. Any references about how to address this issue are much appreciated. By the way, all model fit statistics and parameter standard errors seem satisfactory.
Thank you,
Shimon
PS: here's my output...
lavInspect(RR.fit.b1, "optim.gradient")
(eq.con)     i~~i     s~~s   s2~~s2   s3~~s3     i~~s    i~~s2    i~~s3    s~~s2    s~~s3 
   0.000    0.000    0.000   -0.017   -0.956    0.000   -0.001   -0.004   -0.005   -0.035 
  s2~~s3      i~1      s~1     s2~1     s3~1 
  -0.251    0.000    0.000    0.000    0.000

Terrence Jorgensen

unread,
Nov 22, 2018, 8:54:55 AM11/22/18
to lavaan
I encountered a similar warning message ... Is this the reason for the error message?

Is it a warning or error?  Heywood cases produce warnings because there might be a problem that deserves some attention.  If your model has decent fit, I typically recommend looking at the CIs to see if your estimates include plausible values, in which case the Heywood case is consistent with sampling error.  


In the context of growth modeling, imagine you were using multilevel modeling.  Would you allow the quadratic and cubic slopes to be random, or only the linear one?  If it is plausible that they are fixed across subjects, then that would mean the population variances of those growth factors are zero.  But unlike MLM software, SEM software will not automatically force variances to be non-negative.  That is actually a good thing, because forcing a negative maximum-likelihood estimate to be zero would mean your chi-squared statistic is no longer distributed as expected.


Unconstrained estimation is better, and you can interpret the interval estimate (95% CI) instead of the point estimate.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam
Reply all
Reply to author
Forward
0 new messages