The scripts in this folder compute the expected values used in
tests/testthat. They are written independently of the R code and use
different numerical methods:
| Quantity | R code | Python reference |
|---|---|---|
| State probabilities, forward clock | closed-form transitions and Gauss-Legendre rules | products of matrix exponentials (scipy.linalg.expm) |
| State probabilities, reset clock | closed-form transitions and Gauss-Legendre rules | adaptive quadrature (scipy.integrate.quad) over the progression time, transitions by expm |
| Expected events, log-rank mean and information | accrual handled through cumulative integrals and Gauss-Legendre rules | adaptive quadrature with the enrolled fraction inside the integrand |
| Score covariance under the alternative | per-patient influence functions | formulas of Luo et al. (2019, Section 3.1) as printed, by nested quadrature |
| Bounds and stopping probabilities | mvtnorm::pmvnorm() (Miwa algorithm; Genz-Bretz algorithm with a fixed seed for four or more coordinates whose covariance is not Markov) | recursive conditioning with adaptive quadrature; for covariance matrices that are not Markov, exact recursion for a Markov control plus a quasi-Monte Carlo correction (ref_markov.py) |
| Moments of the score, the observed variance and the event indicator (studentized covariance, stage 2) | cumulative functions on Gauss-Legendre rules, entry by Gauss-Legendre rules | cumulative functions by an ODE solver (solve_ivp), entry by adaptive quadrature |
| Products of the PFS and OS functionals | four terms of counting-process integrals over the PFS and OS times (covariance note, equations (6)-(9)) | Fleischer model: conditioning on the death time; scenarios with switching: Monte Carlo with 10 million patients |
| Time derivatives of the score mean, information and events | integrals against the accrual density | central differences of the reference moments |
| Rejection probabilities of two endpoints (gs_prob_mtp()) | sums of rectangle probabilities over the outcomes of the first endpoint (Miwa algorithm; Genz-Bretz algorithm with a fixed seed for rectangles over both endpoints with four or more coordinates and for other rectangles of four or more coordinates whose covariance is not Markov) | numerical integration over the analyses of the joint density, with the decisions applied on the sample path (canonical joint distribution); for two looks, the formulas of Glimm et al. (2010) as one-dimensional integrals; Monte Carlo with 2 million trials |
| Designs with two endpoints or with looks driven by the events of different endpoints (ms_power(), stage 2) | .look_times(), .design_core2() and .fwer_core() with the functions above | analysis times by root finding on the reference events, moments and covariance from the references above, bounds by recursive conditioning, rejection probabilities as sums over the sample-path outcomes of rectangle probabilities by recursive conditioning with adaptive quadrature (any covariance matrix); Monte Carlo with 4 million trials |
| Model options of stage 3 (switch clock, AFT effect of the switch, switch before progression, censoring of PFS only) | closed forms on the pieces of the intensities (.post_general(), .pre_states(), .from_state5()) and Gauss-Legendre rules | adaptive quadrature over the switch, progression and switch-before-progression times (ref_model5.py); products of matrix exponentials for Markov models |
| Products of the PFS and OS functionals with a switch before progression or a censoring of PFS only | terms C1 to C4 of the covariance note split by the progression-free state (addendum of the covariance note) | Markov models: state probabilities, generator and transition matrices with nested adaptive quadrature over the PFS and OS times (ref_cross5.py); other models: Monte Carlo with 10 million patients |
| Rejection probabilities of two endpoints with recycling of the level (gs_prob_mtp() with upper_recycled, stage 3) | sums of rectangle probabilities over the outcomes at each analysis (.mtp_graph()) | numerical integration over the analyses of the joint density, with the decisions of Algorithm 1 of Maurer and Bretz (2013) applied on the sample path (canonical joint distribution, ref_graph.py); Monte Carlo simulation of the algorithm with 2 million trials |
| Number of events and sample size for a target power with recycling of the level or with switching from a calendar time (ms_size(), stage 3) | .solve_power() (doubling or halving, a grid of 8 points and uniroot()) on .design_core2() and .design_core() | one look: moments from the references above (expected_design.joint(), ref_calendar.Design.look()), rejection probabilities of the procedure with recycling as one-dimensional integrals of the bivariate normal density (adaptive quadrature), root finding (brentq) over the time of the look and the closed form of the sample size |
The influence-function derivation used in the R code was checked against the
formulas of Luo et al. (2019) in Python (function influence_cov() in
ref_logrank.py): for scenario B, the covariance at months 25 and 15 and the
variance at month 25 agree to about 1e-14 (results/alt_check.csv).
ref_model.py: multistate model of one group.ref_logrank.py: accrual, expected events, log-rank moments, Luo et al.
(2019) variance and covariance, and the influence-function check.ref_gsd.py: spending functions, bounds and stopping probabilities.expected_values.py: computes all expected values and writes
results/*.csv.ref_zeta.py: moments of the score, the observed variance and the event
indicator of one endpoint, products of the PFS and OS functionals in the
Fleischer model, and the covariance of the standardized statistics
(Planning/covariance_note in the project folder).expected_zeta.py: expected values for the studentized and PFS-OS
covariance, written to results/zeta_*.csv and read by the tests through
tests/testthat/helper-expected.R.ref_mtp.py: rejection probabilities of two endpoints under the
Bonferroni and fixed-sequence procedures (recursive integration, Monte
Carlo simulation and the formulas of Glimm et al. 2010 and Tamhane et
al. 2010; the last are also used by tools/reproduce_python.py in the
project folder).expected_mtp.py: expected values for gs_prob_mtp(), written to
results/gs_prob_mtp_configs.csv, results/gs_prob_mtp.csv and the Monte
Carlo check results/gs_prob_mtp_mc.csv.expected_design.py: expected values for ms_power() with two endpoints
and with looks driven by the events of PFS and OS (designs D1 to D4 of
tests/testthat/helper-designs.R), written to results/design2.csv, and
the Monte Carlo check of the rejection probabilities
results/design2_mc.csv (ref_mtp.simulate() with the mean vector and
covariance matrix of each design).expected_genz.py: exact probabilities of rectangles over both endpoints
for the tests of the Genz-Bretz algorithm in gs_prob_mtp()
(tests/testthat/test-pmvn_genz.R), by recursive conditioning and by
quasi-Monte Carlo with scrambled Sobol points, written to
results/pmvn_genz.csv.ref_markov.py: stopping probabilities for covariance matrices that need
not be Markov (exact recursion for Markov matrices; otherwise the exact
values for the Markov completion plus a quasi-Monte Carlo correction with
scrambled Sobol points), tensor-product Gauss-Legendre quadrature for at
most four looks, and bounds by alpha and beta spending. Also used by
tools/check_miwa_accuracy.py in the project folder.expected_pmvn.py: expected values for the tests of a covariance that is
not Markov (tests/testthat/helper-pmvn.R, design V2_K5_T2_alternative of
tools/miwa_accuracy.R), of a binding futility bound that reaches the
efficacy bound and of rectangles of 9 and 10 coordinates
(tests/testthat/test-pmvn.R), written to results/pmvn.csv.simulate_ms.py: patient-level simulation of the validation scenarios
V6-V10 (V9 and V10 with switch_clock = "switch" and switch_af),
written to ../results/sim_python.csv (see ../README.md).simulate_two.py: patient-level simulation of PFS and OS together in
the validation scenarios V3, V4, V6, V7, V11 and V12 (designs with two
endpoints, the Bonferroni procedure with and without recycling of the
level, per-patient covariances from 10 million patients for V3-V7; V11
and V12 with switching before progression and a censoring of PFS only,
generated by ref_model5.py), written to ../results/sim_python_two.csv
(see ../README.md).simulate_calendar.py: patient-level simulation of switching from a
calendar time (switch_start) in the validation scenarios V13-V15,
written to ../results/sim_python_calendar.csv (see ../README.md).simulate_type1.py: larger simulations of V2 and V7 under the null
hypothesis (V7, and scenario B with the group sizes of V2, exchanged and
equal), with the functions of simulate_ms.py, written to
../results/sim_python_type1.csv (see ../README.md).simulate_expected.py: patient-level simulation of the expected study
duration, events and enrolled patients when the trial stops at the
bounds (designs E1-E3 of version 0.4.0), with the functions of
simulate_ms.py, written to ../results/sim_python_expected.csv (see
../README.md).danzer_check.py: covariance estimator of Danzer et al. (2025) applied
to large simulated trials under the global null hypothesis, written to
../results/danzer_check.csv.ref_model5.py: multistate model of one group with the options of
stage 3 (switch_clock, switch_af, switch_pre, prog_switch,
death_switch_pre, dropout_pfs and pfs_switch), by adaptive
quadrature over the switch and progression times and, for Markov models,
by matrix exponentials; patient-level simulation of the model.ref_cross5.py: products of the PFS and OS functionals for Markov models
of ref_model5.py (state probabilities, generator and transition
matrices, nested adaptive quadrature).expected_model5.py: expected values for the tests of the options of
stage 3, written to results/model5_*.csv (models and scenarios of
models_s3(), model_post_s3() and scn_s3() in
tests/testthat/helper-scenarios.R), including the Monte Carlo check
results/model5_cross_mc.csv.ref_graph.py: rejection probabilities of two endpoints under the
graphical procedure with recycling of the level (Maurer and Bretz 2013,
Algorithm 1): recursive integration and Monte Carlo simulation of the
algorithm. Kept apart from ref_mtp.py, whose results are not changed.expected_graph.py: expected values for gs_prob_mtp() with
upper_recycled, written to results/gs_prob_graph_configs.csv,
results/gs_prob_graph.csv and the Monte Carlo check
results/gs_prob_graph_mc.csv; it also prints checks of the reference
(with the bounds after recycling equal to the initial bounds it equals
the Bonferroni procedure of ref_mtp.recursion(), and without a test of
the second hypothesis at its initial level the fixed sequence).ref_calendar.py: switching from a calendar time (switch_start of
ms_scenario(), stage 3). OS given the follow-up time from which
switching is possible by adaptive quadrature over the progression time
(with ref_model5.post()) and, for Markov models, by matrix
exponentials; group functions, per-patient moments and the covariance of
the per-patient functionals (equation (5) of the covariance note given
the entry time) by Gauss-Legendre rules over the whole entry range;
time derivatives by central differences; the closed form of the null
covariance (calendar-time switching note, equation (3)).expected_calendar.py: expected values for the tests of switch_start,
written to results/calendar_*.csv (scenario scn_cal() and models
model_post_cal() in tests/testthat/helper-scenarios.R); it also
prints checks of the reference (matrix exponentials against quadrature,
null correlation from the closed form against the moments).expected_size_stage3.py: expected values for the tests of ms_size()
with recycling of the level and with switching from a calendar time
(designs with one look in tests/testthat/test-ms_size.R), written to
results/size_stage3.csv; it also prints checks of the reference (the
rejection probabilities by ref_graph.recursion(), the moments at month
36 against results/calendar_looks.csv).expected_stage4.py: expected values for the tests of version 0.4.0:
the expected study duration, events and enrolled patients when the trial
stops at the bounds and the looks under the null scenario, for the designs
B, A_cal, D4, R_binding and R_nonbinding (defined in the docstring and in
tests/testthat/test-ms_power.R; R_binding and R_nonbinding are the design of
the rpact vignette on survival designs with fixed futility bounds),
written to results/expected_stage4.csv. Analysis times by root finding on
ref_logrank.events(), bounds and stopping probabilities by
ref_gsd.bounds() and ref_gsd.stop_probs(); for D4 the values under the
design scenario are those of results/design2.csv. It also writes the
conditional power of ms_cond_power() to results/cond_power_stage4.csv
(cases cm, B, S, M5 and G of the docstring, read by
tests/testthat/test-cond_moments.R, test-cond_probs.R and
test-ms_cond_power.R): the conditional moments from the independent
increments of the statistics or from the precision matrix, and the
probabilities of the later looks by ref_gsd.stop_probs(); the studentized
covariance of design S by ref_zeta.zeta_cov().python3 expected_values.py # all parts (about 30 minutes)
python3 expected_values.py gs power # selected parts
python3 expected_zeta.py # stage 2 moments (about 10 minutes)
python3 expected_mtp.py # rejection probabilities of two endpoints (about 2 minutes)
python3 expected_design.py # designs with two endpoints (about 30 minutes)
python3 expected_genz.py # rectangles over both endpoints (about 2 minutes)
python3 simulate_ms.py # validation scenarios V6-V8 (about 15 minutes)
python3 simulate_two.py # PFS and OS together, V3, V4, V6, V7 (about 30 minutes)
python3 danzer_check.py # estimator of Danzer et al. (2025) (about 2 minutes)
python3 simulate_type1.py # V2 and V7 under the null hypothesis (about 11 minutes)
python3 simulate_expected.py # expected values when the trial stops at the bounds, E1-E3 (about 4 minutes)
python3 expected_model5.py # model options of stage 3 (about 10 minutes)
python3 expected_graph.py # recycling of the level, stage 3 (about 4 minutes)
python3 expected_calendar.py # switching from a calendar time, stage 3 (about 4 minutes)
python3 expected_size_stage3.py # ms_size() with recycling and switching from a calendar time (about 2 minutes)
python3 expected_stage4.py # expected values and conditional power of version 0.4.0 (about 30 minutes)
python3 expected_stage4.py cond_power # conditional power only (about 25 minutes)
The results in results/ were computed with Python 3.13, numpy 2.5.3 and
scipy 1.18.1.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.