#421Sequential Test (mSPRT-Style Always-Valid p-Value)Hard

Sequential Test (mSPRT-Style Always-Valid p-Value)

Background

Standard A/B tests with peeking inflate Type-I error. mSPRT-style always-valid p-values let an experimenter check the running result at any time without the false-positive rate exceeding α\alpha. The kernel: at each step, compute a zz-statistic on the running differences; map to a bounded pp via min(1,ez2/2)\min(1, e^{-z^2/2}).

Problem statement

Implement running_avalp(differences) returning a list of always-valid pp-values, one per step:

xˉn=1ndi,sn2=1n1(dixˉn)2,zn=xˉnsn/n,pn=min ⁣(1,ezn2/2)\bar x_n = \tfrac1n\sum d_i,\quad s_n^2 = \tfrac1{n-1}\sum (d_i - \bar x_n)^2,\quad z_n = \frac{|\bar x_n|}{s_n / \sqrt n},\quad p_n = \min\!\Bigl(1,\, e^{-z_n^2 / 2}\Bigr)

Input

  • differenceslist[float], the per-step paired differences (treatment − control).

Output

Returns list[float] of length len(differences), each in [0,1][0, 1].

Examples

Example 1 — all-zero stream

Input:  [0.0, 0.0, ..., 0.0]
Output: all 1.0

Example 2 — strong signal eventually crosses 0.05

Input:  [1.0] * 100
Output: at some n, p < 0.05; stays below thereafter

Example 3 — n=1 special case

Input:  [0.5]
Output: [1.0]   # no variance estimate yet, return 1

Constraints

  • n<2n < 2 → return 1.0 for that step.
  • Empty input → empty list.
  • All p-values bounded in [0,1][0, 1].

Notes

  • Why this is "always valid". Peeking-safe means Pr[n:pn<αH0]α\Pr[\exists n : p_n < \alpha\,\mid H_0] \le \alpha — the false-positive rate at any stopping time is bounded. The exponential bound comes from mSPRT theory.
  • vs fixed-horizon. Always-valid pp-values are typically 1.5–3× higher than fixed-horizon pp-values at the planned sample size. Tradeoff: peeking flexibility for some power.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Reference three step
  • Sample five step
  • Example four ramp