BCompare groups · Guide test 289
Wald sequential probability ratio test
Accumulates a likelihood ratio until a prespecified acceptance or rejection boundary is reached.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Sequential probability ratio tests — Wald SPRT, MaxSPRT and conditional MaxSPRT — Can I decide after every observation (or event) while keeping the planned error rates?
In Sequential probability ratio tests — Wald SPRT, MaxSPRT and conditional MaxSPRT, choose Test = Wald SPRT (simple H₀ vs simple H₁).
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Wald sequential probability ratio test
Wald's truncation: decide by the sign of the log-LR if no boundary is reached.
Your data
Observations arrive one at a timeEach observation adds log(p₁/p₀) for a success or log((1 − p₁)/(1 − p₀)) for a failure; the test stops at the first boundary it touches.
If H₀ were true
- The reference: how Λ varies across samples when H₀ is true, the log-LR at stopping under H₀ (exact) (exact: every path to a boundary or the truncation point, ordered by its log-LR).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .017).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- Bernoulli likelihoods under p₀ and p₁
- Wald's boundaries for target error rates α and β (approximate because of overshoot)
- the exact probability under H₀ of stopping with a log-LR at least this large
The verdict
Λ = 2.95, p = .017
p ≤ α = .050: reject H₀
Uses on average far fewer observations than a fixed-n test, but only the first crossing counts; testing again after it is repeated testing.
- Statistic
- 2.955
- p-value
- 0.0171
Wald sequential probability ratio test on 60 yes/no outcomes in order: Λ = 2.95, p = .017. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: observations follow f0; H1: they follow the specified f1.
Assumptions
Sequential observations with known conditional likelihoods; simple hypotheses for the classic SPRT; a prespecified stopping rule.
Formula
Parameters and notation
α,β target type I/II errors. Stop for H1 if Λn≥A, for H0 if Λn≤B, otherwise continue.
Structure of the method
Update the cumulative log likelihood ratio for every observation and stop at the first crossing of lower or upper boundaries. The classic construction compares two specified distributions, with Wald’s approximate boundaries derived from target type I and II errors; truncation adds a terminal decision problem.
Estimated and nuisance parameters
Under simple hypotheses, distribution parameters such as Bernoulli p0 and p1 are fixed, not estimated online. The cumulative likelihood ratio and stopping time are computed state. Replacing a fixed alternative by its running maximum produces a different generalized/sequential test requiring different calibration.
Settings and design choices
Choose p0/p1 or other simple models, alpha, beta, observation schedule and maximum horizon before monitoring. Define what happens if neither boundary is crossed by the horizon. In discrete problems, boundary overshoot means nominal Wald approximations need assessment or exact calibration.
Fitting and adaptation
No neural fine-tuning applies. For a new outcome model, derive valid conditional likelihood increments and calibrate boundaries under the intended sampling/stopping protocol. A simulation study can estimate actual error rates and expected sample size under both hypotheses and scientifically relevant intermediate effects.
Sensitivity and robustness
Dependence, model drift and misspecified likelihoods invalidate the independent Bernoulli illustration. Accept H0 is a decision relative to the specified alternative and error design, not proof that every other effect is absent. Do not repeatedly restart after unfavorable paths or add unplanned analyses without adjusting the sequential procedure.
How to use and calibrate
Use exact or calibrated boundaries when discrete overshoot matters; truncated designs require terminal rules.
Example application
Monitor accumulating evidence while controlling errors under the planned sequential design.
Interpretation and pitfalls
Watch out
Repeated fixed-sample p-value testing is not SPRT. Composite hypotheses and nuisance fitting need another justified construction.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Simple Bernoulli p0=.5 versus p1=.7 SPRT; Wald boundaries approximate requested error rates because of overshoot. Analyze only the first crossing; this is not repeated fixed-sample testing.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
p0=.5;p1=.7;alpha=.05;beta=.2;lower=np.log(beta/(1-alpha));upper=np.log((1-beta)/alpha)
x=rng.binomial(1,p1,500);llr=np.cumsum(x*np.log(p1/p0)+(1-x)*np.log((1-p1)/(1-p0)))
hit=np.flatnonzero((llr<=lower)|(llr>=upper))
if len(hit):
j=hit[0];print(j+1,llr[j],"Reject H0" if llr[j]>=upper else "Accept H0")
else:print("No crossing by 500; continue or follow a prespecified truncation rule")
Output
24 2.9915465165858897 Reject H0
Validated — Executed successfully in the validation environment · needs Base/standard library
set.seed(2026)
p0<-.5;p1<-.7;alpha<-.05;beta<-.2;lower<-log(beta/(1-alpha));upper<-log((1-beta)/alpha)
x<-rbinom(500,1,p1);llr<-cumsum(x*log(p1/p0)+(1-x)*log((1-p1)/(1-p0)))
hit<-which(llr<=lower|llr>=upper)
if(length(hit)) {t<-hit[1];print(c(n=t,logLR=llr[t]));print(if(llr[t]>=upper) "Reject H0" else "Accept H0")} else print("No boundary crossed by 500; continue or use a prespecified truncation rule")
Output
n logLR 11.000000 2.853897 [1] "Reject H0"
Sources
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 289, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT289.