User Tools

Site Tools


lab:zhang:process_bmem_results_for_bmem_paper
res<-read.table('comp.txt', fill=T)
res<-res[ !is.na(res[,65]) ,]
res<-res[, 2:65]

## population parameter values
pop<-c(0,0,.39, .39, 0, 1, 1, .1521)

n<-dim(res)[1]

for (i in 1:8){
  temp<-res[, ((i-1)*8+1):(i*8)]
  if (pop[i] ==0){
       bias<-(mean(temp[,1])-pop[i])*100
       }else{
       	bias<-(mean(temp[,1])-pop[i])*100/pop[i]
       	}
  cvg1<-sum(temp[,3]<pop[i] & temp[,4]>pop[i])/n
  pow1<-sum(temp[,3]>0 | temp[,4]<0)/n
  cvg2<-sum(temp[,5]<pop[i] & temp[,6]>pop[i])/n
  pow2<-sum(temp[,5]>0 | temp[,6]<0)/n
  cvg3<-sum(temp[,7]<pop[i] & temp[,8]>pop[i])/n
  pow3<-sum(temp[,7]>0 | temp[,8]<0)/n
  cat(c(i, bias, cvg1, pow1, cvg2, pow2, cvg3, pow3), "\n")
}


#############################
## function to print the results
proc.res<-function(pat,r){
  filename<-paste(pat,'/',pat,'-',r,'.txt', sep='')
  res<-read.table(filename, fill=T)
  res<-res[ !is.na(res[,65]) ,]
  res<-res[, 2:65]

  ## population parameter values
  pop<-c(0,0,.39, .39, 0, 1, 1, .1521)

  n<-dim(res)[1]
  
  cat(pat,' ',r,' ',n,'\n')

  for (i in 1:8){
    temp<-res[, ((i-1)*8+1):(i*8)]
    bias<-(mean(temp[,1])-pop[i])*100
    cvg1<-sum(temp[,3]<pop[i] & temp[,4]>pop[i])/n
    pow1<-sum(temp[,3]>0 | temp[,4]<0)/n
    cvg2<-sum(temp[,5]<pop[i] & temp[,6]>pop[i])/n
    pow2<-sum(temp[,5]>0 | temp[,6]<0)/n
    cvg3<-sum(temp[,7]<pop[i] & temp[,8]>pop[i])/n
    pow3<-sum(temp[,7]>0 | temp[,8]<0)/n
    cat(c(i, bias, cvg1, pow1, cvg2, pow2, cvg3, pow3), "\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])
  }
}

New codes for results processing

runone<-function(filename, par){
    temp<-read.table(filename, fill=T)
    if (dim(temp)[2]==1){
    c(0,0,0)
    }else{
    par<-par*par
    if (par==0){
      bias<-100*(mean(temp[,2],na.rm=T)-par)
    }else{
      bias<-100*(mean(temp[,2],na.rm=T)-par)/par
    }
    n<-dim(temp)[1]
    cvg<-mean((temp[,6]<par) & (temp[,7]>par), na.rm=T)*100
    power<-mean((temp[,6]>0) | (temp[,7]<0), na.rm=T)*100
    c(bias, cvg, power)
    }
}




for (ab in c(0, .14, .39, .59)){
	for (N in c(50,100,200)){
		for (miss in c('MCAR','MAR','MNAR1', 'MNAR2')){
			for (rate in c(.1,.2,.4) ){
				for (av in c('av','noav')){
		res.name<-paste('ab',ab,'N',N,miss,'M',rate,av,'-em-results.txt',sep='')
		if (file.exists(res.name)){
				cat(ab, N, miss, rate, av, runone(res.name, ab),'\n')    }          
				}
			}
			}
			
			}	
		}
	
	}
lab/zhang/process_bmem_results_for_bmem_paper.txt · Last modified: 2016/01/24 09:48 by 127.0.0.1