Run Simulations, gather results
(nsubj = ceiling(2*(qnorm(.975)+qnorm(.9))^2*(0.1*(1-0.1)+0.25*(1-0.25))/(0.1-0.25)^2));
## [1] 260
nsim = 2e4;
prob_matrix = rbind(c(.1,.1),
c(.25,.25),
c(.6,.6),
c(.9,.9),
c(.1,.2),
c(.1,.25),
c(.1,.3),
c(.1,.35),
c(.4,.25),
c(.4,.55),
c(.4,.75),
c(.4,.95));
all_reject = all_alloc = all_fail =
matrix(NA, nrow(prob_matrix), 2,dimnames = list(paste(prob_matrix[,1],prob_matrix[,2],sep="_"),c("fixed","adaptive optimal")));
for(j in 1:nrow(prob_matrix)) {
set.seed(10);
true_pa = prob_matrix[j,1];
true_pb = prob_matrix[j,2];
fixed_equal = sim_rand_alloc(nsim, nsubj, true_pa, true_pb, rho = 0.5);
adapt_opt = sim_rand_alloc(nsim, nsubj, true_pa, true_pb, rho = "Opt");
#Rejection rate
all_reject[j,] = formatC(c(mean(abs(fixed_equal$zscore)>qnorm(.975)),
mean(abs(adapt_opt$zscore)>qnorm(.975))),format="f",digits=3);
#Number allocated to arm A
foo2 = formatC(c(quantile(fixed_equal$all_alloc,p=0.5),
quantile(adapt_opt$all_alloc,p=0.5)),format="d",digits=0);
foo3 = formatC(c(quantile(fixed_equal$all_alloc,p=0.975),
quantile(adapt_opt$all_alloc,p=0.975)),format="d",digits=0);
all_alloc[j,] = paste0(foo2,"(",foo3,")");
#Treatment falures
foo4 = formatC(c(quantile(nsubj - fixed_equal$all_resp,p=0.5),
quantile(nsubj - adapt_opt$all_resp,p=0.5)),format="d",digits=0);
foo5 = formatC(c(quantile(nsubj - fixed_equal$all_resp,p=0.975),
quantile(nsubj - adapt_opt$all_resp,p=0.975)),format="d",digits=0);
all_fail[j,] = paste0(foo4,"(",foo5,")");
rm(foo2,foo3,foo4,foo5);
}