lab:zhang:r_codes_for_running_the_listwise_deletion_simulation
## R codes for running simulation of pairwise deletion and listwise deletion for (ab in c(0, .14, .39, .59)){ for (N in c(50,100,200)){ for (miss in c('MCAR','MNAR1', 'MNAR2')){ for (rate in c(.1,.2,.4) ){ ## folder name folder.name<-paste('ab',ab,'N',N,miss,'M',rate,sep='') ## change the folder name in SAS repNS<-paste("sed 's/simucond/",folder.name,"/g' listwise.sas > sasmodel.sas",sep='') system(repNS) ## Run SAS for simulation system('SAS sasmodel.sas') ## copy the results to a folder newname<-paste(folder.name,'listwise-results.txt',sep='') file.rename('all.txt', newname) unlink('sasmodel.sas') } } for (miss in 'MAR'){ for (rate in c(1.5, 4, 9) ){ ## folder name folder.name<-paste('ab',ab,'N',N,miss,'M',rate,sep='') ## change the folder name in SAS repNS<-paste("sed 's/simucond/",folder.name,"/g' listwise.sas > sasmodel.sas",sep='') system(repNS) ## Run SAS for simulation system('SAS sasmodel.sas') ## copy the results to a folder newname<-paste(folder.name,'listwise-results.txt',sep='') file.rename('all.txt', newname) unlink('sasmodel.sas') } } } }
Process the results
runone<-function(filename, par){ temp<-read.table(filename, fill=T,skip=1) par<-par*par if (par==0){ bias<-100*(mean(temp[,1],na.rm=T)-par) }else{ bias<-100*(mean(temp[,1],na.rm=T)-par)/par } n<-dim(temp)[1] cvg<-mean((temp[,3]<par) & (temp[,4]>par), na.rm=T)*100 power<-mean((temp[,3]>0) | (temp[,4]<0), na.rm=T)*100 c(bias, cvg, power) } ## R codes for running simulation of pairwise deletion and listwise deletion for (ab in c(0, .14, .39, .59)){ for (N in c(50,100,200)){ for (miss in c('MCAR','MNAR1', 'MNAR2')){ for (rate in c(.1,.2,.4) ){ ## folder name folder.name<-paste('ab',ab,'N',N,miss,'M',rate,sep='') newname<-paste(folder.name,'-listwise.txt',sep='') if (file.exists(newname)){ cat(ab, N, miss, rate,runone(newname, ab),'\n') } } } for (miss in 'MAR'){ for (rate in c(1.5, 4, 9) ){ folder.name<-paste('ab',ab,'N',N,miss,'M',rate,sep='') newname<-paste(folder.name,'-listwise.txt',sep='') if (file.exists(newname)){ cat(ab, N, miss, rate, runone(newname, ab),'\n') } } } } }
Process results from new simulaton
runone<-function(filename, par){ temp<-dget(filename) N<-length(temp) for (i in 1:N){ if (length(temp[[i]])!=4) temp[[i]]<-rep(NA, 4) } temp<-do.call(rbind, temp) par<-par*par if (par==0){ bias<-100*(mean(temp[,1],na.rm=T)-par) }else{ bias<-100*(mean(temp[,1],na.rm=T)-par)/par } n<-dim(temp)[1] cvg<-mean((temp[,3]<par) & (temp[,4]>par), na.rm=T)*100 power<-mean((temp[,3]>0) | (temp[,4]<0), na.rm=T)*100 c(bias, cvg, power) } ## R codes for running simulation of pairwise deletion and listwise deletion for (ab in c(0, .14, .39, .59)){ for (N in c(50,100,200)){ for (miss in c('MCAR','MNAR1', 'MNAR2')){ for (rate in c(.1,.2,.4) ){ ## folder name folder.name<-paste('ab',ab,'N',N,miss,'M',rate,sep='') newname<-paste(folder.name,'-listwise.txt',sep='') if (file.exists(newname)){ cat(ab, N, miss, rate,runone(newname, ab),'\n') } } } for (miss in 'MAR'){ for (rate in c(1.5, 4, 9) ){ folder.name<-paste('ab',ab,'N',N,miss,'M',rate,sep='') newname<-paste(folder.name,'-listwise.txt',sep='') if (file.exists(newname)){ cat(ab, N, miss, rate, runone(newname, ab),'\n') } } } } }
lab/zhang/r_codes_for_running_the_listwise_deletion_simulation.txt · Last modified: 2016/01/24 09:48 by 127.0.0.1