clinical-trial-design

v0.0.12
io.github.wei-ai-lab/clinical-trial-design Checked 4 days ago Published 7 months ago

Phase 2/3 clinical trial design via gsDesign / gsDesign2: sample size, GS boundaries, multiplicity

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

design_binary

Use when the user wants two-arm Phase 2/3 sample size with a BINARY primary endpoint — responder rate, fixed-time mortality, ORR, ACR20, remission/cure, anything that resolves to event-or-no-event per subject. Set comparison='superiority' (default), 'non-inferiority' (then provide ni_margin), or 'equivalence' (then provide equiv_margin; fixed-sample only). Set design_class='group-sequential' for interim analyses with alpha-spending. Supply an optional `operational` block (any 0–4 of accrual_rate, accrual_duration, follow_up_duration, total_trial_duration) and the kernel fills in the rest.…

ParameterTypeDescription
p_control *numberEvent rate in the control arm (0,1).
p_treatment *numberEvent rate in the treatment arm (0,1).
allocation_rationumberTreatment / control allocation ratio. 1 = balanced 1:1.
alphanumberType I error rate. For a standard two-sided 0.05 test use 0.025 with sided = 2.
comparisonstringHypothesis type. 'superiority' (default) tests for a difference; 'non-inferiority' requires ni_margin; 'equivalence' requires equiv_margin.
design_classstringDesign class. 'fixed' = single final analysis; 'group-sequential' = interim looks with alpha-spending. Group-sequential params (k, timing, sfu/sfl, test_type) are ignored when design_class = 'fixed'.
equiv_marginnumberTwo-sided equivalence margin (TOST). Required when comparison='equivalence'. Fixed-sample only.
kintegerNumber of planned analyses including the final one. Integer in [2, 10].
ni_marginnumberNon-inferiority margin on the risk-difference scale. Required when comparison='non-inferiority'.
operationalobjectOptional operational kernel inputs. Supply any 0-4 of {accrual_rate, accrual_duration, follow_up_duration, total_trial_duration}; the solver fills in the missing values from rate*duration = N and A +…
powernumber1 - beta. Targeted power of the test (default 0.9).
sflAlpha-spending function. OF = O'Brien-Fleming, Pocock = Pocock, HSD = Hwang-Shih-DeCani (needs sfupar), Power = power family (needs sfupar), LDOF / LDPocock = Lan-DeMets approximations (the standard),…
sflparnumberNumeric parameter for HSD / Power lower sf.
sfustringAlpha-spending function. OF = O'Brien-Fleming, Pocock = Pocock, HSD = Hwang-Shih-DeCani (needs sfupar), Power = power family (needs sfupar), LDOF / LDPocock = Lan-DeMets approximations (the standard),…
sfuparnumberNumeric parameter for HSD / Power upper sf.
sidednumber1 = one-sided test (default), 2 = two-sided. Many modern designs use sided = 1 with alpha = 0.025 to match the two-sided 0.05 convention.
test_typeintegergsDesign test.type. 1 = efficacy-only, 2 = symmetric efficacy+futility, 3 = non-binding futility, 4 = binding futility, 5/6 = same with lower beta-spending.
timingarrayInformation fractions at each analysis, length k, strictly increasing in (0,1], last = 1. Defaults to equal spacing 1/k, 2/k, ..., 1.

design_continuous

Use when the user wants two-arm Phase 2/3 sample size with a CONTINUOUS primary endpoint — change from baseline in a measured score (HAM-D-17, PANSS, HbA1c reduction, eGFR slope, BP), QoL scale, biomarker level. Provide mean_diff (assumed treatment - control mean) and the common within-arm sd. Set comparison='superiority' (default), 'non-inferiority' (provide ni_margin), or 'equivalence' (provide equiv_margin; fixed-sample only). Set design_class='group-sequential' for interim analyses with alpha-spending. Supports the same `operational` block as design_binary and design_survival. For multi-…

