########################################################################## ## R code for sample size calculation written by Youlan Rao ## ## Reference: ## Determination of Sample Size for Validation Study in Pharmacogenomics ## - Rao, Y., Lee, Y., and Hsu, J. C., ## January 2010, Technical Report No. 834, ## Department of Statistics, The Ohio State University. ## Section 2.2 ########################################################################## # gamma: minimum level of sensitivity # 1-beta: the minimal probability of successful validation # Sen_v: true sensitivity mstar<-fn.samplesize(gamma=0.80, beta=0.05, Sen_v=0.90) # function to find m*: the smallest number of subjects in the subgroup # such that for any m>=m*, the sensitivity rquirement is satisfied. # continuous approximation(CA) + Backward grid search fn.samplesize<-function(gamma, beta=0.05, Sen_v) { if(gamma>=Sen_v) {return(0)} else # find m0: the sharper upper bound than by Hoeffding's inequality { m0<-ceiling(fn.samplesize.CA(gamma, beta, Sen_v)) # Backward grid search N_m=1:m0 rhs<-NULL for (i in 1:length(N_m)) { n_m=N_m[i] # use regularized incomplete beta function. rhs[i]<-pbeta(1-Sen_v, n_m-(ceiling(n_m*gamma)-1), ceiling(n_m*gamma)) } jc<-length(N_m) while((rhs[jc]<=beta) & (jc>1)){jc<-jc-1} if (jc>1) {ind<-jc+1}else {ind<-jc} mstar<-N_m[ind] return(mstar) } } # continuous approximation(CA) # function to find m0: sharper upper bound than by Hoeffding's inequality fn.samplesize.CA<-function(gamma, beta=0.05, Sen_v) { if(gamma>=Sen_v) {return(0)} else # mH: the upper bound given by Hoeffding's inequality { mH<--log(beta)/(2*(Sen_v-gamma)^2) # m0: sharper upper bound than by Hoeffding's inequality m0<-uniroot(function(m) pbeta(1-Sen_v, m-m*gamma, m*gamma+1)-beta, c(1,mH), tol=1e-10)\$root return(m0) } }