Model estimation FAILED! Returning starting values

2,123 views
Skip to first unread message

Michael Filsecker

unread,
May 17, 2023, 6:39:49 AM5/17/23
to lavaan
Dear Lavaaners,

I was trying to replicate a model from a correlation matrix from the study of Meece et al () Students goal orientation and cognitive engagement in class activities. I just copy the correlation matrix and did de following:


lower <- '
 0.42
0.27 0.63
0.24 0.39 0.56
0.03 0.23 0.46 0.48
-0.19 -0.15 -0.20 -0.14 0.13
-0.21 -0.22 -0.40 -0.35 -0.50 0.29
0.04 0.16 0.37 0.31 0.70 0.21 -0.39
0.28 -0.26 -0.41 -0.36 -0.43 0.33 0.71 -0.34'

meece <- getCov(lower, diagonal = FALSE)

model1<-'V8~V3+V5+V6
V5~V3+V4
V6~V3+V4+V5
'
fit1<-lavaan(model1, sample.cov = meececov, sample.nobs=256)

Results: Model estimation FAILED! Returning starting values

Why is the model estimation not achieved? what can I do with the info about the starting values?

Attach a picture of the model.

Thank you!


Meece Pfad Analysis.PNG
Meece Pfad Analysis.PNG

Edward Rigdon

