Skip to content

BCompare groups · Guide test 289

Wald sequential probability ratio test

Accumulates a likelihood ratio until a prespecified acceptance or rejection boundary is reached.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

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

60

Wald's truncation: decide by the sign of the log-LR if no boundary is reached.

0.65
0.50
0.70
0.80
0.050

Your data

Observations arrive one at a time
reject H₀ (log A = 2.77)accept H₀ (log B = −1.56)

Each 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

Λ = 2.95
  1. 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).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .017).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Λn=∑i≤nln⁡f1(xi)f0(xi),stop when Λn≥ln⁡1−βα or Λn≤ln⁡β1−α\Lambda_n=\sum_{i\le n}\ln\frac{f_1(x_i)}{f_0(x_i)},\qquad \text{stop when }\Lambda_n\ge\ln\frac{1-\beta}{\alpha}\ \text{or}\ \Lambda_n\le\ln\frac{\beta}{1-\alpha}

With your numbers

Λ=2.95 after n=39,ln⁡A=2.77, ln⁡B=(−1.56)\Lambda = 2.95\ \text{after } n = 39,\quad \ln A = 2.77,\ \ln B = (-1.56)
f0, f1f_0,\ f_1
Bernoulli likelihoods under p₀ and p₁
ln⁡A, ln⁡B\ln A,\ \ln B
Wald's boundaries for target error rates α and β (approximate because of overshoot)
pp
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 H0.

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

Λn=∏i=1nf1(Xi∣X<i)f0(Xi∣X<i)A≈1−βαB≈β1−α\begin{gathered}\Lambda_n=\prod_{i=1}^{n}\frac{f_1(X_i\mid X_{<i})}{f_0(X_i\mid X_{<i})}\\[5pt] A\approx\frac{1-\beta}{\alpha}\\[5pt] B\approx\frac{\beta}{1-\alpha}\end{gathered}

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.

Python · native

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
R

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

  • Wald (1945) — Wald (1945) · Sequential Tests of Statistical Hypothesesdoi.org
  • 1177731118doi.org
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.