## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(simFastBOIN)

## -----------------------------------------------------------------------------
tite <- tite_boin_decision_table(target = 0.2, max_n = 15)
print(tite, cohort_size = 3)

## -----------------------------------------------------------------------------
tite[tite$n == 9 & tite$n_tox == 1 & tite$n_pending == 4, ]

## ----tite-plot, fig.width = 7, fig.height = 6, eval = requireNamespace("ggplot2", quietly = TRUE)----
plot(tite, n = 9)

## -----------------------------------------------------------------------------
print(tite_boin_decision_table(target = 0.3, max_n = 9, method = "ess"),
      cohort_size = 3)

## -----------------------------------------------------------------------------
oc_tite <- sim_tite_boin(
  target = 0.30,
  p_true = c(0.05, 0.15, 0.30, 0.45, 0.60),
  n_cohort = 10,
  cohort_size = 3,
  window = 3,
  accrual_rate = 2,
  n_trials = 2000,
  seed = 123
)

oc_tite

## -----------------------------------------------------------------------------
by_rate <- sapply(c(0.5, 1, 2, 4), function(rate) {
  oc <- sim_tite_boin(target = 0.30, p_true = c(0.05, 0.15, 0.30, 0.45, 0.60),
                      n_cohort = 10, cohort_size = 3, window = 3,
                      accrual_rate = rate, n_trials = 1000, seed = 1)
  c(accrual_rate = rate, selected_dose_3 = oc$sel_percent[["DL3"]],
    duration = oc$duration_mean, suspensions = oc$avg_n_suspensions)
})
round(t(by_rate), 2)

## -----------------------------------------------------------------------------
no_pending <- sim_tite_boin(target = 0.30,
                            p_true = c(0.05, 0.15, 0.30, 0.45, 0.60),
                            n_cohort = 10, cohort_size = 3, window = 0.5,
                            accrual_rate = 1, accrual = "fixed",
                            n_trials = 1000, seed = 7)
plain_boin <- sim_boin(target = 0.30, p_true = c(0.05, 0.15, 0.30, 0.45, 0.60),
                       n_cohort = 10, cohort_size = 3, n_trials = 1000,
                       seed = 7)

identical(no_pending$sel_percent, plain_boin$sel_percent)
identical(no_pending$n_pts_dose, plain_boin$n_pts_dose)

