## ----setup--------------------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(cmrdesign)

## ----inputs-------------------------------------------------------------------
n_total <- 3000
sigma1 <- 0.18
sigma0 <- 0.28
alpha <- 0.05

## ----break-even---------------------------------------------------------------
break_even_pilot_share(sigma1, sigma0)
n_total * break_even_pilot_share(sigma1, sigma0)

## ----activation---------------------------------------------------------------
activation_threshold_bounded(alpha = alpha, max_total_pilot = n_total - 2)
activation_threshold_bernoulli(alpha = alpha)

## ----viability-band-----------------------------------------------------------
band <- pilot_viability_band(
  n = n_total,
  sigma1 = sigma1,
  sigma0 = sigma0,
  alpha = alpha,
  method = "bounded"
)

band$nonempty
band$min_feasible
band$max_feasible
length(band$feasible_pilot_sizes)

## ----feasible-grid------------------------------------------------------------
head(band$feasible_pilot_sizes)
tail(band$feasible_pilot_sizes)

## ----desired-pilot------------------------------------------------------------
plan <- cmr_plan(
  n = n_total,
  sigma1 = sigma1,
  sigma0 = sigma0,
  alpha = alpha,
  method = "bounded",
  desired_pilot = 120
)

plan$suggested_pilot
plan$desired_status
plan$recommendation
plan$caveat

## ----variance-inputs----------------------------------------------------------
plan_from_variances <- cmr_plan(
  n = n_total,
  sigma1 = sigma1^2,
  sigma0 = sigma0^2,
  input = "variance",
  alpha = alpha,
  method = "bounded",
  desired_pilot = 120
)

plan_from_variances$desired_status
plan_from_variances$suggested_pilot

## ----pooled-accounting--------------------------------------------------------
pooled_plan <- cmr_plan(
  n = n_total,
  sigma1 = sigma1,
  sigma0 = sigma0,
  alpha = alpha,
  method = "bounded",
  accounting = "pooled",
  desired_pilot = 400
)

pooled_plan$desired_status
pooled_plan$band$min_feasible
pooled_plan$band$max_feasible

