# Step 1: Generate data
fc<-fcors.value(nf=3, cors=c(1,.5,.6,.5,1,.4,.6,.4,1))
fl<-loading.value(nf=3, fl.loads=c(.5,.5,.5,0,0,0,0,0,0,0,0,.6,.6,.6,0,0,0,0,0,0,0,0,.4,.4))
sim.normal(nd=10, ss=100, fcors=fc, loading<-fl, f.loc=tempdir())
# Step 2: Specify the model
lavaanM<-'
#CFA Model
f1 =~ NA*x1 + x2 + x3
f2 =~ NA*x4 + x5 + x6
f3 =~ NA*x7 + x8
#Factor Correlations
f1 ~~ f2
f1 ~~ f3
f2 ~~ f3
#Factor variance
f1 ~~ 1*f1
f2 ~~ 1*f2
f3 ~~ 1*f3
'
dl<-"Data_List.dat" # must be available in the working directory
# Step 3: Fit the model across simulated data
fit.simulation(model=lavaanM, PEmethod="MLR", Ordered=FALSE, dataList=dl, f.loc=tempdir())
Run the code above in your browser using DataLab