ParameterTypeDescription
mean_diff *numberAssumed mean difference (treatment - control).
sd *numberCommon within-arm SD.
allocation_rationumberTreatment / control allocation ratio. 1 = balanced 1:1.
alphanumberType I error rate. For a standard two-sided 0.05 test use 0.025 with sided = 2.
comparisonstringHypothesis type. 'superiority' (default) tests for a difference; 'non-inferiority' requires ni_margin; 'equivalence' requires equiv_margin.
design_classstringDesign class. 'fixed' = single final analysis; 'group-sequential' = interim looks with alpha-spending. Group-sequential params (k, timing, sfu/sfl, test_type) are ignored when design_class = 'fixed'.
equiv_marginnumberTwo-sided equivalence margin (TOST). Fixed-sample only.
kintegerNumber of planned analyses including the final one. Integer in [2, 10].
ni_marginnumberNon-inferiority margin on the mean-difference scale.
operationalobjectOptional operational kernel inputs. Supply any 0-4 of {accrual_rate, accrual_duration, follow_up_duration, total_trial_duration}; the solver fills in the missing values from rate*duration = N and A +…
powernumber1 - beta. Targeted power of the test (default 0.9).
sflAlpha-spending function. OF = O'Brien-Fleming, Pocock = Pocock, HSD = Hwang-Shih-DeCani (needs sfupar), Power = power family (needs sfupar), LDOF / LDPocock = Lan-DeMets approximations (the standard),…
sflparnumber
sfustringAlpha-spending function. OF = O'Brien-Fleming, Pocock = Pocock, HSD = Hwang-Shih-DeCani (needs sfupar), Power = power family (needs sfupar), LDOF / LDPocock = Lan-DeMets approximations (the standard),…
sfuparnumber
sidednumber1 = one-sided test (default), 2 = two-sided. Many modern designs use sided = 1 with alpha = 0.025 to match the two-sided 0.05 convention.
test_typeintegergsDesign test.type. 1 = efficacy-only, 2 = symmetric efficacy+futility, 3 = non-binding futility, 4 = binding futility, 5/6 = same with lower beta-spending.
timingarrayInformation fractions at each analysis, length k, strictly increasing in (0,1], last = 1. Defaults to equal spacing 1/k, 2/k, ..., 1.

design_survival

Use when the user wants Phase 2/3 sample size with a TIME-TO-EVENT primary endpoint — overall survival, PFS, time to first hospitalization, time to progression, time to a CV composite, etc. Choose the test statistic via `model`: 'ph' (default — log-rank under proportional hazards, gsDesign::nSurv / gsSurv), 'maxcombo' (delayed effect / non-proportional hazards via Fleming-Harrington combo), 'rmst' (restricted mean survival to landmark tau), 'milestone' (survival probability at landmark t*), 'wlr' / 'ahr' (weighted log-rank / average HR for GS NPH). Set design_class='group-sequential' for i…

ParameterTypeDescription
control_median *numberControl-arm median survival (months).
accrual_durationnumberAccrual period (months).
accrual_ratenumberEnrollment rate (subjects/month).
allocation_rationumberTreatment / control allocation ratio. 1 = balanced 1:1.
alphanumberType I error rate. For a standard two-sided 0.05 test use 0.025 with sided = 2.
analysis_timesarrayCalendar times of k planned analyses (NPH GS); last = study duration.
bindingbooleanWhether the futility boundary is binding (NPH GS).
comparisonstringHypothesis type. 'superiority' (default) tests for a difference; 'non-inferiority' requires ni_margin; 'equivalence' requires equiv_margin.
delay_monthsnumberDuration of HR=1 period preceding the effect (NPH models).
design_classstringDesign class. 'fixed' = single final analysis; 'group-sequential' = interim looks with alpha-spending. Group-sequential params (k, timing, sfu/sfl, test_type) are ignored when design_class = 'fixed'.
dropout_ratenumberPer-month dropout hazard.
followup_durationnumberMinimum follow-up after last enrollment (months).
gammaarrayFleming-Harrington gamma weights (MaxCombo / WLR).
hazard_rationumberTarget HR (PH only). < 1 favors treatment. For NI with hr_null > 1, the assumed true HR is often 1.
hr_nullnumberNull-hypothesis HR for non-inferiority (typically > 1, e.g. 1.3).
kintegerNumber of planned analyses including the final one. Integer in [2, 10].
modelstringSurvival statistical model. 'ph' = log-rank under proportional hazards (gsDesign::nSurv / gsSurv). 'maxcombo' / 'rmst' / 'milestone' are NPH fixed-sample (gsDesign2::fixed_design_*). 'wlr' / 'ahr' are…
ni_hrnumberAlias for hr_null.
operationalobjectOptional operational kernel inputs. Supply any 0-4 of {accrual_rate, accrual_duration, follow_up_duration, total_trial_duration}; the solver fills in the missing values from rate*duration = N and A +…
post_delay_hrnumberHR after delay_months (NPH models).
powernumber1 - beta. Targeted power of the test (default 0.9).
reasoning_chainarrayOptional structured citation trail. Each entry: {decision, value, justification, source_type, source_ref?}. design_report() renders this inline; sponsor_confidential entries trigger a redaction prompt…
rhoarrayFleming-Harrington rho weights (MaxCombo / WLR).
sflAlpha-spending function. OF = O'Brien-Fleming, Pocock = Pocock, HSD = Hwang-Shih-DeCani (needs sfupar), Power = power family (needs sfupar), LDOF / LDPocock = Lan-DeMets approximations (the standard),…
sflparnumber
sfustringAlpha-spending function. OF = O'Brien-Fleming, Pocock = Pocock, HSD = Hwang-Shih-DeCani (needs sfupar), Power = power family (needs sfupar), LDOF / LDPocock = Lan-DeMets approximations (the standard),…
sfuparnumber
sidednumberTTE designs are one-sided.
taunumberLandmark time for RMST / milestone (months). Defaults to total study duration.
tau_fhFleming-Harrington tau (MaxCombo / WLR).
test_typeintegergsDesign test.type. 1 = efficacy-only, 2 = symmetric efficacy+futility, 3 = non-binding futility, 4 = binding futility, 5/6 = same with lower beta-spending.
timingarrayInformation fractions at each analysis, length k, strictly increasing in (0,1], last = 1. Defaults to equal spacing 1/k, 2/k, ..., 1.

