Credit: https://xkcd.com/303/, Randal Munroe
Quantify decision-making ability.
Compare alternative designs.
Complicated R code.
Long execution times.
Frequent changes.
Extremely rare and severe autoimmune liver disease.
Phase 2A study, first look at efficacy.
Double blind: novel therapy vs standard of care.
Randomize up to 100 patients (1:1).
\[ \begin{aligned} \color{orange}{\eta_i(t)} = x_i(t) \beta + b_i \end{aligned} \]
\(\color{orange}{\eta_i(t)}\): expected log bilirubin for patient \(i\) at time \(t\).
\[ \begin{aligned} h_i(t) = h_0(t, \lambda) \exp \left (\color{orange}{\eta_i(t)} \alpha + d_i \color{blue}{\theta} \right ) \end{aligned} \]
\(d_i\): 1 for treatment, 0 for control.
\(\color{blue}{\theta}\): log hazard ratio of treatment vs control.
\[ \begin{aligned} g(y) = \text{P}(\exp(\color{blue}{\theta}) < 0.75 \ | \ y) \end{aligned} \]
\[ \begin{aligned} g(y) > 0.8 \end{aligned} \]
\[ \begin{aligned} g(y) < 0.4 \end{aligned} \]
10-year accrual period.
Futility interim at \(n\) events (liver transplant or death).
Goal: simulate to propose a suitable \(n\).
Simulate 10000 futile trials for \(n = 40, 50, 60, 70\).
A fixed hazard ratio of 1 would be unrealistic.
Instead, draw from a distribution that captures futility.
Use the posterior distribution from a historical trial.
Datasets pbc
and pbcseq
from the survival
package.
Indication: primary biliary cholangitis (PBC).
Mayo Clinic trial of D-penicillamine vs placebo.
D-penicillamine did not improve survival.
\[
\Huge
{\color{blue}{y}} = {\color{purple}{f}}({\color{teal}{x}})
\]
Everything that exists in an object.
Everything that happens is a function call.
— John Chambers
\[ \Huge {\color{blue}{y}} = {\color{purple}{f}}({\color{teal}{x}}) \]
Function | Description |
---|---|
draw_hazard_ratios() |
From historical model. |
trial() |
Simulate one trial rep. |
plot_results() |
Visualize results. |
Step 1: draw historical hazard ratios.
Step 2: run simulations.
HMC = Hamiltonian Monte Carlo.
Physics simulation samples from the posterior distribution.
32 seconds x 10000 reps x 4 scenarios \(>\) 2 weeks!
A pipeline is a formal group of tasks.
Each task has dependencies, a command, and output.
A task can only modify its own output.
A task cannot eventually depend on itself.
Examples: Make, Airflow, Nextflow, Prefect, and targets
.
Retains the comfort of your local R session.
Focuses on your functions, not your scripts.
Integrates with Quarto.
Runs distributed computing.
R/
scripts contain functions.
_targets.R
defines the pipeline.
tar_read(trials, branches = seq_len(8))
#> # A tibble: 10 × 4
#> events efficacy enrolled years
#> <dbl> <dbl> <dbl> <dbl>
#> 1 40 0.055 58 6.31
#> 2 50 0.0685 77 7.99
#> 3 60 0.0602 81 7.93
#> 4 70 0.153 93 9.01
#> 5 40 0.220 65 6.03
#> 6 50 0.479 73 6.43
#> 7 60 0.918 87 8.91
#> 8 70 0.832 89 8.99
Interim at 40 events looks promising.
Need to simulate full design with interims and final analysis
targets
documentation: https://docs.ropensci.org/targets
Clinical trial simulation pipeline: https://github.com/wlandau/targets-example-liver
images/hmc.png
: Prof. David Kahle, Baylor University.© 2025 Eli Lilly and Company