lavaan simulation loop: error message: sigma is not positive definite

836 views
Skip to first unread message

et

unread,
May 31, 2015, 11:20:36 AM5/31/15
to lav...@googlegroups.com
dear all,

when i try to run this code (thx for the example here in this forum!), the error message says 

"Fehler in lav_model_estimate(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  : 
                               lavaan ERROR: initial model-implied matrix (Sigma) is not positive definite;
                             check your model and/or starting parameters." 

does anybody know where the problem is?
i have already tried to reduce the variables separately and to set the first indicators to 1 instead of the variances of the latent variables... 

thx a lot!


runOnce <- function(i) {
  require(lavaan)
  model1 <- '
f1.1 =~ 0.27*x1 + 0.27*x2 + 0.37*x3 + 0.33*x4 + 0.37*x5 + 0.32*x6 + 0.23*x7 + 0.30*x8 + 0.22*x9 + 0.21*x10
f1.2 =~ 0.30*x11 + 0.30*x12 + 0.25*x13 + 0.22*x14 + 0.29*x15 + 0.27*x16 + 0.21*x17 + 0.26*x18 + 0.39*x19 + 0.28*x20
f1.1 ~~ 1*f1.1
f1.2 ~~ 1*f1.2
f1.1 ~~ 0.30*f1.2
'

data.sim1 <- simulateData(model1, sample.nobs = 1000L)

analysismodel1 <- '
f1.1 =~ a1*x1 + a2*x2 + a3*x3 + a4*x4 + a5*x5 + a6*x6 + a7*x7 + a8*x8 + a9*x9 + a10*x10
f1.2 =~ a11*x11 + a12*x12 + a13*x13 + a14*x14 + a15*x15 + a16*x16 + a17*x17 + a18*x18 + a19*x19 + a20*x20
f1.1 ~~ 1*f1.1
f1.2 ~~ 1*f1.2
f1.1 ~~ b1*f1.2
'
  
fit.model1 <- lavaan(analysismodel1, data = data.sim1, int.ov.free = TRUE, estimator = "ML")
fitMeasures(fit.model1, fit.measures = c("chisq", "pvalue"))
}

out <- sapply(1:10, runOnce)
out

makeData <- function(i) {
  require(lavaan)

model1 <- '
f1.1 =~ 0.27*x1 + 0.27*x2 + 0.37*x3 + 0.33*x4 + 0.37*x5 + 0.32*x6 + 0.23*x7 + 0.30*x8 + 0.22*x9 + 0.21*x10
f1.2 =~ 0.30*x11 + 0.30*x12 + 0.25*x13 + 0.22*x14 + 0.29*x15 + 0.27*x16 + 0.21*x17 + 0.26*x18 + 0.39*x19 + 0.28*x20
f1.1 ~~ 1*f1.1
f1.2 ~~ 1*f1.2
f1.1 ~~ 0.30*f1.2
'
  
simulateData(model1, sample.nobs = 1000L)
}
data.sim <- lapply(1:10, makeData)

lapply(data.sim, head)

fit.model1 <- function(i) {

analysismodel1 <- '  
f1.1 =~ a1*x1 + a2*x2 + a3*x3 + a4*x4 + a5*x5 + a6*x6 + a7*x7 + a8*x8 + a9*x9 + a10*x10
f1.2 =~ a11*x11 + a12*x12 + a13*x13 + a14*x14 + a15*x15 + a16*x16 + a17*x17 + a18*x18 + a19*x19 + a20*x20
f1.1 ~~ 1*f1.1
f1.2 ~~ 1*f1.2
f1.1 ~~ b1*f1.2
'

fit.model1 <- lavaan(analysismodel1, data = i, int.ov.free = TRUE, estimator = "ML")
fitMeasures(fit.model1, fit.measures = c("chisq", "pvalue"))
}

out <- sapply(data.sim, fit.model1)
out

Yves Rosseel

unread,
Jun 11, 2015, 11:22:39 AM6/11/15
to lav...@googlegroups.com

> fit.model1 <- lavaan(analysismodel1, data = data.sim1, int.ov.free =
> TRUE, estimator = "ML")

You are using the lavaan() function! That means that you need to include
ALL the free parameters in your model syntax, or add the relevant auto.*
arguments.

In this case, you can add auto.var = TRUE. Or using the sem() function.

Yves.

et

unread,
Jun 14, 2015, 6:18:31 AM6/14/15
to lav...@googlegroups.com
thx a lot! 
Reply all
Reply to author
Forward
0 new messages