## Program to run Mplus for the simulation ## write the model gen.model<-function( ){ ## generate mplus scripts for data analysis ## Mplus input scripts mplus.null<-'model.inp' ## for null model cat('TITLE: Model\n',file=mplus.null); cat('DATA:\n',file=mplus.null, append=T); cat(' FILE=data.txt;\n',file=mplus.null, append=T); cat('VARIABLE: \n',file=mplus.null, append=T); cat(' NAMES ARE X M Y U V W;\n', file=mplus.null, append=T); cat(' USEVARIABLES ARE X M Y;\n', file=mplus.null, append=T); cat(' AUXILIARY = (m) U V W;\n', file=mplus.null, append=T); cat(' MISSING = ALL(99999); \n',file=mplus.null, append=T); cat('ANALYSIS: \n',file=mplus.null, append=T); cat(' COVERAGE=.01; \n',file=mplus.null, append=T); ## cat(' bootstrap=1000; \n',file=mplus.null, append=T); cat('MODEL: \n',file=mplus.null, append=T); cat(' M ON X ;\n',file=mplus.null, append=T); cat(' Y ON M X; \n',file=mplus.null, append=T); cat('MODEL INDIRECT: \n',file=mplus.null, append=T); cat(' Y IND X; \n',file=mplus.null, append=T); ## cat('OUTPUT:\n', file=mplus.null, append=T); ## cat(' CINTERVAL (BCBOOTSTRAP); \n', file=mplus.null, append=T); } ## function to process output to get the parameter estimates and the bc intervals proc.res<-function(){ out.file<-"model.out" output <- suppressWarnings(readLines(out.file)) lnumber <- grep(" Total indirect", output) est<- unlist(strsplit(output[lnumber[1]], " ")) est<-est[!est==""] est<-as.numeric(est[3]) est } ## function to calculate the BC for mplus bc.ci<-function(res, est){ iB<-length(res) ## BC interval alpha<-c(.025, .975) z0<-qnorm(sum(res.39^2)/dim(res)[1] sum(res[,2]>0)/dim(res)[1]