Compute a Normal-Mixture Confidence Sequence Interval for a Running Mean
Quick Overview
Compute the Robbins normal-mixture confidence sequence interval for a running mean with known variance. It tests implementing the anytime-valid half-width, explaining why it is wider than a fixed-sample z-interval, and how the mixing variance changes where the interval is tightest.
Compute a Normal-Mixture Confidence Sequence Interval for a Running Mean
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `normal_mixture_confidence_sequence(xbar, n, sigma2, tau2, alpha=0.05)` in `solution.py`. Given the running mean `xbar` of a normal stream after `n` steps, the known per-observation variance `sigma2` and the mixing variance `tau2`, return the anytime-valid confidence sequence interval for the mean at that `n`.
Requirements:
- Half-width:
```text
hw = sqrt( ( sigma2 * (n*tau2 + sigma2) / (n**2 * tau2) )
* ln( (n*tau2 + sigma2) / (sigma2 * alpha**2) ) )
```
- `ln` is the natural logarithm, and `alpha` appears as `alpha**2` inside the log.
- Return `(xbar - hw, xbar + hw)` as `(float, float)`.
Example:
```text
Input: xbar = 0.2, n = 1000, sigma2 = 1.0, tau2 = 0.05 (alpha = 0.05)
Output: (0.2 - 0.10060693804817317, 0.2 + 0.10060693804817317), about (0.0994, 0.3006)
```
The half-width at `n = 1000` is 0.10060693804817317. With the same `sigma2`, `tau2` and `alpha`, the half-width at `n = 5000` is 0.048089469026356954.
```hint Check the log term
At `n = 1000` the argument of the log is `51 / 0.0025`. If your half-width does not match, check that the log is natural and that `alpha` is squared.
```
```hint Compare with a fixed-n interval
Compute the usual 95% z half-width `1.96 * sqrt(sigma2 / n)` at the same `n` and compare. The follow-ups ask where the difference comes from.
```
### Constraints & Assumptions
- `n` is a positive integer count of observations.
- `sigma2` and `tau2` are positive, and `alpha` is between 0 and 1.
### What a Strong Answer Covers
- The half-width computed exactly as specified, matching the example at `n = 1000` and `n = 5000`.
- The return value as a tuple of two Python floats.
- What anytime-valid means here: coverage holds at every `n` at once, so the interval can be checked after each observation.
- Why the interval is wider than the classical z-interval and how its width shrinks with `n`.
- How `tau2` changes the sample size at which the sequence is tightest.
### Follow-up Questions
- Why is this interval wider than the classical z-interval?
- How does the choice of `tau2` affect the interval?
- If you track the interval over many values of `n`, can you report the running intersection of all intervals so far, and why is that still valid?
Overview: Compute the Robbins normal-mixture confidence sequence interval for a running mean with known variance. It tests implementing the anytime-valid half-width, explaining why it is wider than a fixed-sample z-interval, and how the mixing variance changes where the interval is tightest.
Implement normal_mixture_confidence_sequence(xbar, n, sigma2, tau2, alpha=0.05) in solution.py. Given the running mean xbar of a normal stream after n steps, the known per-observation variance sigma2 and the mixing variance tau2, return the anytime-valid confidence sequence interval for the mean at that n.