#Directory containing JAGS file and R code dir <- "/mydir/jagsfile" #Load necessary R code source(paste(dir, "/run.onesim.r", sep="")) #Prior DLT probabilities for each combination p.prior <- matrix(c(2,4,6,8,5,7,9,11,8,10,12,14,11,13,15,17)/50, nrow=4, ncol=4, byrow=TRUE) #True DLT probabilities p.true <- matrix(c(2,4,6,8,5,7,9,11,8,10,12,14,11,13,15,17)/50, nrow=4, ncol=4, byrow=TRUE) #Targeted rate of DLTs p.star <- 0.2 #Maximum sample size m <- 35 #Prior variance parameter s2 <- 10 #Starting doses j.start <- 1 k.start <- 1 #Run simulations Nsim <- 1000 mysims <- NULL for (i in 1:Nsim) { set.seed(i) temp <- run.onesim(m, p.true, p.prior, p.star, s2, j.start, k.start, dir) mysims <- rbind(mysims, temp) } #Tabulate number of times each combo chosen as MTC ndose.a <- ncol(p.prior) ndose.b <- nrow(p.prior) a <- mysims[,1] b <- mysims[,2] mtc.table <- table(c(b, paste(rep(0:ndose.b, ndose.a+1))), c(a, rep(0:ndose.a, rep(ndose.b+1,ndose.a+1))))-1 rm(a,b) colnames(mtc.table) <- paste(rep("A",ndose.a+1), 0:ndose.a, sep="") rownames(mtc.table) <- paste(rep("B",ndose.b+1), 0:ndose.b, sep="") #Tabulate average number of patients assigned to each combo a <- mysims[,m:(2*m-1)+4] b <- t(matrix(as.numeric(paste(rep(1:ndose.a,ndose.b), rep(1:ndose.b, rep(ndose.a,ndose.b)), sep="")), nrow=ndose.a*ndose.b, ncol=nrow(a))) a <- cbind(a,b) b <- t(apply(a, 1, table)-1) nsubj.table <- matrix(apply(b, 2, mean), ncol=ndose.a, nrow=ndose.b, byrow=F) rm(a,b) colnames(nsubj.table) <- paste(rep("A",ndose.a), 1:ndose.a, sep="") rownames(nsubj.table) <- paste(rep("B",ndose.b), 1:ndose.b, sep="")