lab:zhang:r_codes_for_processing_results_of_mi_using_sas
Process all results
## cp result files into one folder pat<-c('mcar','mcar0','mcar1','mcar2','mar','mar0','mar1','mar2','mnar','mnar0','mnar1','mnar2','mnar0-1','mnar1-1','mnar2-1') for (mis in pat){ for (i in 1:3){ cmd<-paste('cp ', mis,'/',i,'/*.txt results/.', sep='') system(cmd) } } ############################# ## function to print the results proc.res<-function(pat,r){ filename<-paste(pat,'-',r,'.txt', sep='') res<-read.table(filename, fill=T) res<-res[ !is.na(res[,27]) ,] res<-res[, 4:27] ## population parameter values pop<-c(.39,.39,0,.1521,0,0,1,1) n<-dim(res)[1] cat(pat,' ',r,' ',n,'\n') for (i in 1:8){ ind<-c(i, (i+8), (i+16)) temp<-res[, ind] if (pop[i]==0){ bias<-(mean(temp[,1])-pop[i])*100 }else{ bias<-(mean(temp[,1])-pop[i])*100/pop[i] } cvg1<-sum(temp[,2]<pop[i] & temp[,3]>pop[i])/n pow1<-sum(temp[,2]>0 | temp[,3]<0)/n cat(c(i, bias, cvg1, pow1), "\n") } cat('\n\n') } ## process all results pat<-c('mcar','mcar0','mcar1','mcar2','mar','mar0','mar1','mar2','mnar','mnar0','mnar1','mnar2','mnar0-1','mnar1-1','mnar2-1') ## copy bmem to the folders for (mis in pat){ if (substr(mis,1,3)=="mar"){ rate<-c(1.5,4,9) }else{ rate<-c(.1,.2,.4) } for (i in 1:3){ proc.res(mis, rate[i]) } }
## for mnar & mcar rate<-c(0.1,.2,.4) ## for mar rate<-c(1.5,4,9) par<-'mar1' for (j in 1:3){ file.name<-paste(par,'/',j,'/',par,'-',rate[j],'.txt', sep='') res<-read.table(file.name, fill=T) res<-res[ !is.na(res[,27]) ,] res<-res[, 4:27] ## population parameter values pop<-c(.39,.39,0,.1521,0,0,1,1) n<-dim(res)[1] for (i in 1:8){ ind<-c(i, (i+8), (i+16)) temp<-res[, ind] bias<-(mean(temp[,1])-pop[i])*100 cvg1<-sum(temp[,2]<pop[i] & temp[,3]>pop[i])/n pow1<-sum(temp[,2]>0 | temp[,3]<0)/n cat(c(i, bias, cvg1, pow1), "\n") } }
lab/zhang/r_codes_for_processing_results_of_mi_using_sas.txt · Last modified: 2016/01/24 09:48 by 127.0.0.1