| Title: | Bayesian and Adaptive Clinical Trial Simulation and Monitoring |
|---|---|
| Description: | Provides tools for simulating and evaluating Bayesian and adaptive clinical trial designs with binary outcomes. The package includes methods for trial simulation, posterior and predictive probability monitoring, adaptive randomisation, Bayesian treatment effect estimation, dose-finding, Simon two-stage phase II designs, group sequential monitoring boundaries, operating characteristic evaluation, and interim decision support. The implementation is motivated by established Bayesian and adaptive design methodology, including Simon's two-stage design for phase II trials Simon (1989) <doi:10.1016/0197-2456(89)90015-9>, Bayesian adaptive clinical trial approaches described by Berry et al. (2010, ISBN:9781439825488), and modern adaptive trial frameworks reviewed by Pallmann et al. (2018) <doi:10.1186/s12916-018-1017-7>. |
| Authors: | Muhammad Zahir Khan [aut, cre] |
| Maintainer: | Muhammad Zahir Khan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-15 09:30:44 UTC |
| Source: | https://github.com/zerish12/adaptivetrialsr |
Calculates response-adaptive randomisation probabilities from posterior mean response rates. Better-performing arms receive higher allocation probabilities while preserving minimum and maximum allocation limits.
adaptive_randomisation( posterior_means, min_prob = 0.1, max_prob = 0.8, power = 1 )adaptive_randomisation( posterior_means, min_prob = 0.1, max_prob = 0.8, power = 1 )
posterior_means |
Numeric vector of posterior mean response rates. Names may be supplied for treatment arms. |
min_prob |
Minimum allocation probability for each arm. Default is 0.10. |
max_prob |
Maximum allocation probability for any arm. Default is 0.80. |
power |
Tuning parameter controlling how strongly allocation favours better-performing arms. Default is 1. |
A data frame with treatment arms, posterior means, and allocation probabilities.
adaptive_randomisation( posterior_means = c(Control = 0.30, Treatment = 0.50) ) adaptive_randomisation( posterior_means = c(Control = 0.25, TreatmentA = 0.45, TreatmentB = 0.60), min_prob = 0.10, max_prob = 0.80 )adaptive_randomisation( posterior_means = c(Control = 0.30, Treatment = 0.50) ) adaptive_randomisation( posterior_means = c(Control = 0.25, TreatmentA = 0.45, TreatmentB = 0.60), min_prob = 0.10, max_prob = 0.80 )
Applies Bayesian posterior monitoring to real patient-level binary-outcome clinical trial data. The function compares a treatment arm with a control arm using a beta-binomial model.
analyse_trial_data( data, arm_col = "arm", outcome_col = "outcome", control_arm, treatment_arm, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )analyse_trial_data( data, arm_col = "arm", outcome_col = "outcome", control_arm, treatment_arm, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
data |
A data frame containing patient-level trial data. |
arm_col |
Name of the treatment-arm column. |
outcome_col |
Name of the binary outcome column. |
control_arm |
Name of the control arm. |
treatment_arm |
Name of the treatment arm. |
margin |
Minimum clinically important treatment-control difference. |
efficacy_threshold |
Posterior probability threshold for declaring efficacy. |
futility_threshold |
Posterior probability threshold for futility. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of posterior simulations. |
seed |
Optional random seed. |
A data frame containing arm-level summaries, posterior probability, and Bayesian decision.
trial_data <- data.frame( arm = c("Control", "Control", "Control", "Treatment", "Treatment", "Treatment"), outcome = c(0, 1, 0, 1, 1, 0) ) analyse_trial_data( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 )trial_data <- data.frame( arm = c("Control", "Control", "Control", "Treatment", "Treatment", "Treatment"), outcome = c(0, 1, 0, 1, 1, 0) ) analyse_trial_data( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 )
Runs repeated Bayesian adaptive trial simulations across multiple true-response scenarios and summarises the resulting operating characteristics.
compare_trial_scenarios( scenarios, n_sim = 100, n_total = 100, interim_every = 20, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )compare_trial_scenarios( scenarios, n_sim = 100, n_total = 100, interim_every = 20, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
scenarios |
A data frame with columns control_response and treatment_response. |
n_sim |
Number of simulated trials per scenario. |
n_total |
Maximum total sample size per trial. |
interim_every |
Frequency of interim analyses. |
margin |
Minimum clinically important treatment-control difference. |
efficacy_threshold |
Posterior probability threshold for stopping early for efficacy. |
futility_threshold |
Posterior probability threshold for stopping early for futility. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of posterior simulations used inside each trial. |
seed |
Optional random seed. |
A data frame of operating characteristics by scenario.
scenarios <- data.frame( control_response = c(0.25, 0.25, 0.25), treatment_response = c(0.25, 0.35, 0.45) ) compare_trial_scenarios( scenarios = scenarios, n_sim = 10, n_total = 100, interim_every = 20, nsim = 1000, seed = 123 )scenarios <- data.frame( control_response = c(0.25, 0.25, 0.25), treatment_response = c(0.25, 0.35, 0.45) ) compare_trial_scenarios( scenarios = scenarios, n_sim = 10, n_total = 100, interim_every = 20, nsim = 1000, seed = 123 )
Creates a simple patient-level clinical trial data template for use with AdaptiveTrialsR. The template includes patient ID, treatment arm, and binary outcome columns.
create_trial_template(n = 20, arms = c("Control", "Treatment"), path = NULL)create_trial_template(n = 20, arms = c("Control", "Treatment"), path = NULL)
n |
Number of rows to create. Default is 20. |
arms |
Character vector of treatment arms. Default is c("Control", "Treatment"). |
path |
Optional file path for saving the template as a CSV file. |
A data frame containing a trial data template.
create_trial_template(n = 10) temp_file <- tempfile(fileext = ".csv") create_trial_template(n = 10, path = temp_file)create_trial_template(n = 10) temp_file <- tempfile(fileext = ".csv") create_trial_template(n = 10, path = temp_file)
Provides a simplified Bayesian continual reassessment method-style dose-finding summary for Phase I trials. The function estimates posterior toxicity probabilities for each dose and recommends the dose closest to the target toxicity rate.
crm_dose_finding( dose_data, dose_col = "dose", n_col = "n", tox_col = "tox", target_toxicity = 0.25, prior_alpha = 1, prior_beta = 1 )crm_dose_finding( dose_data, dose_col = "dose", n_col = "n", tox_col = "tox", target_toxicity = 0.25, prior_alpha = 1, prior_beta = 1 )
dose_data |
A data frame containing dose-level data. |
dose_col |
Name of the dose column. |
n_col |
Name of the column containing number treated. |
tox_col |
Name of the column containing number with toxicity. |
target_toxicity |
Target toxicity probability. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
A data frame with posterior toxicity summaries and recommended dose.
dose_data <- data.frame( dose = c(1, 2, 3, 4), n = c(3, 3, 3, 3), tox = c(0, 0, 1, 2) ) crm_dose_finding(dose_data)dose_data <- data.frame( dose = c(1, 2, 3, 4), n = c(3, 3, 3, 3), tox = c(0, 0, 1, 2) ) crm_dose_finding(dose_data)
Creates a clean summary table of final trial decisions from repeated Bayesian adaptive clinical trial simulations.
decision_summary(simulations)decision_summary(simulations)
simulations |
An object returned by |
A data frame containing decision counts and percentages.
sims <- simulate_trials( n_sim = 20, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) decision_summary(sims)sims <- simulate_trials( n_sim = 20, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) decision_summary(sims)
Estimates the posterior distribution of the treatment-control difference in response probabilities using a beta-binomial model.
estimate_treatment_effect( data, arm_col = "arm", outcome_col = "outcome", control_arm, treatment_arm, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, cred_level = 0.95, seed = NULL )estimate_treatment_effect( data, arm_col = "arm", outcome_col = "outcome", control_arm, treatment_arm, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, cred_level = 0.95, seed = NULL )
data |
A data frame containing patient-level trial data. |
arm_col |
Name of the treatment-arm column. |
outcome_col |
Name of the binary outcome column. |
control_arm |
Name of the control arm. |
treatment_arm |
Name of the treatment arm. |
margin |
Minimum clinically important treatment-control difference. |
efficacy_threshold |
Posterior probability threshold for declaring efficacy. |
futility_threshold |
Posterior probability threshold for futility. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of posterior simulations. |
cred_level |
Credible interval level. |
seed |
Optional random seed. |
A data frame containing posterior treatment-effect summaries.
trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) estimate_treatment_effect( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 )trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) estimate_treatment_effect( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 )
Copies the package figures folder to the user's Desktop. This is useful for backing up figures for GitHub, manuscripts, presentations, or supplementary materials.
export_figures_to_desktop( figures_dir = "figures", folder_name = "AdaptiveTrialsR_figures", overwrite = TRUE )export_figures_to_desktop( figures_dir = "figures", folder_name = "AdaptiveTrialsR_figures", overwrite = TRUE )
figures_dir |
Source figures directory. Default is "figures". |
folder_name |
Name of the destination folder on Desktop. |
overwrite |
Logical. Should an existing destination folder be overwritten? Default is TRUE. |
Invisibly returns the destination folder path.
## Not run: export_figures_to_desktop() ## End(Not run)## Not run: export_figures_to_desktop() ## End(Not run)
Exports simulation-level results, operating characteristics, and decision summaries from repeated Bayesian adaptive trial simulations to CSV files.
export_trial_results(simulations, path = ".", prefix = "adaptive_trial")export_trial_results(simulations, path = ".", prefix = "adaptive_trial")
simulations |
An object returned by |
path |
Directory where CSV files should be saved. |
prefix |
Prefix used in exported file names. |
Invisibly returns a character vector of written file paths.
sims <- simulate_trials( n_sim = 10, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) temp_dir <- tempdir() export_trial_results(sims, path = temp_dir)sims <- simulate_trials( n_sim = 10, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) temp_dir <- tempdir() export_trial_results(sims, path = temp_dir)
Creates simple group sequential monitoring boundaries for interim analyses in a clinical trial. The function provides approximate efficacy and futility boundaries across planned information fractions.
group_sequential_boundary( looks = 5, alpha = 0.05, beta = 0.2, boundary = "obrien_fleming" )group_sequential_boundary( looks = 5, alpha = 0.05, beta = 0.2, boundary = "obrien_fleming" )
looks |
Number of interim looks including the final analysis. |
alpha |
Overall type I error rate. Default is 0.05. |
beta |
Type II error rate. Default is 0.20. |
boundary |
Type of efficacy boundary. Options are "obrien_fleming" and "pocock". |
A data frame containing information fractions and monitoring boundaries.
group_sequential_boundary( looks = 5, alpha = 0.05, beta = 0.20, boundary = "obrien_fleming" )group_sequential_boundary( looks = 5, alpha = 0.05, beta = 0.20, boundary = "obrien_fleming" )
Performs Bayesian interim monitoring using a beta-binomial model and calculates the posterior probability that the treatment response rate exceeds the control response rate by a specified margin.
interim_monitoring( y_treatment, n_treatment, y_control, n_control, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )interim_monitoring( y_treatment, n_treatment, y_control, n_control, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
y_treatment |
Number of responders in the treatment arm. |
n_treatment |
Number of patients in the treatment arm. |
y_control |
Number of responders in the control arm. |
n_control |
Number of patients in the control arm. |
margin |
Minimum clinically important difference. Default is 0. |
efficacy_threshold |
Posterior probability threshold for stopping early for efficacy. Default is 0.95. |
futility_threshold |
Posterior probability threshold for stopping early for futility. Default is 0.10. |
prior_alpha |
Beta prior alpha parameter. Default is 1. |
prior_beta |
Beta prior beta parameter. Default is 1. |
nsim |
Number of posterior simulations. Default is 10000. |
seed |
Optional random seed. |
A data frame containing interim monitoring results.
interim_monitoring( y_treatment = 18, n_treatment = 40, y_control = 10, n_control = 40 )interim_monitoring( y_treatment = 18, n_treatment = 40, y_control = 10, n_control = 40 )
Creates a publication-quality plot of posterior toxicity probabilities across dose levels from a Bayesian CRM-style dose-finding summary.
plot_dose_finding( dose_result, title = "Bayesian Phase I Dose-Finding Summary", subtitle = "Posterior toxicity estimates by dose level" )plot_dose_finding( dose_result, title = "Bayesian Phase I Dose-Finding Summary", subtitle = "Posterior toxicity estimates by dose level" )
dose_result |
A data frame returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
dose_data <- data.frame( dose = c(1, 2, 3, 4), n = c(3, 3, 3, 3), tox = c(0, 0, 1, 2) ) dose_result <- crm_dose_finding(dose_data) plot_dose_finding(dose_result)dose_data <- data.frame( dose = c(1, 2, 3, 4), n = c(3, 3, 3, 3), tox = c(0, 0, 1, 2) ) dose_result <- crm_dose_finding(dose_data) plot_dose_finding(dose_result)
Creates a publication-quality plot of efficacy and futility monitoring boundaries across planned interim analyses.
plot_group_sequential_boundary( boundary_data, title = "Group Sequential Monitoring Boundaries", subtitle = "Approximate efficacy and futility boundaries across interim looks" )plot_group_sequential_boundary( boundary_data, title = "Group Sequential Monitoring Boundaries", subtitle = "Approximate efficacy and futility boundaries across interim looks" )
boundary_data |
A data frame returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
boundaries <- group_sequential_boundary( looks = 5, alpha = 0.05, beta = 0.20 ) plot_group_sequential_boundary(boundaries)boundaries <- group_sequential_boundary( looks = 5, alpha = 0.05, beta = 0.20 ) plot_group_sequential_boundary(boundaries)
Creates a publication-quality bar plot of key operating characteristics from repeated Bayesian adaptive clinical trial simulations.
plot_operating_characteristics( simulations, title = "Operating Characteristics of Bayesian Adaptive Trial Design", subtitle = "Estimated from repeated trial simulations" )plot_operating_characteristics( simulations, title = "Operating Characteristics of Bayesian Adaptive Trial Design", subtitle = "Estimated from repeated trial simulations" )
simulations |
An object returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object showing key operating characteristics.
sims <- simulate_trials( n_sim = 10, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) plot_operating_characteristics(sims)sims <- simulate_trials( n_sim = 10, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) plot_operating_characteristics(sims)
Creates a publication-quality density plot of posterior response probabilities for each trial arm using a beta-binomial model.
plot_posterior_density( data, arm_col = "arm", outcome_col = "outcome", prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL, title = "Posterior Response Distributions by Trial Arm", subtitle = "Beta-binomial posterior densities for binary clinical trial outcomes" )plot_posterior_density( data, arm_col = "arm", outcome_col = "outcome", prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL, title = "Posterior Response Distributions by Trial Arm", subtitle = "Beta-binomial posterior densities for binary clinical trial outcomes" )
data |
A data frame containing patient-level trial data. |
arm_col |
Name of the treatment-arm column. |
outcome_col |
Name of the binary outcome column. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of posterior simulations. |
seed |
Optional random seed. |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) plot_posterior_density(trial_data, seed = 123)trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) plot_posterior_density(trial_data, seed = 123)
Creates a publication-quality forest-style plot of posterior mean response rates and credible intervals for each trial arm.
plot_posterior_intervals( posterior_data, title = "Posterior Response Estimates by Trial Arm", subtitle = "Posterior means with 95% credible intervals" )plot_posterior_intervals( posterior_data, title = "Posterior Response Estimates by Trial Arm", subtitle = "Posterior means with 95% credible intervals" )
posterior_data |
A data frame returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) post <- posterior_summary(trial_data) plot_posterior_intervals(post)trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) post <- posterior_summary(trial_data) plot_posterior_intervals(post)
Creates a publication-quality bar plot comparing observed response rates between control and treatment arms from real patient-level trial data.
plot_real_trial_results( analysis_result, title = "Bayesian Analysis of Real Trial Data", subtitle = "Observed response rates by treatment arm" )plot_real_trial_results( analysis_result, title = "Bayesian Analysis of Real Trial Data", subtitle = "Observed response rates by treatment arm" )
analysis_result |
A data frame returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
trial_data <- data.frame( arm = c("Control", "Control", "Control", "Treatment", "Treatment", "Treatment"), outcome = c(0, 1, 0, 1, 1, 0) ) result <- analyse_trial_data( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 ) plot_real_trial_results(result)trial_data <- data.frame( arm = c("Control", "Control", "Control", "Treatment", "Treatment", "Treatment"), outcome = c(0, 1, 0, 1, 1, 0) ) result <- analyse_trial_data( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 ) plot_real_trial_results(result)
Creates a publication-quality histogram showing the distribution of enrolled sample sizes across repeated Bayesian adaptive clinical trial simulations.
plot_sample_size_distribution( simulations, title = "Sample Size Distribution Across Adaptive Trial Simulations", subtitle = "Distribution of enrolled patients before stopping or reaching maximum sample size" )plot_sample_size_distribution( simulations, title = "Sample Size Distribution Across Adaptive Trial Simulations", subtitle = "Distribution of enrolled patients before stopping or reaching maximum sample size" )
simulations |
An object returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
sims <- simulate_trials( n_sim = 20, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) plot_sample_size_distribution(sims)sims <- simulate_trials( n_sim = 20, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) plot_sample_size_distribution(sims)
Creates a publication-quality plot comparing operating characteristics across multiple true treatment-effect scenarios.
plot_scenario_comparison( scenario_results, metric = "probability_stop_efficacy", title = "Operating Characteristics Across Trial Scenarios", subtitle = "Bayesian adaptive trial performance under different treatment effects" )plot_scenario_comparison( scenario_results, metric = "probability_stop_efficacy", title = "Operating Characteristics Across Trial Scenarios", subtitle = "Bayesian adaptive trial performance under different treatment effects" )
scenario_results |
A data frame returned by |
metric |
Operating characteristic to plot. Default is "probability_stop_efficacy". |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
scenarios <- data.frame( control_response = c(0.25, 0.25, 0.25), treatment_response = c(0.25, 0.35, 0.45) ) scenario_results <- compare_trial_scenarios( scenarios = scenarios, n_sim = 10, n_total = 100, interim_every = 20, nsim = 1000, seed = 123 ) plot_scenario_comparison(scenario_results)scenarios <- data.frame( control_response = c(0.25, 0.25, 0.25), treatment_response = c(0.25, 0.35, 0.45) ) scenario_results <- compare_trial_scenarios( scenarios = scenarios, n_sim = 10, n_total = 100, interim_every = 20, nsim = 1000, seed = 123 ) plot_scenario_comparison(scenario_results)
Creates a publication-quality plot of the posterior treatment-control difference with a Bayesian credible interval.
plot_treatment_effect( effect_result, title = "Bayesian Treatment Effect Estimate", subtitle = "Posterior treatment-control difference with credible interval" )plot_treatment_effect( effect_result, title = "Bayesian Treatment Effect Estimate", subtitle = "Posterior treatment-control difference with credible interval" )
effect_result |
A data frame returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object.
trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) effect <- estimate_treatment_effect( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 ) plot_treatment_effect(effect)trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) effect <- estimate_treatment_effect( data = trial_data, control_arm = "Control", treatment_arm = "Treatment", seed = 123 ) plot_treatment_effect(effect)
Creates a publication-quality plot of posterior probability across interim analyses for a simulated Bayesian adaptive clinical trial.
plot_trial_path( trial, title = "Bayesian Interim Monitoring Path", subtitle = "Posterior probability of treatment benefit across interim analyses" )plot_trial_path( trial, title = "Bayesian Interim Monitoring Path", subtitle = "Posterior probability of treatment benefit across interim analyses" )
trial |
An object returned by |
title |
Plot title. |
subtitle |
Plot subtitle. |
A ggplot object showing the Bayesian interim monitoring path.
trial <- simulate_trial( n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, seed = 123 ) plot_trial_path(trial)trial <- simulate_trial( n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, seed = 123 ) plot_trial_path(trial)
Computes Bayesian posterior summaries for binary response rates in each treatment arm using a beta-binomial model.
posterior_summary( data, arm_col = "arm", outcome_col = "outcome", prior_alpha = 1, prior_beta = 1, cred_level = 0.95 )posterior_summary( data, arm_col = "arm", outcome_col = "outcome", prior_alpha = 1, prior_beta = 1, cred_level = 0.95 )
data |
A data frame containing patient-level trial data. |
arm_col |
Name of the treatment-arm column. |
outcome_col |
Name of the binary outcome column. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
cred_level |
Credible interval level. Default is 0.95. |
A data frame containing posterior summaries by treatment arm.
trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) posterior_summary(trial_data)trial_data <- data.frame( arm = c("Control", "Control", "Treatment", "Treatment"), outcome = c(0, 1, 1, 1) ) posterior_summary(trial_data)
Calculates the posterior probability that the treatment response rate exceeds the control response rate by at least a specified margin using a beta-binomial model.
predict_success( y_treatment, n_treatment, y_control, n_control, margin = 0, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )predict_success( y_treatment, n_treatment, y_control, n_control, margin = 0, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
y_treatment |
Number of responders in the treatment arm. |
n_treatment |
Number of patients in the treatment arm. |
y_control |
Number of responders in the control arm. |
n_control |
Number of patients in the control arm. |
margin |
Minimum clinically important difference. Default is 0. |
prior_alpha |
Beta prior alpha parameter. Default is 1. |
prior_beta |
Beta prior beta parameter. Default is 1. |
nsim |
Number of posterior simulations. Default is 10000. |
seed |
Optional random seed. |
A data frame containing posterior probability and decision.
predict_success( y_treatment = 18, n_treatment = 40, y_control = 10, n_control = 40 )predict_success( y_treatment = 18, n_treatment = 40, y_control = 10, n_control = 40 )
Estimates the predictive probability that a trial will meet its final success criterion if recruitment continues to the planned maximum sample size. This is useful for Bayesian futility monitoring in adaptive trials.
predictive_probability( y_treatment, n_treatment, y_control, n_control, n_total, margin = 0, success_threshold = 0.95, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )predictive_probability( y_treatment, n_treatment, y_control, n_control, n_total, margin = 0, success_threshold = 0.95, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
y_treatment |
Current number of responders in the treatment arm. |
n_treatment |
Current number of patients in the treatment arm. |
y_control |
Current number of responders in the control arm. |
n_control |
Current number of patients in the control arm. |
n_total |
Planned total sample size across both arms. |
margin |
Minimum clinically important treatment-control difference. |
success_threshold |
Posterior probability threshold for final success. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of simulation draws. |
seed |
Optional random seed. |
A data frame containing predictive probability and decision.
predictive_probability( y_treatment = 12, n_treatment = 30, y_control = 8, n_control = 30, n_total = 100, seed = 123 )predictive_probability( y_treatment = 12, n_treatment = 30, y_control = 8, n_control = 30, n_total = 100, seed = 123 )
Calculates an approximate sample size for a two-arm clinical trial with binary outcomes using a normal approximation for comparing two proportions.
sample_size_binary( p_control, p_treatment, alpha = 0.05, power = 0.8, allocation_ratio = 1 )sample_size_binary( p_control, p_treatment, alpha = 0.05, power = 0.8, allocation_ratio = 1 )
p_control |
Expected response probability in the control arm. |
p_treatment |
Expected response probability in the treatment arm. |
alpha |
Type I error rate. Default is 0.05. |
power |
Desired statistical power. Default is 0.80. |
allocation_ratio |
Allocation ratio treatment/control. Default is 1. |
A data frame containing sample size calculations.
sample_size_binary( p_control = 0.25, p_treatment = 0.45 )sample_size_binary( p_control = 0.25, p_treatment = 0.45 )
Searches for a Simon two-stage design for a single-arm Phase II trial with a binary outcome. The design tests an unacceptable response rate against a desirable response rate while controlling the type I error rate and ensuring the required power.
simon_two_stage(p0, p1, alpha = 0.05, power = 0.8, n_max = 100)simon_two_stage(p0, p1, alpha = 0.05, power = 0.8, n_max = 100)
p0 |
Unacceptable response probability under the null hypothesis. |
p1 |
Desirable response probability under the alternative hypothesis. |
alpha |
Maximum type I error rate. Default is 0.05. |
power |
Minimum desired power. Default is 0.80. |
n_max |
Maximum total sample size to search. Default is 100. |
A data frame containing the selected Simon two-stage design.
simon_two_stage( p0 = 0.20, p1 = 0.40, alpha = 0.10, power = 0.70, n_max = 35 ) ## Not run: simon_two_stage( p0 = 0.20, p1 = 0.40, alpha = 0.05, power = 0.80, n_max = 80 ) ## End(Not run)simon_two_stage( p0 = 0.20, p1 = 0.40, alpha = 0.10, power = 0.70, n_max = 35 ) ## Not run: simon_two_stage( p0 = 0.20, p1 = 0.40, alpha = 0.05, power = 0.80, n_max = 80 ) ## End(Not run)
Simulates a two-arm Bayesian adaptive clinical trial with binary outcomes. The trial can include interim monitoring for early stopping based on posterior probability thresholds.
simulate_trial( n_total = 100, true_response = c(0.25, 0.4), arm_names = c("Control", "Treatment"), interim_every = 20, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )simulate_trial( n_total = 100, true_response = c(0.25, 0.4), arm_names = c("Control", "Treatment"), interim_every = 20, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
n_total |
Maximum total sample size. |
true_response |
Numeric vector of true response probabilities for control and treatment arms. |
arm_names |
Character vector of treatment arm names. |
interim_every |
Frequency of interim analyses. |
margin |
Minimum clinically important treatment-control difference. |
efficacy_threshold |
Posterior probability threshold for stopping early for efficacy. |
futility_threshold |
Posterior probability threshold for stopping early for futility. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of posterior simulations. |
seed |
Optional random seed. |
A list containing patient-level data, interim results, and final trial decision.
simulate_trial( n_total = 100, true_response = c(0.25, 0.40), interim_every = 20, seed = 123 )simulate_trial( n_total = 100, true_response = c(0.25, 0.40), interim_every = 20, seed = 123 )
Runs repeated simulations of a Bayesian adaptive clinical trial and estimates key operating characteristics, including stopping probability, efficacy stopping rate, futility stopping rate, mean sample size, and probability of trial success.
simulate_trials( n_sim = 100, n_total = 100, true_response = c(0.25, 0.4), arm_names = c("Control", "Treatment"), interim_every = 20, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )simulate_trials( n_sim = 100, n_total = 100, true_response = c(0.25, 0.4), arm_names = c("Control", "Treatment"), interim_every = 20, margin = 0, efficacy_threshold = 0.95, futility_threshold = 0.1, prior_alpha = 1, prior_beta = 1, nsim = 10000, seed = NULL )
n_sim |
Number of simulated trials. |
n_total |
Maximum total sample size per trial. |
true_response |
Numeric vector of true response probabilities for control and treatment arms. |
arm_names |
Character vector of treatment arm names. |
interim_every |
Frequency of interim analyses. |
margin |
Minimum clinically important treatment-control difference. |
efficacy_threshold |
Posterior probability threshold for stopping early for efficacy. |
futility_threshold |
Posterior probability threshold for stopping early for futility. |
prior_alpha |
Beta prior alpha parameter. |
prior_beta |
Beta prior beta parameter. |
nsim |
Number of posterior simulations used inside each trial. |
seed |
Optional random seed. |
A list containing simulation-level results and operating characteristics.
sims <- simulate_trials( n_sim = 10, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) sims$operating_characteristicssims <- simulate_trials( n_sim = 10, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) sims$operating_characteristics
Provides a concise summary of a simulated adaptive clinical trial object
produced by simulate_trial().
summary_trial(trial)summary_trial(trial)
trial |
An object returned by |
A data frame summarising trial sample size, responses, stopping status, and final decision.
trial <- simulate_trial( n_total = 100, true_response = c(0.25, 0.40), interim_every = 20, seed = 123 ) summary_trial(trial)trial <- simulate_trial( n_total = 100, true_response = c(0.25, 0.40), interim_every = 20, seed = 123 ) summary_trial(trial)
Creates a concise plain-language report from repeated Bayesian adaptive clinical trial simulations. The report is intended for clinicians, trial teams, and non-statistical audiences.
trial_report(simulations)trial_report(simulations)
simulations |
An object returned by |
A character vector containing a formatted trial report.
sims <- simulate_trials( n_sim = 20, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) trial_report(sims)sims <- simulate_trials( n_sim = 20, n_total = 100, true_response = c(0.25, 0.45), interim_every = 20, nsim = 1000, seed = 123 ) trial_report(sims)
Checks whether a real clinical trial dataset has the minimum required structure for use with AdaptiveTrialsR functions. The dataset must contain one row per patient, a treatment-arm variable, and a binary outcome variable.
validate_trial_data( data, arm_col = "arm", outcome_col = "outcome", allowed_outcomes = c(0, 1) )validate_trial_data( data, arm_col = "arm", outcome_col = "outcome", allowed_outcomes = c(0, 1) )
data |
A data frame containing patient-level trial data. |
arm_col |
Name of the treatment-arm column. |
outcome_col |
Name of the binary outcome column. |
allowed_outcomes |
Allowed values for the binary outcome. Default is c(0, 1). |
A cleaned data frame with standardised columns arm and outcome.
trial_data <- data.frame( patient_id = 1:6, arm = c("Control", "Control", "Treatment", "Treatment", "Control", "Treatment"), outcome = c(0, 1, 1, 1, 0, 1) ) validate_trial_data(trial_data)trial_data <- data.frame( patient_id = 1:6, arm = c("Control", "Control", "Treatment", "Treatment", "Control", "Treatment"), outcome = c(0, 1, 1, 1, 0, 1) ) validate_trial_data(trial_data)