fparse(DV ~ IV1 + IV2 * IV2*IV3 + (IV4) + I(IV5^2) )
#somewhat more complicated
fparse(DV1 + DV2 ~ IV1 + IV2 + IV3*IV4 + I(IV5^2) + I(Iv6^2) + (IV7) + (IV8) - IV9)
model <- ' F1 =~ .9*V1 + .8*V2 + .7*V3
F2 =~ .8 * V4 + .7*V5 + .6*V6
F3 =~ .9*V7 + .7*V8 + .5*V9
F1 ~ .3 * F2 + .6* F3
F2 ~ .5*F3'
lavParse(model,phi=TRUE) #will return a 9 x 3 matrix loadings and 3x3 phi matrix for sim
#by specifying the coefficients, we can run sim more readily
sim.data <-sim(model,n=500)
cx <- CFA(model,sim.data$observed)
#The CFA function will not use the coefficients nor the phi matrix, just the path model
#So we can use the same model for simulations and CFA
#But, lavaan needs to drop the coefficients
modelg <- 'g =~ .4*V1 +.4*V2+.4*V3 +.4*V4+.4*V5+.4*V6 +.4*V7+.4*V8+.4*V9
F1 =~ .9*V1 + .8*V2 + .7*V3
F2 =~ .8 * V4 + .7*V5 + .6*V6
F3 =~ .9*V7 + .7*V8 + .5*V9 '
modelg <- 'g=~V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 +V9
F1 =~ V1 + V2 + V3
F2 =~ V4 + V5 + V6
F3 =~ V7 + V8 + V9'
lavParse(modelg)
#model without coefficients to run in lavaan
Run the code above in your browser using DataLab