User Tools

Site Tools


lab:zhang:r_codes_for_running_the_pairwise_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' pairwise.sas > sasmodel.sas",sep='')
              system(repNS)
              ## Run SAS for simulation
              system('SAS sasmodel.sas')
              ## copy the results to a folder
              newname<-paste(folder.name,'results.txt',sep='')
              file.rename('all.txt', newname)              
				}
			}
			
		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' pairwise.sas > sasmodel.sas",sep='')
              system(repNS)
              ## Run SAS for simulation
              system('SAS sasmodel.sas')
              ## copy the results to a folder
              newname<-paste(folder.name,'results.txt',sep='')
              file.rename('all.txt', newname)              
				}
			}	
		}
	
	}
runone<-function(filename, par){
    temp<-read.table(filename, fill=T,skip=1)
    
    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,'pairwise-results.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,'pairwise-results.txt',sep='')
           if (file.exists(newname)){
				cat(ab, N, miss, rate, runone(newname, ab),'\n')    } 
				}              
				}
			}	
		}
	
lab/zhang/r_codes_for_running_the_pairwise_deletion_simulation.txt · Last modified: 2016/01/24 09:48 by 127.0.0.1