Skip to content
svgsprt-path

SPRT log-likelihood ratio walk

After each observation (or event), has the evidence crossed the boundary for H₁ or for H₀?

Demo data · seed 20261101 · 43 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read the black path as the evidence after each observation.
  2. Crossing the upper line: reject H₀; the lower: accept H₀.
  3. Stop at the first crossing.
  1. Callout 1: The first crossing: stop here.
  2. Callout 2: The reject-H₀ boundary.
  3. Callout 3: The accept-H₀ boundary.

Watch out

  • An SPRT plans for specific hypotheses; a true effect between them can take a long time to decide.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Series named like reject / log A / critical value are the upper boundary, accept / log B the lower one; any other series is the observed walk.
  • The first crossing is the first observed point at or beyond a boundary interpolated at that x; the engine's decision is authoritative (Wald's truncation rule may decide earlier).
# SPRT log-likelihood ratio walk — Codesplash Chart Lab (recipe "sprt-path")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("sprt-path-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["series"] = pd.Categorical(df["series"].astype("string"), categories=["reject H₀ (log A)", "accept H₀ (log B)", "observed log Λ"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
X = "observation"
L = "log Λ"
S = "series"
groups = levels_of(df[S]) if S else [None]
series = []
for name in groups:
    d = df if name is None else df[df[S].astype(str) == str(name)]
    series.append((name if name is not None else "", d.dropna(subset=[X]).sort_values(X)))
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axhline(0, color="grey", linewidth=0.8)
for name, d in series:
    low = str(name).lower()
    kind = "upper" if any(w in low for w in ("reject", "log a", "critical", "upper", "signal")) else "lower" if any(w in low for w in ("accept", "log b", "lower")) else "path"
    col = {"upper": PALETTE[0], "lower": PALETTE[1], "path": "black"}[kind]
    ax.plot(d[X], d[L], color=col, linestyle="-" if kind == "path" else "--", marker="o" if kind == "path" else None, ms=3, linewidth=2 if kind == "path" else 1.5, label=name)
ax.set_xlabel(X)
ax.set_ylabel(L)
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads sprt-path-demo.csv · app theme from the optional codesplash helper