mSPRT Always-Valid Stopping Rule

Quick Overview

Implement the mSPRT stopping rule that returns the first look at which the normal-mixture likelihood ratio reaches one over alpha. It tests computing the statistic correctly, handling the threshold boundary, and explaining why an always-valid test needs no alpha spending under continuous monitoring.

mSPRT Always-Valid Stopping Rule

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: medium

Interview Round: Other

Implement `msprt_stopping_look(xbars, ns, sigma2, tau2, alpha=0.05)` in `solution.py`. A normal stream with known variance `sigma2` is tested under `H0: mean = 0`. Given per-look means `xbars`, sample sizes `ns`, `sigma2`, the mixing variance `tau2` and `alpha`, compute the mSPRT statistic at each look and return the 1-based index of the first look where it reaches `1/alpha`, or `None`. The statistic at look `k`: ```text Lambda_k = sqrt(sigma2 / (sigma2 + ns[k]*tau2)) * exp(ns[k]**2 * tau2 * xbars[k]**2 / (2*sigma2*(sigma2 + ns[k]*tau2))) ``` Requirements: - Iterate over the looks in order, computing `Lambda_k` from `xbars[k]`, `ns[k]`, `sigma2` and `tau2`. - Stop at the first look where `Lambda_k >= 1/alpha` (use `>=`, not `>`). - Apply no multiple-looks correction beyond the `1/alpha` threshold. - Return the 1-based look index as an `int`, or `None` if the threshold is never reached. Example: ```text Input: xbars = [0.05, 0.08, 0.10, 0.11, 0.115] ns = [500, 1000, 2000, 3000, 4000] sigma2 = 1.0, tau2 = 0.01, alpha = 0.05 Output: 3 ``` With `alpha = 0.05` the threshold is 20, and look 3 is the first look where `Lambda_k` is at least 20. ```hint Check the boundary Compute the statistic at looks 2 and 3 of the example by hand to see where it first passes 20, and make sure a value exactly equal to `1/alpha` stops the test. ``` ```hint Large samples For a large `ns[k]` and a nonzero mean the exponent can overflow `np.exp`. Ask whether the comparison with the threshold has to happen on the original scale. ``` ### Constraints & Assumptions - `xbars` and `ns` are aligned, equal-length `np.ndarray` inputs ordered by look. - `ns` holds positive observation counts. - `sigma2` and `tau2` are positive, and `alpha` is between 0 and 1. ### What a Strong Answer Covers - The statistic computed exactly as given and checked against the example. - The first crossing found with `>=`, reported as a 1-based index, with `None` when the threshold is never reached. - Why a fixed `1/alpha` threshold controls type I error under continuous monitoring (the martingale property under `H0` and Ville's inequality). - Numerical stability for large samples, plus time and space complexity. ### Follow-up Questions - Why is no alpha-spending correction needed here, unlike group sequential designs? - How does the choice of the mixing variance `tau2` affect the test? - How would you also emit an always-valid confidence sequence, not just a stop decision?

Overview: Implement the mSPRT stopping rule that returns the first look at which the normal-mixture likelihood ratio reaches one over alpha. It tests computing the statistic correctly, handling the threshold boundary, and explaining why an always-valid test needs no alpha spending under continuous monitoring.

Nov 24, 2026
mediumData ScientistOtherAnalytics & Experimentation
0
0

Implement msprt_stopping_look(xbars, ns, sigma2, tau2, alpha=0.05) in solution.py. A normal stream with known variance sigma2 is tested under H0: mean = 0. Given per-look means xbars, sample sizes ns, sigma2, the mixing variance tau2 and alpha, compute the mSPRT statistic at each look and return the 1-based index of the first look where it reaches 1/alpha, or None.

The statistic at look k:

Lambda_k = sqrt(sigma2 / (sigma2 + ns[k]*tau2))
           * exp(ns[k]**2 * tau2 * xbars[k]**2 / (2*sigma2*(sigma2 + ns[k]*tau2)))

Requirements:

  • Iterate over the looks in order, computing Lambda_k from xbars[k] , ns[k] , sigma2 and tau2 .
  • Stop at the first look where Lambda_k >= 1/alpha (use >= , not > ).
  • Apply no multiple-looks correction beyond the 1/alpha threshold.
  • Return the 1-based look index as an int , or None if the threshold is never reached.

Example:

Input:  xbars  = [0.05, 0.08, 0.10, 0.11, 0.115]
        ns     = [500, 1000, 2000, 3000, 4000]
        sigma2 = 1.0, tau2 = 0.01, alpha = 0.05
Output: 3

With alpha = 0.05 the threshold is 20, and look 3 is the first look where Lambda_k is at least 20.

Constraints & Assumptions

  • xbars and ns are aligned, equal-length np.ndarray inputs ordered by look.
  • ns holds positive observation counts.
  • sigma2 and tau2 are positive, and alpha is between 0 and 1.

What a Strong Answer Covers Guidance

  • The statistic computed exactly as given and checked against the example.
  • The first crossing found with >= , reported as a 1-based index, with None when the threshold is never reached.
  • Why a fixed 1/alpha threshold controls type I error under continuous monitoring (the martingale property under H0 and Ville's inequality).
  • Numerical stability for large samples, plus time and space complexity.

Follow-up Questions Guidance

  • Why is no alpha-spending correction needed here, unlike group sequential designs?
  • How does the choice of the mixing variance tau2 affect the test?
  • How would you also emit an always-valid confidence sequence, not just a stop decision?