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;
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...
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