Confidence Sequence Stopping Rule: First Look Whose Interval Excludes Zero
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `confidence_sequence_stop(xbars, ns, sigma2, tau2, alpha=0.05)` in `solution.py`. A stream of normal observations with known variance `sigma2` is monitored at several looks; at look `k` you see the running mean `xbars[k]` after `ns[k]` observations. At each look, form the interval `[xbars[k] - hw_k, xbars[k] + hw_k]` using the Robbins normal-mixture half-width below, where `tau2` is the mixing variance. Return the 1-based index of the first look whose interval excludes 0, or `None` if no look does.
```text
hw_k = sqrt( (sigma2 * (ns[k]*tau2 + sigma2) / (ns[k]**2 * tau2))
* ln((ns[k]*tau2 + sigma2) / (sigma2 * alpha**2)) )
```
Requirements:
- Use the natural log, with `alpha**2` inside the log.
- Exclusion is strict: `xbars[k] - hw_k > 0` or `xbars[k] + hw_k < 0`. A bound exactly at 0 does not count.
- Return a 1-based `int`, or `None`.
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
```
The first two intervals still contain 0. At `n = 2000` the interval is about `[0.031, 0.169]`, so the third look is the first to exclude 0.
```hint Check one look by hand
Compute the half-width at the first look before writing the loop (it comes out near 0.137). That confirms where `ns[k]**2` and `alpha**2` belong.
```
```hint Two ways to exclude 0
An interval can clear 0 from above or from below, and a bound that lands exactly on 0 must not count.
```
### Constraints & Assumptions
- `xbars` and `ns` are aligned, equal-length arrays ordered by look.
- `ns` holds positive observation counts.
- `sigma2`, `tau2` and `alpha` are positive, with `alpha` below 1.
### What a Strong Answer Covers
- The half-width computed exactly as specified (natural log, `alpha**2` inside the log), checked against the example.
- A strict two-sided exclusion test, a 1-based return value, and `None` when no look qualifies.
- Why stopping at the first exclusion keeps the false positive rate at or below `alpha` no matter how often you look, and why repeated fixed-horizon z-tests do not.
- Time and space complexity, and edge cases such as negative effects and empty input.
### Follow-up Questions
- Why is this stopping rule anytime-valid, unlike a fixed-horizon z-test?
- How would you handle `sigma2` being unknown in practice?
- How does this stopping rule relate to an mSPRT with the same `tau2` and `alpha`?
Overview: Implement a sequential stopping rule that returns the first look at which a Robbins normal-mixture confidence sequence excludes zero. It tests computing the time-uniform half-width correctly, a strict two-sided exclusion check, and explaining why continuous peeking keeps the false positive rate at alpha.