Which method?¶
Start from the question you are asking and from what you are willing to assume. Each row points to the procedure, says how exact its guarantee is, and names the tutorial that uses it.
"Exact" means: the error rate holds at every sample size and at any stopping time, under the stated assumptions. "Asymptotic" means it holds approximately in long runs.
Prefer an exact procedure. Where an exact procedure answers the question, it is the default here and in the tutorials. An asymptotic one is worth its approximation only when nothing exact fits: an unbounded metric with no variance bound, a ratio of sums, planned analyses of an approximately normal statistic.
Every procedure states its promise in its guarantee attribute
(sequential_analysis.core.GUARANTEES lists the values):
| Guarantee | Meaning | Procedures |
|---|---|---|
| exact | error rates, coverage or false-alarm rates hold at every sample size, under the stated assumptions | AnytimeLinearModel, AnytimeLogRankTest, BettingConfidenceSequence, BettingMeanTest, BoundedABTest, CatoniConfidenceSequence, ConformalForecast, CUSUM, ForecastComparison, GroupSequentialTest (known sigma), GroupSequentialTwoMeans (known sigma), KernelTwoSampleTest, MeanEDetector, MultipleTests, NormalMixtureSPRT, OnlineFDR, PlanTest, QuantileConfidenceSequence, QuantileEDetector, QuantileTest, RateRatioTest, SampleRatioMismatch, SequentialSignTest, ShiryaevRoberts, SPRT, TMixtureSPRT, TwoProportionTest, TwoSPRT |
| asymptotic | they hold approximately, the better the larger the sample | ABTest, AsymptoticConfidenceSequence, EventStudy, GroupSequentialLogRank, GroupSequentialMonitor, GroupSequentialProportions, GroupSequentialTest (estimated sigma), GroupSequentialTwoMeans (estimated sigma), RatioABTest |
| model | exact probabilities under the stated model and prior; no error rate beyond the model | AutoRegressive, BayesianChangePoint, DynamicRegression, ExponentialSmoothing, GARCH, HawkesProcess, HiddenMarkovFilter, KalmanFilter, LocalLevelKalman, ModelAveraging, PoissonSmoothing, ThompsonAllocation, VectorAutoRegressive |
| approximate | an approximation even under the model (Monte Carlo, variational, stochastic approximation) | BootstrapParticleFilter, OnlineHMM, ParticleFilter, RobustKalmanFilter |
| none | a transformation of the data; no inferential claim | CrossCorrelation, EMA, MeanDifference |
First: may you look at any time, or only at planned analyses?¶
| You want to | Use | What it costs |
|---|---|---|
| look after every observation and stop whenever the data are conclusive | an anytime-valid procedure (e-process, confidence sequence) | more data at the planned effect than a planned design: for two proportions, 1.3–1.6 times a single analysis |
| look a few times (a committee meets, a release cycle) | a group sequential design | an inflation factor of 1.01–1.2 over a single analysis; looking more often than planned is not allowed, but alpha spending lets the times move |
| test one simple hypothesis against another with the fewest observations on average | SPRT, TwoSPRT, or an optimal plan from kiefer_weiss_plan |
needs the distribution family and both parameter values |
Online experiments (A/B tests)¶
| Metric | Procedure | Guarantee | Tutorial |
|---|---|---|---|
| conversion (0/1) | TwoProportionTest |
exact, any n | A/B test |
| any bounded metric (share, capped revenue) | BoundedABTest |
exact confidence sequence for the difference | A/B test §6 |
| mean with a pre-experiment covariate (CUPED) | ABTest |
asymptotic | A/B test |
| several covariates, regression adjustment | AnytimeLinearModel |
exact under Gaussian errors | — |
| ratio metric (revenue per session, clicks per impression), relative lift | RatioABTest |
asymptotic, delta method on the randomised unit | A/B test §8 |
| events per unit of exposure | RateRatioTest |
exact for Poisson counts, robust to a drifting rate | A/B test §7 |
| median, 90th percentile of one group (a latency target) | QuantileTest, QuantileConfidenceSequence |
exact, no assumption on the distribution; one group only (a difference of two groups' medians is not covered yet) | — |
| "are A and B distributed the same at all?" | KernelTwoSampleTest |
exact | — |
| traffic split as intended? | SampleRatioMismatch |
exact | A/B test |
| many metrics or arms at once | MultipleTests (e-BH) |
false discovery rate at any stopping time | A/B test |
| a series of experiments decided one by one | OnlineFDR (e-LOND) |
false discovery rate over the series | programme |
| how long will it take, how much power? | planning.simulate |
simulation | A/B test §9 |
| send more traffic to the better arm during the test | ThompsonAllocation (shares, expected-loss deployment rule); test with TwoProportionTest(method="universal") or BoundedABTest(propensity_input=...) |
the rule bounds expected loss; those tests stay exact under any split | A/B test §10 |
Clinical trials¶
| Endpoint | Planned analyses | Monitored after every event |
|---|---|---|
| normal mean, one sample or paired | GroupSequentialTest (known or estimated variance) |
NormalMixtureSPRT, TMixtureSPRT |
| continuous endpoint, two arms | GroupSequentialTwoMeans (known or estimated variance) |
AnytimeLinearModel with the arm as the tested covariate |
| two proportions (response rate) | GroupSequentialProportions |
TwoProportionTest |
| time to event | GroupSequentialLogRank (stratified if needed) |
AnytimeLogRankTest (stratified if needed) |
| any statistic you compute (Cox model, mixed model) | GroupSequentialMonitor (Z and information per analysis) |
— |
For the design itself, use group_sequential_design, which gives:
- efficacy and non-binding futility boundaries;
- power and expected sample size;
- maximum sample sizes for means and proportions, and the number of events.
design.at(...) recomputes the boundaries when the analyses do not
happen as planned. The boundaries and sample sizes agree with rpact
(tutorial §8).
Two cautions:
- Late entry with time-dependent hazards. The anytime-valid log-rank test needs proportional hazards on the time scale of the records. With staggered entry and hazards that depend on time since entry, stratify by entry cohort or use the group sequential test. The survival tutorial has the numbers.
- Small trials. With few patients, the normal approximations of the group sequential statistics are approximate. The tests simulate the level at the sizes the designs give.
Monitoring a process¶
| Situation | Procedure | Guarantee |
|---|---|---|
| known distribution before and after the change | CUSUM, ShiryaevRoberts |
optimal detection delay for the chosen alternative |
| only the mean or a quantile before the change is known | MeanEDetector, QuantileEDetector |
average run length to a false alarm at least the target, for every distribution |
| unknown parameters, several changes, a posterior wanted | BayesianChangePoint |
Bayesian; sensitive to the model |
The monitoring tutorial compares them on the same data.
Tracking a hidden state¶
| Model | Procedure |
|---|---|
| linear Gaussian (trends, autoregressions, tracking) | KalmanFilter; outliers: RobustKalmanFilter |
| a few hidden regimes, model known | HiddenMarkovFilter |
| a few hidden regimes, parameters to learn | fit_hmm on a history, or OnlineHMM on the stream (tutorial) |
| anything you can simulate | ParticleFilter |
| smoothing after the fact | sequential_analysis.smoothing |
Forecasting¶
| Situation | Procedure |
|---|---|
| a history to fit, the process stable | fit_ets (level, trend, season) or fit_ar, then forecast with the fitted model |
| no history, or a process that changes | averaged_smoothing (learns the smoothing parameters), AutoRegressive without coefficients, with forgetting below 1 to follow drift |
| known drivers: promotions, holidays, prices | regressors= on any of them |
| counts (orders, calls, incidents) | fit_counts or averaged_counts (PoissonSmoothing) |
| growth, swings proportional to the level | transform="log" |
| several candidate models | ModelAveraging |
| intervals that must hold whatever the data | ConformalForecast around any of them |
| is one forecaster better than another? | ForecastComparison, valid at every time |
The forecasting tutorial runs both kinds of training on the same data, before and after a change.
Several series and event streams¶
| Question | Procedure | Guarantee |
|---|---|---|
| which series leads, by how many steps? | CrossCorrelation (correlations at lags -L..L, with forgetting) |
descriptive |
| does x's past improve the forecast of y? (Granger) | Lagged around AnytimeLinearModel; many pairs or lags: OnlineFDR |
exact under the regression model |
| forecast several series together | fit_var on a history, VectorAutoRegressive on the stream |
under the model |
| a hedge ratio or beta that drifts, the spread of a pair | DynamicRegression |
under the model |
| has a relationship broken? | QuantileEDetector or MeanEDetector on the spread or the residuals |
approximate when they are autocorrelated |
| events in bursts (news, trades, alerts) | fit_hawkes, HawkesProcess; a change of the flow: an e-detector on its compensators |
under the model |
| attach irregular events to regular bars without look-ahead | the AsOfJoin topology |
— |
| how does a series move after events? | EventStudy |
asymptotic |
| volatility, value at risk | fit_garch on a history, then GARCH (normal or Student t, optional leverage) |
under the model; agrees with arch |
Tutorials: several series, a news stream, volatility.
Means of data that are not normal¶
- Bounded data:
BettingConfidenceSequence, exact. - A known bound on the standard deviation:
CatoniConfidenceSequence, exact. - Anything else:
AsymptoticConfidenceSequence, which is valid only approximately and in long runs. No method can guarantee coverage of the mean of arbitrary unbounded data. - The median or another quantile: the quantile procedures, which assume nothing about the distribution.