npoptimal <- function(r,theta,n,B,rseed){ set.seed(rseed) select=rep(0,length(r)) j=1 while(j<=B){ latent=runif(n,0,1) tox=matrix(nrow=n,ncol=length(r)) i=1 while(i<=n){ tox[i,]<-as.numeric(latent[i]<=r) i=i+1 } loss=abs(colMeans(tox)-theta) sugglev=which(loss==min(loss)) mtd=ifelse(length(sugglev)==1,sugglev,sample(sugglev,1)) select[mtd]=select[mtd]+1 j=j+1 } cat("True DLT probability: ", round(r,3), sep=" ", "\n"); cat("Selection percentage: ", formatC((select/B)*100, digits=1, format="f"), sep=" ", "\n"); cat("Accuracy Index: ", round(1-length(r)*(sum(abs(r-theta)*(select/B))/sum(abs(r-theta))),4), sep=" ", "\n"); } ##Assumed true toxicity scenario truth=c(0.05,0.07,0.20,0.35,0.55,0.70) #################################### # # Input: # # r = assumed true toxicity probabilities # n = sample size # theta = target toxicity rate # B = number of simulated trials # #################################### theta=0.20 n=25 B=2000 r=truth rseed=580 npoptimal(r,theta,n,B,rseed)