unread,
May 17, 2023, 11:15:21 AM5/17/23
to lav...@googlegroups.com
This is actually more interesting than you let on. When I run this code (fixing the error in the lavaan() call, I get a dump:
> fit1<-lavaan(model1, sample.cov = meece, sample.nobs=256)
            [,1]       [,2]        [,3]       [,4]       [,5]
[1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
[2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
[3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
[4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
[5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
            [,1]       [,2]        [,3]       [,4]       [,5]
[1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
[2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
[3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
[4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
[5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
            [,1]       [,2]        [,3]       [,4]       [,5]
[1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
[2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
[3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
[4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
[5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
            [,1]       [,2]        [,3]       [,4]       [,5]
[1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
[2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
[3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
[4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
[5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
Warning message:
In lavaan(model1, sample.cov = meece, sample.nobs = 256) : lavaan WARNING:
    Model estimation FAILED! Returning starting values.

I've never seen that before.

If you change the call from lavaan() to sem(), the model runs fine.

This is just a path analysis so it should run easy-peasy, unless there is some substantial data error. You may have uncovered a bug in the lavaan() function.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/4da8cf71-9385-4978-b644-0592fddf39b5n%40googlegroups.com.

Michael Filsecker

unread,
May 17, 2023, 11:45:37 AM5/17/23
to lavaan
hi Edward,

thank you for your feedback, if that is a bug, well nice to have been the one to have "discovered" it..now the expert can repair it.
I run the model in sem and worked fine I could replicate the results of the paper.

Thanks again and have a nice long weekend.
Michael.

Shu Fai Cheung

unread,
May 17, 2023, 3:09:06 PM5/17/23
to lav...@googlegroups.com
I am not sure whether we can call it a bug. (But the output can be made more informative, I think.)

Let me repeat the results here so others can see the full printout:
library(lavaan)
#> This is lavaan 0.6-15
#> lavaan is FREE software! Please report any bugs.

lower <- '
0.42
0.27 0.63
0.24 0.39 0.56
0.03 0.23 0.46 0.48
-0.19 -0.15 -0.20 -0.14 0.13
-0.21 -0.22 -0.40 -0.35 -0.50 0.29
0.04 0.16 0.37 0.31 0.70 0.21 -0.39
0.28 -0.26 -0.41 -0.36 -0.43 0.33 0.71 -0.34'

meece <- getCov(lower, diagonal = FALSE)

model1<-'V8~V3+V5+V6
V5~V3+V4
V6~V3+V4+V5
'
fit1<-lavaan(model1, sample.cov = meece, sample.nobs=256)
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#> Warning in lavaan(model1, sample.cov = meece, sample.nobs = 256): lavaan WARNING:
#>     Model estimation FAILED! Returning starting values.
lavann() is called directly. As Ed and Michael mentioned, no error if sem() is called.

This is because the model is not specified correctly if we call lavaan(), and this is expected. lavaan() assumes users have set all the arguments like int.ov.free, auto.var, etc. correctly for a model. This is complicated (to me). sem(), as a wrapper of lavaan(), sets these arguments for users. That's why we usually should use sem() instead of lavaan().

This is part of the parameter table when lavaan() is used:
ptable_lavaan <- parameterTable(fit1)
ptable_lavaan[, 1:14] #> id lhs op rhs user block group free ustart exo label plabel start est #> 1 1 V8 ~ V3 1 1 1 1 NA 0 .p1. 0.110 0.110 #> 2 2 V8 ~ V5 1 1 1 2 NA 0 .p2. 0.630 0.630 #> 3 3 V8 ~ V6 1 1 1 3 NA 0 .p3. 0.150 0.150 #> 4 4 V5 ~ V3 1 1 1 4 NA 0 .p4. 0.279 0.279 #> 5 5 V5 ~ V4 1 1 1 5 NA 0 .p5. 0.324 0.324 #> 6 6 V6 ~ V3 1 1 1 6 NA 0 .p6. -0.267 -0.267 #> 7 7 V6 ~ V4 1 1 1 7 NA 0 .p7. -0.145 -0.145 #> 8 8 V6 ~ V5 1 1 1 8 NA 0 .p8. 0.323 0.323 #> 9 9 V8 ~~ V8 0 1 1 0 0 0 .p9. 0.000 0.000 #> 10 10 V5 ~~ V5 0 1 1 0 0 0 .p10. 0.000 0.000 #> 11 11 V6 ~~ V6 0 1 1 0 0 0 .p11. 0.000 0.000 #> 12 12 V3 ~~ V3 0 1 1 0 NA 1 .p12. 0.996 0.996 #> 13 13 V3 ~~ V4 0 1 1 0 NA 1 .p13. 0.558 0.558 #> 14 14 V4 ~~ V4 0 1 1 0 NA 1 .p14. 0.996 0.996
This is the table when sem() is used:
ptable_sem <- parameterTable(fit2)
ptable_sem[, 1:14] #> id lhs op rhs user block group free ustart exo label plabel start est #> 1 1 V8 ~ V3 1 1 1 1 NA 0 .p1. 0.110 0.110 #> 2 2 V8 ~ V5 1 1 1 2 NA 0 .p2. 0.630 0.630 #> 3 3 V8 ~ V6 1 1 1 3 NA 0 .p3. 0.150 0.150 #> 4 4 V5 ~ V3 1 1 1 4 NA 0 .p4. 0.279 0.279 #> 5 5 V5 ~ V4 1 1 1 5 NA 0 .p5. 0.324 0.324 #> 6 6 V6 ~ V3 1 1 1 6 NA 0 .p6. -0.267 -0.267 #> 7 7 V6 ~ V4 1 1 1 7 NA 0 .p7. -0.145 -0.145 #> 8 8 V6 ~ V5 1 1 1 8 NA 0 .p8. 0.323 0.323 #> 9 9 V8 ~~ V8 0 1 1 9 NA 0 .p9. 0.485 0.485 #> 10 10 V5 ~~ V5 0 1 1 10 NA 0 .p10. 0.714 0.714 #> 11 11 V6 ~~ V6 0 1 1 11 NA 0 .p11. 0.881 0.881 #> 12 12 V3 ~~ V3 0 1 1 0 NA 1 .p12. 0.996 0.996 #> 13 13 V3 ~~ V4 0 1 1 0 NA 1 .p13. 0.558 0.558 #> 14 14 V4 ~~ V4 0 1 1 0 NA 1 .p14. 0.996 0.996
As shown above, the error variances of V8, V5, and V6 were fixed to zero. This can also be confirmed if we use summary(fit1):
summary(fit1)
#> lavaan 0.6.15 did not run (perhaps do.fit = FALSE)?
#> ** WARNING ** Estimates below are simply the starting values
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                         8
#> Variances:
#>                    Estimate  Std.Err  z-value  P(>|z|)
#>    .V8                0.000                           
#>    .V5                0.000                           
#>    .V6                0.000
The error variances are not fixed to zero when sem() is called, and the number of model parameters is 11 instead of 8:
summary(fit2)
#> lavaan 0.6.15 ended normally after 1 iteration
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                        11
#> Variances:
#>                    Estimate  Std.Err  z-value  P(>|z|)
#>    .V8                0.485    0.043   11.314    0.000
#>    .V5                0.714    0.063   11.314    0.000
#>    .V6                0.881    0.078   11.314    0.000
So, the problem can be produced using sem(), by setting the error variances to zero manually with V8~~0*V8, V5~~0*V5, V6~~0*V6:
model1b<-'V8~V3+V5+V6
V5~V3+V4
V6~V3+V4+V5
V8~~0*V8
V5~~0*V5
V6~~0*V6
'
fit1b<-sem(model1b, sample.cov = meece, sample.nobs=256)
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#> Warning in lavaan::lavaan(model = model1b, sample.cov = meece, sample.nobs = 256, : lavaan WARNING:
#>     Model estimation FAILED! Returning starting values.
Regarding the warning, it is due to the optimization. If we add verbose = TRUE, this is the printout:
fit1<-lavaan(model1, sample.cov = meece, sample.nobs=256, verbose = TRUE)
#> lavoptions         ... done.
#> lavdata            ... done.
#>   Number of observations                           256
#> lavpartable        ... done.
#> lavpta             ... done.
#> lavsamplestats ... done.
#> lavh1              ... start:
#> lavh1              ... done.
#> lavpartable bounds ... done.
#> lavstart           ... done.
#> lavmodel           ... done.
#> lavoptim           ... start:
#> attempt 1 -- default options
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#> attempt 2 -- optim.parscale = "standardized"
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#> attempt 3 -- start = "simple"
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#> attempt 4 -- optim.parscale = "standardized" + start = "simple"
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#> Warning in lavaan(model1, sample.cov = meece, sample.nobs = 256, verbose = TRUE): lavaan WARNING:
#>     Model estimation FAILED! Returning starting values.
#> lavoptim    ... done.
#> lavimplied  ... done.
#> lavloglik   ... done.
#> lavbaseline ... done.
lavaan() tried different ways to find the solution but, after four different ways to try, still failed.

Although the problem is due to calling lavaan() instead of sem(), I agree this may reveal a bug, or at least a probably unintended behavior, though not about optimization. I will discuss this in the next post.

Regards,
Shu Fai Cheung (張樹輝)


Shu Fai Cheung

unread,
May 17, 2023, 3:19:24 PM5/17/23
to lav...@googlegroups.com
This is the bug or unintended behavior that I found.

I also wondered what these lines are:

#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
#>             [,1]       [,2]        [,3]       [,4]       [,5]
#> [1,]  0.16314255  0.2133761 -0.07923048  0.3685547  0.3416982
#> [2,]  0.21337609  0.2825516 -0.10067745  0.4582031  0.4781250
#> [3,] -0.07923048 -0.1006774  0.04098148 -0.1992188 -0.1394531
#> [4,]  0.36855469  0.4582031 -0.19921875  0.9960938  0.5578125
#> [5,]  0.34169825  0.4781250 -0.13945313  0.5578125  0.9960938
I traced the steps and the printout above is generated by these lines from the function lav_model_estimate(), called by lavaan() to do the optimization:

                print(Sigma.hat[[g]][,])
                stop("lavaan ERROR: initial model-implied matrix (Sigma) is not positive definite;\n  check your model and/or starting parameters", group.txt)

The function is supposed to stop and raise an error here.

However, when called by lavaan(), try() is used:

            x <- try(lav_model_estimate(lavmodel        = lavmodel,
                                        lavpartable     = lavpartable,
                                        lavsamplestats  = lavsamplestats,
                                        lavdata         = lavdata,
                                        lavoptions      = lavoptions,
                                        lavcache        = lavcache),

Therefore, lav_model_estimate() cannot stop the function. That's why there are four sets of printouts.

Regards,
Shu Fai Cheung (張樹輝)

Shu Fai Cheung

unread,
May 17, 2023, 3:38:57 PM5/17/23
to lav...@googlegroups.com
A quick follow-up.

First, sorry for the first sentence. I did not find the bug. Michael and Ed did.

Second, like Ed, I was also puzzled by the output.  And I was wrong. The four sets of printouts were not due to the error being suppressed. Suppressing the error may be intended (Yves, please correct me if I am wrong). However, printing the matrices may not.

I posted a follow-up to the issue opened by Ed here:


Regards,
Shu Fai Cheung (張樹輝)


Yves Rosseel

unread,
May 19, 2023, 6:18:34 AM5/19/23
to lav...@googlegroups.com
There is no bug here (or at least, I don't think so). This is all due to
the fact that you are using the lavaan() function instead of the sem()
function.

The difference is explained in the lavaan paper (page 12):

https://www.jstatsoft.org/article/view/v048i02

but in short: the lavaan() function requires the user to specify ALL the
free model parameters in the syntax. This includes (residual) variances
for all variables! The sem() function takes care of this behind the scenes.

In your syntax, no (residual) variances are specified, and therefore,
they are all fixed to zero, which obviously is not what you want. So you
have either to include the variances in the model syntax, or you should
add the auto.var = TRUE argument in the lavaan() call. Or use the sem()
function instead. For 'standard' models, using the sem() function is the
best choice for most users.

The 'dump' that you see is the initial model-implied variance-covariance
matrix (Sigma), based on the starting values. You can clearly see that
many off-diagonal elements are larger than the diagonal elements, which
is a symptom that the (residual) variances are off. (You get it 4 times,
because lavaan tries four times with different starting values for the
free parameters, which doesn't help here, as the variances remaing fixed
to zero).

Yves.
> --
> 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
> <mailto:lavaan+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/lavaan/4da8cf71-9385-4978-b644-0592fddf39b5n%40googlegroups.com <https://groups.google.com/d/msgid/lavaan/4da8cf71-9385-4978-b644-0592fddf39b5n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages