Sequential tests¶
sequential_analysis.procedures.sprt
¶
sequential_analysis.procedures.two_sprt
¶
Lorden's 2-SPRT for the Kiefer-Weiss problem.
The Kiefer-Weiss problem asks for the test of theta0 against theta1 that, subject to error probabilities alpha0 and alpha1, minimizes the maximum expected sample size over theta. The SPRT is optimal at theta0 and theta1 but can be slow in between. The 2-SPRT runs two one-sided SPRTs against an intermediate point theta*:
L0_n = sum_i log f_{theta*}(X_i) / f_{theta0}(X_i) reject H0 when L0_n >= a0
L1_n = sum_i log f_{theta*}(X_i) / f_{theta1}(X_i) accept H0 when L1_n >= a1
and stops at the first n at which either boundary is reached. Under
theta_i, exp(Li_n) is a non-negative martingale with mean one, so by
Ville's inequality the wrong decision has probability at most exp(-a_i).
The default thresholds a_i = log(1/alpha_i) therefore guarantee the error
rates, conservatively. Explicit thresholds=(a0, a1) can be passed when
they have been calibrated to attain the error rates more tightly.
TwoSPRT
¶
Bases: Procedure
max_sample_size()
¶
Largest possible stopping time, where one is known in closed form.
For Gaussian observations the continuation region is a triangle in the (n, sum) plane, so the test is closed: it always stops by
n_max = ceil( 2 sigma^2 (a0/d0 + a1/d1) / (d0 + d1) ),
with d_i = |theta* - theta_i|.
as_plan()
¶
The same test written as a sampling plan on the running sum S_n.
For Gaussian observations and theta0 < theta1 the two boundaries are straight lines in the (n, S_n) plane,
reject H0 when S_n >= a0 sigma^2 / d0 + n (theta* + theta0) / 2
accept H0 when S_n <= n (theta* + theta1) / 2 - a1 sigma^2 / d1,
and the plan ends at the first step at which they meet. The result
can be executed by PlanTest and is used to validate it.
kiefer_weiss_point(family, theta0, theta1, a0, a1)
¶
Intermediate point at which both boundaries are reached at the same rate.
Solves a0 / KL(theta, theta0) = a1 / KL(theta, theta1) on (theta0, theta1) by bisection. This is the first-order choice of theta*; see Lorden (1976) and Huffman (1983) for refinements.
sequential_analysis.procedures.plan
¶
Execute a precomputed sequential sampling plan.
Optimal sequential tests, such as the numerical solutions of the Kiefer-Weiss problem by Novikov, Novikov and Farkhshatov, are computed offline by backward induction. Their result is a plan: for every step n = 1, ..., H an interval of the running sum S_n in which sampling continues. Computing the plan is a design problem. Executing it on a stream is a Sequential Procedure, and that is all this class does.
Plan format¶
continuation[n-1] = (lower_n, upper_n) for n = 1, ..., H.
S_n <= lower_n stop and accept H0
S_n >= upper_n stop and reject H0
otherwise continue
The acceptance side is checked first. None means "no boundary on this
side at this step". The last step must force a decision, so it needs
lower_H >= upper_H; the usual choice (c, c) reads "accept H0 if
S_H <= c, otherwise reject". With reject_high=False the two decisions
are swapped, for problems in which large sums favour H0.
Boundary conventions (open or closed ends) differ between design codes. Check them against the code that produced the plan; for integer-valued data, shift a boundary by one where necessary.
sequential_analysis.procedures.families
¶
One-parameter likelihood families used by the likelihood-ratio procedures.
A family provides the log likelihood ratio of one observation, the
Kullback-Leibler divergence, a parameter check and the input contract.
Gaussian (known variance), Bernoulli, Poisson and Exponential are
exponential families: the sum of the observations is sufficient, which is
what sequential_analysis.design relies on.
sequential_analysis.procedures.group_sequential
¶
Execute a group sequential test of a normal mean on a stream.
Observations arrive one at a time; the test looks at them only at the planned analyses n_1 < ... < n_K. At analysis k it computes
Z_k = (mean_k - theta0) sqrt(n_k) / sigma
and stops for efficacy (rejects H0) if Z_k >= c_k, or |Z_k| >= c_k for
a two-sided design. With futility boundaries f_k it stops and accepts H0
if Z_k <= f_k. If no boundary is crossed by n_K, H0 is accepted (not
rejected). The boundaries come from sequential_analysis.group_sequential.
With sigma=None the variance is estimated at each analysis and Z_k is
replaced by the t statistic, compared with the boundary of the same
one-sided significance level, t_{n_k - 1}^{-1}(Phi(c_k)) -- the
significance-level approach of Jennison and Turnbull (2000, sec. 11.4).
The type I error is then approximately, not exactly, the design's.
The schedule is fixed in advance. If analyses happen at other sample sizes than planned, the boundaries must be recomputed for the actual information fractions, which is what alpha spending allows: build a new design with the realised fractions before the next analysis.
GroupSequentialTest
¶
Bases: Procedure
guarantee
property
¶
Exact with a known sigma; with an estimated one the t boundaries are approximate.
from_design(design, n_max, sigma, theta0=0.0, **kwargs)
classmethod
¶
Analyses at the design's information fractions of n_max (rounded up).
bound_at(k)
¶
Efficacy boundary for the statistic at analysis k (0-based).
GroupSequentialMonitor
¶
Bases: Procedure
Alpha spending at the information actually reached, for any endpoint (Lan and DeMets 1983).
Each input is one analysis: the standardised statistic Z_k and the
information I_k it is based on (for a difference of means
1 / Var(estimate); for a log-rank statistic its variance, about
events / 4 with 1:1 allocation; any statistic whose increments are
approximately independent with Var Z_k sqrt(I_k) = I_k). The
boundary of analysis k is computed when it happens, from the spending
function at t_k = I_k / max_information and the boundaries already
used, so analyses need not be planned: a data monitoring committee can
meet when it meets. The analysis is final when I_k reaches
max_information, when max_analyses is reached, or when the record
says so (final_input, if given); the final analysis spends all the
alpha left (under- and over-running). Boundaries are those of
GroupSequentialDesign.at, which the tests check against rpact.
Futility boundaries (one-sided only) need the beta-spending function,
the design's drift theta sqrt(I_max) and its power: give them, or use
from_design. They are non-binding, as in the design.
Cost per analysis: a recursive numerical integration over the
analyses so far, finer when they are close together: with twelve
equally spaced analyses, 80 ms at the fourth and 0.7 s at the
eleventh (CPython, PERFORMANCE.md); a grid of more than 20,000 points
is refused (NumericalError). The state grows by three numbers per
analysis, at most max_analyses.
from_design(design, max_information, **kwargs)
classmethod
¶
The monitor of a design: its alpha, spending functions, sidedness and, with futility, power and drift.
boundaries(fractions, final=True)
¶
Efficacy and futility boundaries for analyses at these fractions; the last one final or not.
Futility boundaries are empty without a beta-spending function.
GroupSequentialProportions
¶
Bases: _TwoArmGroupSequential
Group sequential comparison of two proportions (conversion, response, adverse event rates).
Each input is one unit: its arm and its binary outcome. At analysis k (after n_k units of both arms together) the pooled two-proportion statistic
Z_k = (p_T - p_C) / sqrt(p (1 - p) (1/n_T + 1/n_C)), p the pooled rate,
(whose square is the chi-square test without continuity correction)
is compared with the boundary: alternative="greater" rejects for large
p_T - p_C, "less" for small (Z is then computed with the sign
reversed); a two-sided design compares |Z|. While an arm is empty or
every outcome so far is the same, Z = 0. Units of other arms are
ignored. Boundaries come from a design (from_design, which also
recomputes them for analyses at other counts than planned) or are
given; GroupSequentialDesign.max_sample_size_two_proportions gives
the maximum sample size. The type I error is that of the normal
approximation: close to the design's for the sample sizes such
designs give (simulated in the tests).
Cost per step: a few additions; at an analysis a square root. The state is six numbers.
from_design(design, n_max, *, analyses=None, **kwargs)
classmethod
¶
Analyses at the design's fractions of n_max units, or at the counts analyses (boundaries recomputed).
GroupSequentialTwoMeans
¶
Bases: _TwoArmGroupSequential
Group sequential comparison of two means: the most common trial, a continuous endpoint in two arms.
Each input is one unit: its arm and its outcome. At analysis k (after n_k units of both arms together)
Z_k = (mean_T - mean_C) / (sigma sqrt(1/n_T + 1/n_C))
with a known sigma; with sigma=None the pooled two-sample t
statistic (Student's, n - 2 degrees of freedom; checked against R's
t.test in the tests) is compared with the boundary of the same
one-sided significance level, as GroupSequentialTest does for one
mean (Jennison and Turnbull 2000, sec. 11.4: approximately the
design's type I error). alternative="greater" rejects for a large
mean_T - mean_C, "less" for a small one; a two-sided design compares
|Z|. While an arm is empty (or, with an estimated variance, fewer
than three units are in), Z = 0. Units of other arms are ignored.
GroupSequentialDesign.max_sample_size_two_means gives the maximum
sample size.
Cost per step: a Welford update; the state is eight numbers.
guarantee
property
¶
Exact with a known sigma; with an estimated one the t boundaries are approximate.
from_design(design, n_max, sigma, *, analyses=None, **kwargs)
classmethod
¶
Analyses at the design's fractions of n_max units, or at the counts analyses (boundaries recomputed).
bound_at(k)
¶
Efficacy boundary for the statistic at analysis k (0-based).
GroupSequentialLogRank
¶
Bases: _TwoArmGroupSequential
Group sequential log-rank test, with analyses after given numbers of events.
The input is the stream of AnytimeLogRankTest: each record a patient's arm and what happened (0 enters the risk set, 1 has the event, 2 leaves without one), in the order it happened. At each event, with n_T and n_C at risk (in the event's stratum), p = n_T / (n_T + n_C) is added to E and p (1 - p) to V; O counts the events in the treatment arm. At analysis k (after d_k events)
Z_k = (E - O) / sqrt(V)
for alternative="less" (the treatment lowers the hazard; Z positive
when it has fewer events than expected), (O - E) / sqrt(V) for
"greater"; a two-sided design compares |Z|. This is the log-rank
statistic (the score test of a Cox model with the arm as covariate,
late entry handled as left truncation; checked against R's survival
package in the tests), analysed at event counts as is usual
(information fraction d_k / d_max). With strata > 1 each record
carries its stratum and E, V are summed within strata: the stratified
log-rank test. Events with nobody at risk in the other arm add
nothing. Records of other arms are ignored. Tied events are taken
one at a time in arrival order (a slightly larger V than Breslow's
tie correction).
GroupSequentialDesign.max_events gives the maximum number of events
(Schoenfeld). Cost per step: a few additions; the state is 2 per
stratum plus five numbers.
from_design(design, max_events, *, analyses=None, **kwargs)
classmethod
¶
Analyses at the design's fractions of max_events, or at the event counts analyses.
sequential_analysis.group_sequential
¶
Group sequential designs with alpha spending (Lan and DeMets 1983).
A trial is analysed K times, at information fractions 0 < t_1 < ... < t_K = 1 (for a normal mean with known variance, t_k = n_k / n_K). At analysis k the standardised statistic Z_k is compared with an efficacy boundary c_k; the trial stops for efficacy the first time Z_k >= c_k (or |Z_k| >= c_k for a two-sided test). A spending function alpha(t) says how much of the type I error may be used up by information t; the boundaries are chosen so that, under H0,
P(first crossing at analysis k) = alpha(t_k) - alpha(t_{k-1}).
Under H0 the score process B(t) = Z(t) sqrt(t) is a Brownian motion, so these probabilities are computed by recursive numerical integration of its sub-density on the continuation region (Armitage, McPherson and Rowe 1969; Jennison and Turnbull 2000, ch. 19), here with Simpson's rule. The same recursion with a drift gives power and expected sample size.
Spending functions (one-sided level a; a two-sided test spends a/2 on each side):
"obrien-fleming" 2 - 2 Phi(Phi^-1(1 - a/2) / sqrt(t)) (Lan-DeMets)
"pocock" a log(1 + (e - 1) t) (Lan-DeMets)
("power", rho) a t^rho (Kim-DeMets)
a callable t -> cumulative alpha, with f(1) = a
GroupSequentialDesign
dataclass
¶
crossing(drift=0.0, points_per_sd=24, *, binding=True)
¶
P(stop for efficacy at analysis k), with Z(t) sqrt(t) drifting at drift per unit information.
With futility boundaries, binding=True assumes the trial stops when
it crosses one; binding=False ignores them, which is how the type I
error of a non-binding design is controlled.
futility_crossing(drift=0.0, points_per_sd=24)
¶
P(stop for futility at analysis k); zeros without futility boundaries.
power(drift)
¶
P(reject H0) at this drift; for a two-sided design, P(reject in the direction of the drift).
A two-sided trial that stops for the wrong sign has not shown the
effect it was powered for; rpact and gsDesign count power the same
way. sum(crossing(drift)) counts both sides.
expected_fraction(drift)
¶
Expected information at stopping, as a fraction of the maximum (futility obeyed).
drift_for_power(power)
¶
Drift theta * sqrt(I_max) at which the design has the given power.
Solved for probit(power(drift)) = probit(power), which is nearly linear in the drift (exactly, for a single analysis), by the Illinois method: a few evaluations of the power instead of fifty.
inflation_factor(power=None)
¶
Maximum information over the information of a single-analysis test with the same alpha and power.
For a fixed-sample design the factor is 1; the sample sizes below are the fixed-sample ones multiplied by it (as rpact and gsDesign do).
max_sample_size(effect, sigma, power=None)
¶
Smallest maximum sample size for a normal mean: I_max = n / sigma^2, drift = effect sqrt(I_max).
A design with futility boundaries was built for one power; leave
power out to use it.
max_sample_size_two_means(effect, sigma, allocation=0.5, power=None)
¶
Total maximum sample size to compare two normal means (known sigma, normal approximation).
allocation is the share of the treatment arm. The information on
the difference is n a (1 - a) / sigma^2.
max_sample_size_two_proportions(p_control, p_treatment, allocation=0.5, power=None)
¶
Total maximum sample size to compare two proportions (normal approximation).
The fixed-sample size uses the pooled variance under H0 and the unpooled one under the alternative,
n = (z_a sqrt(p (1 - p) (1/a + 1/(1 - a))) + z_b sqrt(p_T q_T / a + p_C q_C / (1 - a)))^2 / (p_T - p_C)^2,
p = a p_T + (1 - a) p_C, and is multiplied by the inflation factor: the method of rpact's getSampleSizeRates (checked against it in the tests).
max_events(hazard_ratio, allocation=0.5, power=None)
¶
Maximum number of events for a log-rank test (Schoenfeld 1981).
The information of the log-rank statistic is about D a (1 - a) after D events, so D_max = drift^2 / (a (1 - a) log(HR)^2). The number of patients and the follow-up needed to observe them depend on accrual and on the baseline hazard, which this does not model.
at(fractions)
¶
The design recomputed for the analyses actually done, at these information fractions.
This is what alpha spending is for (Lan and DeMets 1983): the analyses need not happen when planned. The fractions are realised information over the planned maximum; the last one is the final analysis, which spends all the alpha left, also when it comes before (under-running) or after (over-running) the planned maximum. A boundary depends only on the analyses up to its own, so the boundaries of analyses already done do not change when later ones move. Futility boundaries keep the drift the design was built for, and the last one equals the last efficacy boundary.
spending_function(kind, alpha)
¶
Cumulative alpha spent by information fraction t, for one side.
group_sequential_design(alpha, fractions, spending='obrien-fleming', *, two_sided=False, futility=None, power=None, points_per_sd=24)
¶
Efficacy boundaries, and optionally futility boundaries, for K analyses.
alpha is the overall type I error: one-sided, or the total of both
sides when two_sided (then each side spends alpha/2).
futility is a spending function for beta = 1 - power (same forms as
spending); it requires power and a one-sided design. Futility
boundaries are non-binding: the efficacy boundaries are computed as if
they did not exist, so the type I error stays at most alpha whether or
not a trial stops when it crosses one. The design's drift is chosen
so that, with futility obeyed, the power is exactly power and the
two boundaries meet at the last analysis (Pampallona and Tsiatis 1994;
the "non-binding" designs of gsDesign and rpact, against which the
boundaries are checked in the tests).
sequential_analysis.procedures.survival
¶
Anytime-valid log-rank test for two-arm survival data (ter Schure, Pérez-Ortiz, Ly and Grünwald 2024).
The input is the stream of what happens to the patients of a trial, in the order it happens: a patient enters the risk set (kind 0), has the event (kind 1: death, failure) or leaves it without one (kind 2: censored, lost to follow-up). The procedure keeps n_T and n_C, the numbers at risk in the treatment and control arms. Under proportional hazards with hazard ratio theta (treatment over control), an event that happens when n_T and n_C patients are at risk is in the treatment arm with probability
p_theta = n_T theta / (n_T theta + n_C),
whatever the baseline hazard (Cox's partial likelihood). So under H0: theta = theta0 each event's arm is a Bernoulli(p_theta0) variable given the past, and for any alternative theta1 = theta0 exp(delta) chosen before the event the likelihood ratio
LR_t(delta) = exp(x_t delta) (n_T theta0 + n_C) / (n_T theta0 exp(delta) + n_C),
x_t = 1 for an event in the treatment arm and 0 in the control arm, has conditional mean exactly 1 under H0. Products of such factors are test martingales, and Ville's inequality makes rejecting at E >= 1/alpha a level-alpha test at any stopping time: the trial may be monitored after every event, stopped or extended at will, with no maximum number of events. No assumption is made on the baseline hazard, on censoring or on entry beyond their being non-informative: given the past, who enters and who is censored does not depend on the arms of future events.
Time scale. Risk sets are those of the order the records arrive in. Validity needs proportional hazards on that time scale -- the calendar time of the trial when records are streamed as they happen; a patient who enters late is then left-truncated, which the partial likelihood handles exactly. If instead the hazards are a function of time since entry and they are not constant, staggered entry breaks the martingale property (the paper says so too), and not by a little. By simulation (200 patients entering uniformly over 25 scale units, 1:1, a Weibull hazard of shape 0.3 in time since entry with scale 1, exponential censoring at rate 0.3 after entry, the default mixture, alpha = 0.05), the test rejects a true H0 in 21% of 4000 trials (25% of 800 with censoring at rate 0.05; shape 0.5: 14% of 2000; shape 2: none of 2000), where an exact analysis of the same kind of trial, records in time since entry, rejects 1.7% of 2000. The events of patients who entered recently then tell which arm they are in more often than n_T / (n_T + n_C) says. Exponential (constant) hazards are the same on both time scales and are fine. With hazards in time since entry, stream the records in that time scale (possible only after the fact) or stratify by narrow entry cohorts (next paragraph), which brings the same trials back under the level.
Stratification (strata > 1). Each record also names its stratum s -- a centre, a prognostic group, an entry cohort -- and the procedure keeps n_T^s and n_C^s, the numbers at risk of each arm in each stratum. Under proportional hazards within strata (a baseline hazard of any shape in each stratum, one hazard ratio theta common to all), an event in stratum s is in the treatment arm with probability n_T^s theta / (n_T^s theta + n_C^s): the stratified partial likelihood. LR_t is the factor above with n_T^s and n_C^s in place of n_T and n_C, its conditional mean under H0 is still exactly 1, and the products over the events of all strata, in arrival order, are test martingales: the methods, the one-sided composite nulls and the confidence sequence carry over unchanged, and the estimate is the (penalised) stratified Cox estimate. An event in a stratum with one arm empty is certain: factor 1. By simulation (exponential hazards, 200 patients, 600 trials, alpha = 0.05): in three centres with hazards 0.2, 1 and 5 randomising 1:3, 1:1 and 3:1, the unstratified test rejects a true H0 in 96% of trials and the stratified one in 2.5%; in two centres with hazards 0.1 and 10 randomising 1:1 (400 patients), power at a hazard ratio of 0.6 is 18% unstratified and 82% stratified.
Entry cohorts are an approximation: within a cohort, entry still varies, so the cohorts must be narrow compared with the time over which the hazard changes after entry. In the shape-0.3 simulation above (4000 trials; cohorts are equal periods of entry), the rejection rate of a true H0 is 21% unstratified, 20% with 2 cohorts, 16% with 4, 11% with 8, 5.8% with 16, 3.8% with 25 (one scale unit each, 8 patients on average) and 1.5% with 50. Narrow cohorts cost power, since an event in a cohort with one arm empty carries no information: at a hazard ratio of 0.6, 39% with 25 cohorts and 21% with 50 (1000 trials), against 54% for the exact analysis in time since entry (2000 trials).
With strata = 1, the default, the inputs, the configuration and the state
are exactly those of the unstratified test: the configuration names
strata and stratum_input only when strata > 1, so the identity,
checkpoints and conformance vectors of earlier releases are unchanged.
The state's at_risk holds n_T^0, n_C^0, n_T^1, n_C^1, ... (two numbers
per stratum); the output's at_risk is the total of each arm.
Ties. Events are processed one at a time in arrival order, each removed from the risk set before the next. Tied events should be streamed in an order that does not depend on their arms (random, say); under H0: theta = 1 the test is then exact.
Alternatives. "less" means theta < theta0 (with events as deaths: the treatment is better), "greater" theta > theta0, "two-sided" either.
method="mixture" (default): E_n = sum_j w_j prod_t LR_t(delta_j), a
discrete normal prior on delta = log(theta / theta0) with standard
deviation prior_sd (tau): delta_j = j tau / 8 for 0 < |j| <= 32
(so up to 4 tau), w_j proportional to exp(-delta_j^2 / (2 tau^2)),
restricted to delta_j < 0 for "less" and delta_j > 0 for "greater"
and normalised. A finite mixture of test martingales is one. The
normal prior is Robbins' method of mixtures; in the normal
approximation of the log-rank statistic it is tightest at about
32 / tau^2 events for alpha = 0.05 with 1:1 allocation (128 for the
default tau = 0.5, about the number a fixed-sample test needs for a
hazard ratio of 0.6). It is not the paper's own prior (the paper
mainly uses a point alternative or virtual data points).
method="grow": E_n = prod_t LR_t(d_t), with d_t the plug-in estimate of delta from the events before t (predictable): the maximiser of the partial log-likelihood plus the log-density of the N(0, tau^2) prior, found on the grid delta_j above and refined by a parabola through the best grid point and its neighbours. For a one-sided test an estimate on the null side is not bet on (d_t = 0, factor 1).
For one-sided tests every factor has conditional mean at most 1 for every theta on the null side (for "less": E_theta LR(delta) decreases in theta when delta < 0), so the e-process is valid for the composite null.
hazard_ratio_estimate is theta0 exp(d), d the (unrestricted) plug-in
estimate after the latest event: the partial-likelihood estimate, shrunk
towards theta0 by the prior.
Confidence sequence (confidence_sequence=True). The two-sided mixture is
inverted over a grid of cs_grid hazard ratios theta_i log-spaced over
cs_range (default 101 points over [1/10, 10], step h = log(100)/100):
theta_i is excluded once
E_n(theta_i) = sum_j w'_j exp(l_n(b_i + m_j) - l_n(b_i)) >= 1/alpha,
with l_n(b) the partial log-likelihood at log hazard ratio b and m_j the
offsets of the same normal prior, on multiples of h so that every
b_i + m_j is a point of one grid. The state holds l_n on that grid (the
CS grid widened by 4 tau on each side), which is all the mixtures need:
constant memory, and one log per grid point per event. Excluded points
are never evaluated again (the sequence is intersected over time); the
interval spans the points not excluded, widened by one grid step on each
side. lower (upper) is None while the end of the grid is not excluded:
the data do not yet bound the ratio within cs_range. For every grid
point theta_i, P(theta_i is ever excluded | theta = theta_i) <= alpha;
between grid points the one-step widening is the same approximation as
in BettingConfidenceSequence. If every point is excluded (a <= alpha
event, or the true ratio lies outside cs_range) the interval collapses to
the least-excluded point and its neighbours. The interval is two-sided
at level alpha, whatever alternative.
Cost per event (CPython, default grids): 65 logarithms for the test, 40 to 55 µs; with the confidence sequence also 187 logarithms and exponentials and a convolution of the points still in the interval with 86 prior weights (8 700 multiply-adds at the start, falling as the interval narrows): 0.6 ms for the first events, 0.2 ms once the interval is narrow. Entries and censorings cost a few µs. The state is constant: 252 floats with the default grids (5 kB of JSON; 1.5 kB without the confidence sequence), and two integers per stratum. 25 strata do not change the cost measurably; 1000 strata about double the cost of an entry or censoring (the output sums the numbers at risk over the strata).
AnytimeLogRankTest
¶
Bases: Procedure
Anytime-valid log-rank test and confidence sequence for a hazard ratio; see the module docstring.
Inputs: the arm of the record (arm_input, an integer label) and its
kind (input): 0 = the patient enters the risk set, 1 = event,
2 = censored. arms = (treatment label, control label); records of
other arms are ignored. An event or censoring in an arm with nobody
at risk is a contract violation. theta0 is the null hazard ratio
(treatment over control); alternative "less" tests H0: theta >= theta0
against theta < theta0. prior_sd is the standard deviation of the
normal prior on log(theta / theta0) (method="mixture" and the
confidence sequence) and of the shrinkage of the plug-in estimate.
strata > 1 makes the test stratified (see "Stratification" in the
module docstring): every record then also carries its stratum
(stratum_input, an integer in 0..strata-1), the state keeps the
numbers at risk of each arm in each stratum, and an event or censoring
in an arm of a stratum with nobody at risk is a contract violation.
The output's at_risk is the total over the strata. With the default
strata=1 the procedure, its inputs, its configuration and its state
are exactly those of the unstratified test (the configuration names
strata and stratum_input only when strata > 1), so earlier
checkpoints restore unchanged.