I'm trying to simulate mtmm data with higher order trait. When I use the code below I get this error message : " Error in MASS::mvrnorm(n = sample.nobs[g], mu = Mu.hat[[g]], Sigma = COV, : 'Sigma' is not positive definite "
When I remove the second order trait, the code works without problem. What is the problem with my code?
Model1<-'
##traits
ListeningSpeaking=~ .49*CELDTls + .95*ELDlo+.95*ELDlt
Reading=~ .55*CELDTr+ .98*ELDwa+.97*ELDfv+.95*ELDc+.94*ELDlr
Writing=~ .60*CELDTw+ .96*ELDw+.95*ELDwc
##methods
CELDT=~.35*CELDTls +.65*CELDTr +.69*CELDTw
ELD=~.28*ELDlo +.27*ELDlt +.16*ELDwa +.21*ELDfv +.30*ELDc +.31*ELDlr +.23*ELDw +.24*ELDwc
##higher order trait
HOT=~ .957*ListeningSpeaking+.999*Reading+.991*Writing
##trait correlations
ListeningSpeaking~~.5*Reading
ListeningSpeaking~~.5*Writing
Writing~~.5*Reading
# methods correlation
CELDT ~~.3*ELD
##zero cross covariances
ListeningSpeaking~~0*CELDT
Reading~~0*CELDT
Writing ~~0*CELDT
ListeningSpeaking~~0*ELD
Reading~~0*ELD
Writing ~~0*ELD
HOT~~0*CELDT
HOT~~0*ELD
##distribution of categories in each indicator
CELDTls|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
CELDTr|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
CELDTw|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDlo|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDlt|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDwa|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDfv|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDc|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDlr|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDw|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
ELDwc|-.70*t1+ .39*t2+ 1.16*t3+ 2.05*t4
'
Model<-'ListeningSpeaking=~ ELDlt+CELDTls + ELDlo
Reading=~ ELDwa+CELDTr+ ELDfv+ELDc+ELDlr
Writing=~ ELDw+CELDTw+ELDwc
CELDT=~CELDTls +CELDTr +CELDTw
ELD=~ELDlo +ELDlt +ELDwa +ELDfv +ELDc +ELDlr +ELDw +ELDwc
HOT=~ ListeningSpeaking+Reading+Writing
ListeningSpeaking~~0*CELDT
Reading~~0*CELDT
Writing ~~0*CELDT
ListeningSpeaking~~0*ELD
Reading~~0*ELD
Writing ~~0*ELD
HOT~~0*CELDT
HOT~~0*ELD
'
Output1 <- sim(10,model=Model, n=500, generate=Model1, dataOnly= TRUE) #raw data only
Output2 <- sim(100,model=Model, n=1000, generate=Model1,
std.lv=TRUE, model.type= "cfa", estimator= 'WLSMV')
mysample<-simulateData(Model1, model.type = "cfa", seed=1234, sample.nobs = 5000, return.type = "data.frame")
complete.fit<-cfa(Model, data=mysample,
ordered= c('CELDTls', 'CELDTr', 'CELDTw','ELDlo', 'ELDlt', 'ELDwa', 'ELDfv' ,'ELDc' ,'ELDlr', 'ELDw', 'ELDwc'),
estimator= 'DWLS', mimic= 'Mplus',
std.lv=T, std.ov=T)