design_co_primary

Multi-endpoint co-primary trial design with multiplicity control. Use when a confirmatory trial requires positive results on two or more primary endpoints (oncology PFS+OS, CV death+HHF, etc.). Strategies: fixed-sequence (hierarchical, full alpha per test, the canonical approach for ordered co-primary), alpha-split (partition alpha by weights), bonferroni (equal alpha-split). Each endpoint is sized at its effective alpha via the matching design_<type> wrapper; total N is the max across endpoints. For graphical multiplicity (Maurer-Bretz with alpha recycling), use `design_graphical_multiplicity…

ParameterTypeDescription
endpoints *objectNamed map of co-primary endpoints. Each entry has `type` plus the parameters the matching design_<type> wrapper accepts (e.g., for survival: model, design_class, control_median, hazard_ratio, accrual_…
allocation_rationumberTreatment-to-control allocation ratio, shared across endpoints.
alphanumberFamily-wise type I error (default 0.025, one-sided).
alpha_weightsobjectFor strategy='alpha-split' only. Named numeric vector summing to 1. Default (when omitted with alpha-split): equal weights 1/k.
orderingarrayFor strategy='fixed-sequence' only. Endpoint names in test order. Default: order in which `endpoints` was supplied.
powernumberPer-endpoint power (default 0.80).
reasoning_chainarrayOptional structured citation trail. Each entry: {decision, value, justification, source_type, source_ref?}. design_report() renders this inline; sponsor_confidential entries trigger a redaction prompt…
sidednumberSidedness.
strategystringMultiplicity-control strategy. `fixed-sequence` (hierarchical) tests each endpoint at the full family alpha conditional on prior rejection — preserves alpha by closed testing, no per-test discount.…

design_multi_population

Multi-population (subgroup) trial design with multiplicity control. Use when a confirmatory trial tests the same endpoint in multiple populations — biomarker-positive subgroup + ITT, nested PD-L1 strata, etc. Pick relation='nested' (the canonical case: TPS≥50 ⊂ TPS≥20 ⊂ ITT, all patients enroll into the broadest, total N driven by largest implied-enrolled across strata) or 'disjoint' (strata enrolled separately, total N = sum). Strategies: fixed-sequence (hierarchical), alpha-split, bonferroni. For graphical multiplicity (Maurer-Bretz with alpha recycling between populations), use de…

ParameterTypeDescription
endpoint_args *objectShared endpoint design parameters (e.g., for survival: model, design_class, control_median, accrual_duration, followup_duration, dropout_rate). The effect parameter (hazard_ratio / p_treatment / delta…
endpoint_type *stringEndpoint family — selects which design_<type> wrapper handles each population.
populations *objectNamed map of populations. Each entry has `effect` (and `prevalence` for nested mode).
allocation_rationumber
alphanumber
alpha_weightsobjectFor strategy='alpha-split' only. Names match `populations`; sum to 1.
orderingarrayFor strategy='fixed-sequence' only. Population names in test order.
powernumber
reasoning_chainarrayOptional structured citation trail. Each entry: {decision, value, justification, source_type, source_ref?}. design_report() renders this inline; sponsor_confidential entries trigger a redaction prompt…
relationstringHow populations relate. `nested` (default): subgroups overlap, all patients enroll into the broadest, total N = max of implied-enrolled-N. `disjoint`: separate strata enrolled, total N = sum of per-po…
sidednumber
strategystringMultiplicity-control strategy across populations. `fixed-sequence` is the canonical biomarker pattern (test strongest-effect subgroup first, gate broader strata on rejection).

design_graphical_multiplicity

Graphical multiplicity (Maurer-Bretz) trial design with alpha recycling. Use when a confirmatory trial has 2+ hypotheses (mixed primary + secondary, dose-response, parent + derived endpoints) where a graph-based procedure preserves family-wise alpha better than Bonferroni. Validates the transition matrix (Rule-3 + row sums) and constructs a graphicalMCP graph object. Sizes each hypothesis at its worst-case alpha; total N is the max across hypotheses. For simpler co-primary or multi-population designs use design_co_primary or design_multi_population instead.

ParameterTypeDescription
hypotheses *objectNamed map of hypotheses. Each entry has `type` plus the parameters the matching design_<type> wrapper accepts. Continuous uses `mean_diff`, binary uses `p_treatment`, survival uses `hazard_ratio`.
initial_weights *objectPer-hypothesis initial alpha weights. Names match `hypotheses`; sum to <= 1. Hypotheses with weight 0 start un-testable and become testable only after alpha is recycled to them through the transition…
transition_matrix *arraySquare (k x k) transition matrix. Row i column j = weight of alpha re-allocated from hypothesis i to hypothesis j upon rejection of i. Each row sums to <= 1; diagonal must be 0 (no self-loops). Order…
allocation_rationumber
alphanumber
gate_prereqsobjectOptional per-hypothesis prerequisite map. Each entry is the list of hypothesis names that must be rejected before this one can be tested. Used by the Rule-3 validator: every prerequisite must have a n…
powernumber
reasoning_chainarrayOptional structured citation trail. Each entry: {decision, value, justification, source_type, source_ref?}. design_report() renders this inline; sponsor_confidential entries trigger a redaction prompt…
sidednumber
worst_case_weightsobjectOptional override of the per-hypothesis worst-case weight used for sample-size sizing. Default: max(initial_weight_i, fallback) where fallback = smallest non-zero initial weight.

validate_against_benchmark

Load a benchmark corpus case, re-run the matching design wrapper with its inputs, and diff computed sample_size_total / events_total against expected within the case's tolerance.

ParameterTypeDescription
family *stringBenchmark family directory name under benchmarks/ (e.g. 'fixed-superiority', 'group-sequential', 'tte-nph').
id *stringCase ID = YAML filename without extension, e.g. '1997_CAPTURE_abciximab'.
toolstringOverride the design tool to dispatch. If omitted, inferred from case metadata.

verify_design

Monte Carlo simulation cross-check for a designr result. Closed-form simulation (rbinom / rnorm / rexp) drives empirical power and Type I error estimates against the design's target alpha and power. Supports fixed and group-sequential families on binary, continuous, and PH survival endpoints. NPH families (MaxCombo, RMST, milestone) and equivalence designs are not yet supported and return a clean error.

ParameterTypeDescription
result *objectA designr result object as returned by any design_* tool (the JSON payload, including $method, $inputs, and (for GS) $boundaries / $timing).
n_simintegerMonte Carlo replicate count. Default 5000.
seedintegerRNG seed for reproducibility. Default 1.
tolerance_power_ppnumberAllowed deviation from target power, in percentage points. Default 2.
tolerance_type_I_ppnumberAllowed deviation from target alpha, in percentage points. Default 0.5.

design_report

Render a clinician-readable design summary in markdown, Word, or PDF. Reasoning chain (when populated on the result) appears as a table; sponsor_confidential entries trigger a redaction warning at the top. Sections: title, design overview, key inputs, headline output, GS analysis plan, reasoning chain, method + version. Default output is markdown text; format='docx' returns a native Word file path (officer); format='pdf' renders via rmarkdown + Pandoc.

ParameterTypeDescription
result *objectA designr result object as returned by any design_* tool (the JSON payload, including $method, $inputs, and (for GS) $boundaries / $timing).
formatstringOutput format. 'markdown' (default) returns the report as text. 'docx' writes a native Word document via the officer R package; 'pdf' renders via rmarkdown + Pandoc (requires Pandoc + a TeX engine on…
pathstringFor format='docx' or 'pdf': output file path. If omitted, a tempfile is created and its path returned in the result.