I have figured out how to use simulateData specifying the model with a string written with lavaan model syntax. Now I need to simulate data specifying the model based on a previously fitted model object. Reading the documentation, I thought that I could do this as simulateData(model=lavaanify(model=MyFittedModel), model.type="sem",sample.nobs=1000). This gives the error:
The problem seems to be with lavaanify because PT=lavaanify(model=MyFittedModel) gives the error:
Now I am confused, because MyFittedModel really is a fitted lavaan object.
summary(MyFittedModel)
lavaan (0.5-17) converged normally after 17 iterations
Number of observations 1000
Estimator ML
Minimum Function Test Statistic 0.694
Degrees of freedom 4
P-value (Chi-square) 0.952
Parameter estimates:
Information Expected
Standard Errors Standard
Estimate Std.err Z-value P(>|z|)
Regressions:
R ~
H 0.406 0.031 12.947 0.000
LC 0.301 0.031 9.844 0.000
PC 0.273 0.030 9.042 0.000
LP 0.225 0.039 5.771 0.000
SA -0.063 0.034 -1.832 0.067
FS -0.013 0.035 -0.379 0.705
H ~
LP 0.386 0.037 10.321 0.000
LC 0.003 0.031 0.101 0.919
SA -0.013 0.030 -0.434 0.664
LC ~
LP 0.515 0.035 14.785 0.000
SA -0.027 0.035 -0.765 0.444
FS 0.037 0.033 1.124 0.261
PC ~
FS -0.480 0.029 -16.660 0.000
LC -0.002 0.029 -0.060 0.952
FS ~
SA 0.517 0.030 17.160 0.000
LP 0.003 0.034 0.093 0.926
SA ~
LP -0.306 0.034 -9.006 0.000
Variances:
R 0.973 0.044
H 0.990 0.044
LC 1.044 0.047
PC 1.069 0.048
FS 0.977 0.044
SA 1.074 0.048
I can't just edit the values into a lavaan syntax string because I need to be able to do this itteratively many times?
I would love any help.