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 (張樹輝)