I am just sharing this in case someone might find it interesting--this isn't a case where I have a real problem and need assistance. (I am playing with methods to turn factor models into composite models.)
In particular, I have seen other people report this message:
5: In lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable, :
lavaan WARNING: the optimizer (NLMINB) claimed the model converged,
but not all elements of the gradient are (near) zero;
the optimizer may not have found a local solution
use check.gradient = FALSE to skip this check.
and I didn't entirely understand what it meant, so I thought this example might be valuable.
Here is the R script:
library(lavaan)
R<-matrix(data=c(1, .72, .72,.63,
.72, 1, .64, .56,
.72, .64, 1, .56,
.63, .56, .56, 1),byrow=T,nrow=4)
row.names(R)<-c("y1","y2","y3","y4")
colnames(R)<-row.names(R)
M<-'f=~y1+y2+y3+y4
y2~~a*y2
y3~~a*y3
y2~~a*y3'
fit4<-cfa(model=M,sample.cov=R,sample.nobs=1000)
summary(fit4)
and here is the output:
Warning messages:
1: In computeOmega(Sigma.hat = Sigma.hat, Mu.hat = NULL, lavsamplestats = lavsamplestats, :
lav_model_gradient: Sigma.hat is not positive definite
2: In lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable, :
lavaan WARNING: the optimizer warns that a solution has NOT been found!
3: In computeOmega(Sigma.hat = Sigma.hat, Mu.hat = NULL, lavsamplestats = lavsamplestats, :
lav_model_gradient: Sigma.hat is not positive definite
4: In computeOmega(Sigma.hat = Sigma.hat, Mu.hat = NULL, lavsamplestats = lavsamplestats, :
lav_model_gradient: Sigma.hat is not positive definite
5: In lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable, :
lavaan WARNING: the optimizer (NLMINB) claimed the model converged,
but not all elements of the gradient are (near) zero;
the optimizer may not have found a local solution
use check.gradient = FALSE to skip this check.
6: In computeOmega(Sigma.hat = Sigma.hat, Mu.hat = NULL, lavsamplestats = lavsamplestats, :
lav_model_gradient: Sigma.hat is not positive definite
7: In lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable, :
lavaan WARNING: the optimizer warns that a solution has NOT been found!
8: In computeOmega(Sigma.hat = Sigma.hat, Mu.hat = NULL, lavsamplestats = lavsamplestats, :
lav_model_gradient: Sigma.hat is not positive definite
9: In computeOmega(Sigma.hat = Sigma.hat, Mu.hat = NULL, lavsamplestats = lavsamplestats, :
lav_model_gradient: Sigma.hat is not positive definite
10: In lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable, :
lavaan WARNING: the optimizer (NLMINB) claimed the model converged,
but not all elements of the gradient are (near) zero;
the optimizer may not have found a local solution
use check.gradient = FALSE to skip this check.
> summary(fit4)
lavaan 0.6-7 did NOT end normally after 1 iterations
** WARNING ** Estimates below are most likely unreliable
Estimator ML
Optimization method NLMINB
Number of free parameters 9
Number of equality constraints 2
Number of observations 1000
Model Test User Model:
Test statistic NA
Degrees of freedom NA
Parameter Estimates:
Standard errors Standard
Information Expected
Information saturated (h1) model Structured
Latent Variables:
Estimate Std.Err z-value P(>|z|)
f =~
y1 1.000
y2 0.700 NA
y3 0.700 NA
y4 0.700 NA
Covariances:
Estimate Std.Err z-value P(>|z|)
.y2 ~~
.y3 (a) 0.667 NA
Variances:
Estimate Std.Err z-value P(>|z|)
.y2 (a) 0.667 NA
.y3 (a) 0.667 NA
.y1 1.000 NA
.y4 1.000 NA
f 1.000 NA
For the record, adding starting values, as in:
R<-matrix(data=c(1, .72, .72,.63,
.72, 1, .64, .56,
.72, .64, 1, .56,
.63, .56, .56, 1),byrow=T,nrow=4)
row.names(R)<-c("y1","y2","y3","y4")
colnames(R)<-row.names(R)
M<-'f=~y1+y2+y3+y4
y2~~a*y2 + 0.36?y2
y3~~a*y3 + 0.36?y3
y2~~a*y3 + 0.36?y3'
fit5<-cfa(model=M,sample.cov=R,sample.nobs=1000)
summary(fit5)
Got rid of most of the warnings, replaced by an error message:
> fit5<-cfa(model=M,sample.cov=R,sample.nobs=1000)
[,1] [,2] [,3] [,4]
[1,] 0.54950000 0.04444444 0.04444444 0.03888889
[2,] 0.04444444 0.39950617 0.39950617 0.03456790
[3,] 0.04444444 0.39950617 0.39950617 0.03456790
[4,] 0.03888889 0.03456790 0.03456790 0.52974691
Error in lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable, :
lavaan ERROR: initial model-implied matrix (Sigma) is not positive definite;
check your model and/or starting parameters.
> summary(fit5)
lavaan 0.6-7 did NOT end normally after 1 iterations
** WARNING ** Estimates below are most likely unreliable
Estimator ML
Optimization method NLMINB
Number of free parameters 9
Number of equality constraints 2
Number of observations 1000
Model Test User Model:
Test statistic NA
Degrees of freedom NA
Parameter Estimates:
Standard errors Standard
Information Expected
Information saturated (h1) model Structured
Latent Variables:
Estimate Std.Err z-value P(>|z|)
f =~
y1 1.000
y2 0.700 NA
y3 0.700 NA
y4 0.700 NA
Covariances:
Estimate Std.Err z-value P(>|z|)
.y2 ~~
.y3 (a) 0.667 NA
Variances:
Estimate Std.Err z-value P(>|z|)
.y2 (a) 0.667 NA
.y3 (a) 0.667 NA
.y1 1.000 NA
.y4 1.000 NA
f 1.000 NA