Docs/Two-Arm Bayesian Design

Two-Arm Bayesian Trial Design

Technical documentation for sample size determination in two-arm randomized Bayesian trials. Supports superiority and non-inferiority designs with flexible allocation ratios and independent arm priors.

1. Overview & Design Settings

This calculator determines the sample size for two-arm randomized Bayesian trials comparing a treatment arm to a control arm. It supports both superiority and non-inferiority designs with binary endpoints.

Design Types

Superiority

Test whether treatment is better than control

H0: θTθC  vs  H1: θT>θCH_0{:}\ \theta_T {\leq} \theta_C \ \ vs \ \ H_1{:}\ \theta_T {>} \theta_C

Non-Inferiority

Test whether treatment is not worse by margin δ\delta

H0: Δδ  vs  H1: Δ>δH_0{:}\ \Delta {\leq} {-}\delta \ \ vs \ \ H_1{:}\ \Delta {>} {-}\delta

Comparison Metrics

Risk Difference

Δ=θTθC\Delta = \theta_T - \theta_C

Absolute difference in response rates

Relative Risk

RR=θTθCRR = \frac{\theta_T}{\theta_C}

Ratio of response rates (superiority only)

Non-Inferiority + Ratio Not Supported

Non-inferiority margins are defined on the difference scale. Ratio-based non-inferiority (e.g., RR>0.8RR > 0.8) requires different margin interpretation and is not currently supported.

2. Statistical Model

Each arm is modeled with an independent Beta-Binomial conjugate prior:

Prior Distributions

Treatment Arm

θTBeta(αT,βT)\theta_T \sim \text{Beta}(\alpha_T, \beta_T)

Control Arm

θCBeta(αC,βC)\theta_C \sim \text{Beta}(\alpha_C, \beta_C)

Likelihood

Given kTk_T responses in nTn_Ttreatment patients and kCk_C responses innCn_C control patients:

kTθTBinomial(nT,θT),kCθCBinomial(nC,θC)k_T | \theta_T \sim \text{Binomial}(n_T, \theta_T), \quad k_C | \theta_C \sim \text{Binomial}(n_C, \theta_C)

Posterior Distributions

θTkTBeta(αT+kT,βT+nTkT)\theta_T | k_T \sim \text{Beta}(\alpha_T + k_T, \beta_T + n_T - k_T)
θCkCBeta(αC+kC,βC+nCkC)\theta_C | k_C \sim \text{Beta}(\alpha_C + k_C, \beta_C + n_C - k_C)

Shared vs. Independent Priors

By default, both arms use the same prior (αT=αC,βT=βC\alpha_T = \alpha_C, \beta_T = \beta_C). Independent priors can be specified when arms have different expected rates (e.g., control rate is well-established from historical data).

3. Decision Rules

Superiority Decision Rule

For risk difference comparison:

Declare Success if P(θTθC>0Data)γ\text{Declare Success if } P(\theta_T - \theta_C > 0 | \text{Data}) \geq \gamma

For relative risk comparison:

Declare Success if P(θT/θC>1Data)γ\text{Declare Success if } P(\theta_T / \theta_C > 1 | \text{Data}) \geq \gamma

Non-Inferiority Decision Rule

With margin δ>0\delta > 0:

Declare Success if P(θTθC>δData)γ\text{Declare Success if } P(\theta_T - \theta_C > -\delta | \text{Data}) \geq \gamma

Monte Carlo Probability Estimation

The posterior probability is computed via Monte Carlo sampling:

# Draw samples from posteriors
θ_T_samples = Beta(α_T + k_T, β_T + n_T - k_T).sample(10000)
θ_C_samples = Beta(α_C + k_C, β_C + n_C - k_C).sample(10000)

# Compute comparison metric
if comparison == "difference":
    metric = θ_T_samples - θ_C_samples
    threshold = margin  # 0 for superiority, -δ for NI
else:  # ratio
    metric = θ_T_samples / θ_C_samples
    threshold = 1.0

# Estimate probability
P_success = mean(metric > threshold)

4. Operating Characteristics

Operating characteristics are computed via nested Monte Carlo simulation to evaluate the design under different true parameter values.

Type I Error

Probability of success when null is true

