--- title: "Getting started with simFastBOIN" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Getting started with simFastBOIN} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") library(simFastBOIN) ``` ## What the package does The Bayesian optimal interval (BOIN) design assigns a cohort of patients to a dose, counts how many experienced a dose-limiting toxicity, and compares the observed rate against two boundaries. If the rate is at or below the lower boundary the next cohort is escalated, if it reaches the upper boundary the next cohort is de-escalated, and otherwise the dose is repeated. The rule is as simple to run as a 3+3 design, and Liu and Yuan report average performance comparable to that of the continual reassessment method. This package provides the boundaries, a fast simulation engine for operating characteristics, and the MTD selection rule applied at the end of a trial. The traditional 3+3 design is included as a comparator, so the two can be tabulated side by side. For toxicity that appears late in the assessment window, the time-to-event version of the design has a vignette of its own, `vignette("simFastBOIN-tite")`, and so do the designs that backfill patients to lower doses while the escalation waits, `vignette("simFastBOIN-backfill")`, and the design for trials of two drugs given together, `vignette("simFastBOIN-combination")`. The designs that look for the optimal biological dose, which weighs the response against the toxicity, are described in `vignette("simFastBOIN-boin-et")` (BOIN-ET, its time-to-event and backfill versions and BOIN-ETC for two drugs) and `vignette("simFastBOIN-boin12")` (BOIN12, TITE-BOIN12, Comb-BOIN12 and TITE-Comb-BOIN12). The functions of the section "Tables and figures" below set the results of any of these designs side by side. ## Decision boundaries `boin_lambda()` returns the two interval boundaries, which depend only on the target rate and the two thresholds around it. ```{r} boin_lambda(target = 0.30) ``` In practice the boundaries are used as whole numbers of toxicities. `boin_boundary()` tabulates them, together with the elimination boundary, for every attainable sample size at a dose. ```{r} bd <- boin_boundary(target = 0.30, max_n = 18, extrasafe = TRUE) print(bd, cohort_size = 3) ``` Reading the first column: with three patients treated, escalate on zero toxicities, de-escalate on two or more, and stay on exactly one. The same information can be read as a table indexed by both counts. Printing it with a cohort size shows only the sample sizes that are actually reached. ```{r} decisions <- boin_decision_table(target = 0.30, max_n = 18) print(decisions, cohort_size = 3) ``` For a protocol the table is usually easier to read as a picture. Every cell carries its decision letter, so the figure survives grayscale printing. ```{r decision-plot, fig.width = 8, fig.height = 6, eval = requireNamespace("ggplot2", quietly = TRUE)} plot(decisions) ``` When `extrasafe = TRUE` there is a second, stricter rule that applies at the lowest dose only. `boin_stopping_table()` lays it out the same way. ```{r} boin_stopping_table(bd, cohort_size = 3) ``` ## Operating characteristics for one scenario `sim_boin()` simulates the design many times under an assumed dose-toxicity curve and summarizes the result. ```{r} oc <- 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 = 2000, seed = 123 ) oc ``` The third dose is the true MTD here, and it is the dose selected most often. The components of the result are available individually. ```{r} oc$sel_percent oc$percent_no_mtd oc$overdose$pct_patients ``` ## Comparing scenarios A design is judged across a range of plausible curves rather than one. `sim_boin_multi()` runs the same design under several scenarios and collects the results into one table. ```{r} scenarios <- list( "MTD at dose 2" = c(0.15, 0.30, 0.45, 0.60, 0.75), "MTD at dose 4" = c(0.02, 0.06, 0.15, 0.30, 0.50), "All doses toxic" = c(0.40, 0.55, 0.65, 0.75, 0.85) ) sim_boin_multi( target = 0.30, scenarios = scenarios, n_cohort = 10, cohort_size = 3, n_trials = 2000, seed = 123 ) ``` ## Design options Six options change how the design behaves. `titration = TRUE` treats one patient per dose until the first toxicity, which moves through safe doses quickly. ```{r} safe_curve <- c(0.01, 0.02, 0.05, 0.12, 0.30) plain <- sim_boin(target = 0.30, p_true = safe_curve, n_cohort = 12, cohort_size = 3, n_trials = 1000, seed = 1) titrated <- sim_boin(target = 0.30, p_true = safe_curve, n_cohort = 12, cohort_size = 3, n_trials = 1000, titration = TRUE, seed = 1) rbind(plain = plain$n_pts_dose, titrated = titrated$n_pts_dose) ``` `titration_doses` ends the titration at a given dose: when no DLT is seen up to it, full cohorts start at the next dose. With `titration_doses = 2` and `n_earlystop = 6`, which stops the trial once six patients are at the current dose and the design would stay, this is the accelerated BOIN design of Kojima, Wende and Zhao (2024). ```{r} standard <- sim_boin(target = 0.30, p_true = safe_curve, n_cohort = 8, cohort_size = 3, n_trials = 1000, seed = 1) accelerated <- sim_boin(target = 0.30, p_true = safe_curve, n_cohort = 8, cohort_size = 3, n_trials = 1000, titration = TRUE, titration_doses = 2, n_earlystop = 6, seed = 1) round(rbind(standard = c(standard$sel_percent, patients = standard$total_n_pts), accelerated = c(accelerated$sel_percent, patients = accelerated$total_n_pts)), 1) ``` ```{r, include = FALSE} kojima <- utils::read.csv(system.file("reproduce", "results", "reproduce_Kojima2024.csv", package = "simFastBOIN"), stringsAsFactors = FALSE) kojima_aboin <- kojima[kojima$design == "ABOIN", ] ``` With at most 24 patients, the accelerated design treats `r round(accelerated$total_n_pts, 1)` patients on average against `r round(standard$total_n_pts, 1)` for the standard design. `inst/reproduce/reproduce_Kojima2024.R` compares it with Tables 1 and 2 of the article: `r sum(kojima_aboin$judgement == "PASS")` of the `r nrow(kojima_aboin)` values of the accelerated design lie within four standard errors of the published ones. `extrasafe = TRUE` adds a stopping rule at the lowest dose that is easier to trigger than elimination, and `bound_mtd = TRUE` refuses to select a dose whose estimated toxicity exceeds the de-escalation boundary. ```{r} toxic_curve <- c(0.35, 0.45, 0.55, 0.65, 0.75) c( plain = sim_boin(target = 0.30, p_true = toxic_curve, n_cohort = 12, cohort_size = 3, n_trials = 1000, seed = 2)$percent_no_mtd, extrasafe = sim_boin(target = 0.30, p_true = toxic_curve, n_cohort = 12, cohort_size = 3, n_trials = 1000, extrasafe = TRUE, seed = 2)$percent_no_mtd ) ``` `n_earlystop` stops a trial once the current dose has accrued this many patients and the design would stay there, which is taken as a sign that the algorithm has settled. It defaults to 18. Note that the reference implementation in the BOIN package defaults to 100, which effectively switches the rule off, so a comparison between the two should set it explicitly. For some target rates one DLT out of three patients de-escalates the dose, where the 3+3 design would stay. `stay_on_1_of_3 = TRUE` aligns the design with that practice by raising the de-escalation boundary at three patients, which changes one cell of the table and nothing else. ```{r} c(default = boin_decision_table(0.25, 9)["1", "3"], modified = boin_decision_table(0.25, 9, stay_on_1_of_3 = TRUE)["1", "3"]) ``` ## Working with the trial data `boin_simulate()` returns the raw counts, which is useful when a summary other than the built-in one is needed. ```{r} trials <- boin_simulate( 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 = 123 ) trials ``` The MTD selection rule can then be applied separately, which makes it possible to compare selection rules on one set of simulated trials. ```{r} free <- boin_select_mtd(trials$n_pts, trials$n_tox, target = 0.30) bounded <- boin_select_mtd(trials$n_pts, trials$n_tox, target = 0.30, bound_mtd = TRUE) table(free$mtd, bounded$mtd, useNA = "ifany") ``` The estimated dose-toxicity curve behind those decisions is available on its own. ```{r} round(boin_isotonic(trials$n_pts[1:5, ], trials$n_tox[1:5, ]), 3) ``` ## Comparing with the 3+3 design `oc_3p3()` gives the operating characteristics of the traditional 3+3 design. The probability of every path the design can take is evaluated in closed form, so the result carries no Monte Carlo error and takes no seed. ```{r} oc_3p3(p_true = c(0.05, 0.15, 0.25, 0.45, 0.60)) ``` Two definitions of the MTD are in common use and `mtd_rule` chooses between them. The default, `"previous"`, names the dose below the one declared too toxic. The other takes the MTD to be the highest dose at which at most one of six patients had a DLT, expanding a dose that has only three patients before assessing it. ```{r} expanded <- oc_3p3(p_true = c(0.05, 0.15, 0.25, 0.45, 0.60), mtd_rule = "expand") round(expanded$sel_percent, 1) round(expanded$total_n_pts, 2) ``` The components of the result carry the same names as those of `sim_boin()`, so the same code can tabulate either design. `sim_3p3()` simulates the same design and exists to confirm the closed form rather than to obtain the numbers. `decision_table_3p3()` shows the rule itself. With `mtd_rule = "expand"` it also lists the search for the MTD that follows escalation. ```{r} decision_table_3p3(mtd_rule = "expand") ``` ## Tables and figures `oc_scenarios()` tabulates the true DLT rates of the scenarios with their true MTDs (and, when response rates are given, the true utilities and OBDs). `oc_results()` collects the results of any of the simulation functions, of their `_multi` versions and of `oc_3p3()` in one long data frame, and `oc_compare()` judges them against the true doses: how often the true MTD or OBD is selected, how many patients are treated there, how often an overdose is selected and how many patients are treated at overdoses. All three have `print()` and `plot()` methods. The 3+3 design is given as a list of `oc_3p3()` results named by the scenarios. ```{r} scenarios_two <- scenarios[c("MTD at dose 2", "MTD at dose 4")] truth <- oc_scenarios(scenarios_two, target = 0.30) truth boin_two <- sim_boin_multi(target = 0.30, scenarios = scenarios_two, n_cohort = 10, cohort_size = 3, n_trials = 2000, seed = 123) three_two <- lapply(scenarios_two, function(p) oc_3p3(p_true = p)) results <- oc_results(BOIN = boin_two, "3+3" = three_two) comparison <- oc_compare(BOIN = boin_two, "3+3" = three_two, truth = truth) comparison ``` ```{r, include = FALSE} correct_4 <- function(design) { comparison$pct_correct[comparison$design == design & comparison$scenario == "MTD at dose 4"] } ``` When the MTD is dose 4, BOIN selects it in `r round(correct_4("BOIN"), 1)` percent of the trials and the 3+3 design in `r round(correct_4("3+3"), 1)` percent. The selection of every dose is drawn by the `plot()` method of `oc_results()`, and the comparison by that of `oc_compare()`. ```{r results-plot, fig.width = 7, fig.height = 4.5, eval = requireNamespace("ggplot2", quietly = TRUE)} plot(results) ``` ```{r compare-plot, fig.width = 7, fig.height = 6, eval = requireNamespace("ggplot2", quietly = TRUE)} plot(comparison) ``` ## Agreement with the BOIN package The engine draws one uniform variate per patient, in enrollment order, and applies the decision rules in the order used by `BOIN::get.oc()`. With the same seed and matching arguments the two implementations agree trial by trial, not merely on average. The package's test suite checks this directly whenever the BOIN package is installed, and `inst/validation/compare-with-BOIN.R` runs the same comparison over 200 configurations covering every combination of the options the two packages share. ```{r, eval = FALSE} reference <- BOIN::get.oc( target = 0.30, p.true = c(0.05, 0.15, 0.25, 0.45, 0.60), ncohort = 20, cohortsize = 3, n.earlystop = 18, ntrial = 1000, seed = 6 ) ours <- sim_boin( target = 0.30, p_true = c(0.05, 0.15, 0.25, 0.45, 0.60), n_cohort = 20, cohort_size = 3, n_earlystop = 18, n_trials = 1000, seed = 6 ) all.equal(unname(ours$sel_percent), reference$selpercent) all.equal(unname(ours$n_pts_dose), reference$npatients) ``` ## References Kojima, M., Wende, W. and Zhao, H. (2024). Tips for Accelerating BOIN Design. *Therapeutic Innovation & Regulatory Science*, 58, 1129-1137. Liu S. and Yuan, Y. (2015). Bayesian Optimal Interval Designs for Phase I Clinical Trials. *Journal of the Royal Statistical Society: Series C*, 64, 507-523. Yan, F., Zhang, L., Zhou, Y., Pan, H., Liu, S. and Yuan, Y. (2020). BOIN: An R Package for Designing Single-Agent and Drug-Combination Dose-Finding Trials Using Bayesian Optimal Interval Designs. *Journal of Statistical Software*, 94(13), 1-32.