#This program was written for the book chapter #Use of Monte Carlo Studies in Structural Equation Modeling Research #code to run the simulation study setwd("F:/walter/research/simulation/Book_chapter") #set working directory set.seed(741355) #set random seed #loop through conditions (in this case, two sample sizes) for (sample in c(150,500) ) { #specify all population parameters lambda = matrix (c(1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1),8,2,byrow = T) phi = matrix(c(0.5,0.25,0.25,0.5),2,2,byrow = T) theta = diag( 0.5,8) epsilon = rep(1.39,8) #read functions source("function_montecarlo.r") source("function_run_sem.r") #simulate 100 datasets montecarlo(lambda, phi, theta, epsilon,sample,iter=500) #run MPLUS fot fit a CFA to the simulated datasets run_sem("MPLUS_analysis",number.results=45,conditions=sample) } #close loop through conditions