knitr::opts_chunk$set(echo = TRUE)
library(PhIIdesign)
library(benchr)
library(ggplot2)

Fleming

One setting

comparison <- benchmark(
  fleming1stage(p0 = 0.1, pa = 0.3, alpha = 0.05, beta = 0.1, eps = 0.00001),
  PhIIdesign:::fleming_single_stage(p0 = 0.1, pa = 0.3, alpha = 0.05, beta = 0.1, eps = 0.00001)
)
comparison
boxplot(comparison) + coord_flip()

Fleming - several

test <- expand.grid(p0 = seq(0, 0.95, by = 0.05),
                    pa = seq(0, 0.95, by = 0.05))
test <- subset(test, (pa - p0) > 0.00001)
fleming1stage_multiple <- function(p0, pa, alpha = 0.05, beta = 0.1, eps = 0.00001){
  samplesize <- mapply(p0 = p0, pa = pa, FUN=function(p0, pa, alpha, beta, eps){
    fleming1stage(p0 = p0, pa = pa, alpha = alpha, beta = beta, eps = eps)
  }, SIMPLIFY = FALSE, alpha = alpha, beta = beta, eps = eps)
  samplesize <- do.call(rbind, samplesize)
  samplesize
}
comparison <- benchmark(
  fleming1stage_multiple(p0 = test$p0, pa = test$pa, alpha = 0.05, beta = 0.1, eps = 0.00001),
  fleming1stage(p0 = test$p0, pa = test$pa, alpha = 0.05, beta = 0.1, eps = 0.00001),
  times = 100
)
comparison
boxplot(comparison) + coord_flip()

Sargent 1 stage

One setting

comparison <- benchmark(
  sargent1stage(p0=0.5, pa=0.65, alpha=0.1, beta=0.1, 
                eta=0.8, pi=0.8, eps = 0.005, N_min=0, N_max=200, rcpp=FALSE),
  sargent1stage(p0=0.5, pa=0.65, alpha=0.1, beta=0.1, 
                eta=0.8, pi=0.8, eps = 0.005, N_min=0, N_max=200, rcpp=TRUE),
  times = 50
)
comparison
boxplot(comparison) + coord_flip()

Sargent setting - several

test <- data.frame(p0 = c(0.05,0.1,0.2,0.3,0.4,0.5),
                   pa = c(0.05,0.1,0.2,0.3,0.4,0.5) + 0.15)
test <- merge(test,
              expand.grid(alpha = c(0.1,0.05), beta = 0.1, eta = 0.8, pi = 0.8))

sargent1stage_multiple <- function(p0, pa, alpha, beta, eta, pi, eps, N_min, N_max){
  samplesize <- mapply(p0 = p0, pa = pa, alpha = alpha, beta = beta, eta = eta, pi = pi, FUN=function(p0, pa, alpha, beta, eta, pi, eps, N_min, N_max){
    sargent1stage(p0 = p0, pa = pa, alpha = alpha, beta = beta, eta = eta, pi = pi, eps = eps, N_min = N_min, N_max = N_max, rcpp = FALSE)
  }, SIMPLIFY = FALSE, eps = eps, N_min = N_min, N_max = N_max)
  samplesize <- do.call(rbind, samplesize)
  samplesize
}
comparison <- benchmark(
  sargent1stage_multiple(p0 = test$p0, pa = test$pa,
                         alpha = test$alpha, beta = test$beta,
                         eta = test$eta, pi = test$pi,
                         eps = 0.005, N_min = 20, N_max = 70),
  sargent1stage(p0 = test$p0, pa = test$pa,
                         alpha = test$alpha, beta = test$beta,
                         eta = test$eta, pi = test$pi,
                         eps = 0.005, N_min = 20, N_max = 70),
  times = 25
)
comparison
boxplot(comparison) + coord_flip()

Exact 1 stage

comparison <- benchmark(
  PhIIdesign:::bin_dif_cdf(0.1, 90, 100, 0.1, 0.05, type="exact"),
  PhIIdesign:::rcpp_bin_dif_cdf(0.1, 90, 100, 0.1, 0.05, type="exact"),
  times = 50
)
comparison
boxplot(comparison) + coord_flip()

One setting

comparison <- benchmark(
  exact1stage(p0=0.45,pa=0.7,alpha=0.05,beta=0.2,alloc=1,type="normal"),
  PhIIdesign:::rcpp_exact1stage(p0=0.45,pa=0.7,alpha=0.05,beta=0.2,alloc=1,type="normal"),
  times = 50
)
comparison
boxplot(comparison) + coord_flip()

Exact 1 stage - several

test <- rbind(
  data.frame(p0 = c(0.1, 0.2, 0.3, 0.4),
             pa = c(0.1, 0.2, 0.3, 0.4) + 0.2),
  data.frame(p0 = c(0.1, 0.2, 0.3, 0.4),
             pa = c(0.1, 0.2, 0.3, 0.4) + 0.15))
test <- merge(test,
              expand.grid(alpha = c(0.05, 0.1), beta = 0.1))

exact1stage_multiple <- function(p0, pa, alpha, beta, eps, alloc, type){
  samplesize <- mapply(p0 = p0, pa = pa, alpha = alpha, beta = beta,
                                  FUN=function(p0, pa, alpha, beta, eps, alloc, type){
                                    exact1stage(p0 = p0, pa = pa, alpha = alpha, beta = beta,
                                                eps = eps, alloc = alloc, type = type)
                                  }, eps, alloc, type, SIMPLIFY = FALSE)
  samplesize <- do.call(rbind, samplesize)
  samplesize
}

comparison <- benchmark(
  exact1stage_multiple(p0 = test$p0, pa = test$pa,
                       alpha = test$alpha, beta = test$beta,
                       eps = 0.025, alloc = 1, type = "normal"),
  exact1stage(p0 = test$p0, pa = test$pa,
                       alpha = test$alpha, beta = test$beta,
                       eps = 0.025, alloc = 1, type = "normal"),
  times = 1
)
comparison
boxplot(comparison) + coord_flip()

Simon 2-stage

One setting

data.table::setDTthreads(1L)
comparison <- benchmark(
  simon2stage(p0=0.1,pa=0.3,alpha=0.05,beta=0.2,eps = 0.005,N_min=0,N_max=50, method = "original"),
  simon2stage(p0=0.1,pa=0.3,alpha=0.05,beta=0.2,eps = 0.005,N_min=0,N_max=50, method = "speedup"),
  times = 1
)
comparison
boxplot(comparison) + coord_flip()

Sargent 2-stage

One setting

data.table::setDTthreads(1L)
comparison <- benchmark(
  sargent2stage(p0=0.1,pa=0.3,alpha=0.05,beta=0.1,eta=0.8,pi=0.8,
                eps = 0.005,N_min=15,N_max=40, method = "original"),
  sargent2stage(p0=0.1,pa=0.3,alpha=0.05,beta=0.1,eta=0.8,pi=0.8,
                eps = 0.005,N_min=15,N_max=40, method = "speedup"),
  times = 1
)
comparison
boxplot(comparison) + coord_flip()


IDDI-BE/PhIIdesign documentation built on June 5, 2021, 2:03 p.m.