Superiority: θT=θC\theta_T = \theta_C
NI: θTθC=δ\theta_T - \theta_C = -\delta

Power

Probability of success when alternative is true

Superiority: θT=θC+Δ\theta_T = \theta_C + \Delta
NI: θT=θC\theta_T = \theta_C (treatment equivalent)

Simulation Algorithm

for sim in 1...N_simulations:
    # Under null hypothesis
    k_T_null = Binomial(n_T, θ_T_null)
    k_C_null = Binomial(n_C, θ_C_null)
    if P(θ_T > θ_C | k_T_null, k_C_null) >= γ:
        type1_count += 1

    # Under alternative hypothesis
    k_T_alt = Binomial(n_T, θ_T_alt)
    k_C_alt = Binomial(n_C, θ_C_alt)
    if P(θ_T > θ_C | k_T_alt, k_C_alt) >= γ:
        power_count += 1

type1_error = type1_count / N_simulations
power = power_count / N_simulations

Computational Note

The default uses 5,000 outer simulations × 5,000 inner Monte Carlo samples for posterior probability estimation. The final operating characteristics use 3× simulations (15,000) for higher precision.

5. Allocation Ratios

The allocation ratio r=nT/nCr = n_T / n_C determines how patients are distributed between arms. Given a control sample sizenCn_C:

nT=rnCn_T = \lfloor r \cdot n_C \rfloor

Common Allocation Ratios

RatioDistributionWhen to Use
1:1EqualMost efficient statistically; standard choice
2:1More on treatmentEnhance safety data or patient preference for active treatment
1:2More on controlRare; when control data has added value
3:1Heavy treatmentEthical concerns with randomization to control

Power Impact of Unequal Allocation

Unequal allocation (e.g., 2:1) requires ~10-15% more total patients than 1:1 to achieve the same power. The calculator accounts for this when searching for the optimal sample size.

6. Power Curve Analysis

The power curve shows how the probability of declaring success varies with the true treatment effect. This is computed across a range of effect sizes at the recommended sample size.

Power Curve Grid

For risk difference, power is evaluated at:

Δ{0.10,0.05,0,0.05,0.10,0.15,0.20,...,Δdesign}\Delta \in \{-0.10, -0.05, 0, 0.05, 0.10, 0.15, 0.20, ..., \Delta_{design}\}

Key points on the curve:

  • Δ=0\Delta = 0: Type I error rate (should be ≤ 0.05)
  • Δ=Δdesign\Delta = \Delta_{design}: Power at design alternative (should be ≥ 0.80)
  • Crossover point: Effect size where power = 50% (minimum detectable effect)

7. Regulatory Considerations

FDA Guidance on Two-Arm Bayesian Trials

Per the January 2026 guidance, sponsors must demonstrate that Bayesian two-arm designs maintain appropriate frequentist error control and provide operating characteristics under both null and alternative hypotheses.

SAP Documentation Checklist

  • Design Type: Superiority or non-inferiority with margin justification
  • Priors: Report αT,βT,αC,βC\alpha_T, \beta_T, \alpha_C, \beta_Cwith ESS and source documentation
  • Decision Rule: Threshold γ\gamma, comparison metric, and success criterion
  • Sample Size: nT,nCn_T, n_C with allocation ratio justification
  • Operating Characteristics: Type I error and power with simulation parameters
  • Sensitivity Analysis: Prior sensitivity and sample size robustness

Non-Inferiority Margin Justification

For non-inferiority designs, the margin δ\deltamust be pre-specified and justified based on:

  • Clinical significance (smallest effect that matters to patients)
  • Historical effect size of active control vs. placebo
  • Regulatory precedent in the therapeutic area

8. API Quick Reference

POST /api/v1/calculators/bayesian-two-arm

Key Parameters

ParameterTypeDescription
control_ratefloatExpected control arm response rate
treatment_effectfloatExpected difference θ_T - θ_C
design_typestring"superiority" | "non_inferiority"
decision_thresholdfloatPosterior probability threshold γ (default: 0.95)
allocation_ratiofloatn_T / n_C ratio (default: 1.0)

Key Response Fields

  • recommended_n_per_arm — Sample size per arm
  • recommended_n_total — Total sample size
  • operating_characteristics — Type I error and power
  • decision_rule — Design type and interpretation
View full API documentation →