Simulate Type I error inflation from repeated peeking in A/A tests
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `peeking_false_positive_rate` in `solution.py`. It simulates A/A tests in which the analyst checks a fixed-alpha z-test at every interim look and stops as soon as the result looks significant. Return the fraction of experiments that declare a false positive at least once.
```python
def peeking_false_positive_rate(n_looks: int, per_look: int, alpha: float = 0.05,
n_sims: int = 4000, seed: int = 0) -> float:
```
Follow this procedure exactly so the result is reproducible:
1. Create `rng = np.random.default_rng(seed)` and `z_crit = scipy.stats.norm.ppf(1 - alpha/2)`.
2. For each of `n_sims` experiments, run up to `n_looks` looks, keeping a running sum for each arm and a running per-arm count `n`.
3. At each look, draw arm A first and then arm B, each with `rng.standard_normal(per_look)`, and update the sums and `n`.
4. Compute `z = (mean_A - mean_B) / sqrt(2.0 / n)`. Each arm has known unit variance, so there is no pooled estimate.
5. If `|z| >= z_crit`, count a false positive and stop that experiment.
6. Return the false-positive fraction as a `float`. Expect it to be several times `alpha`.
Use only `numpy` and `scipy.stats`, with no I/O or external data.
```hint Reproducibility
All experiments share one random stream. Think about which draws happen, and in what order, once an experiment has already stopped.
```
```hint Sanity check
With `n_looks = 1` the procedure is an ordinary fixed-sample test. Work out what the function should return in that case before you trust the larger values.
```
### Constraints & Assumptions
- `n_looks >= 1`, `per_look >= 1` and `0 < alpha < 1`.
- Defaults are `n_sims = 4000` and `seed = 0`.
- Both arms come from the same standard normal distribution, so every rejection is a false positive.
- Only `numpy` and `scipy.stats` are available.
### What a Strong Answer Covers
- A loop that follows the procedure step by step: one generator, arm A drawn before arm B, running sums, and a stop at the first crossing.
- The correct standard error for a difference of two means with known unit variance and `n` observations per arm.
- Why the returned rate exceeds `alpha` and how it changes as `n_looks` grows.
- A sanity check on the output, such as the one-look case or the Monte Carlo error at 4,000 simulations.
- The time and memory cost of the simulation.
### Follow-up Questions
- How would you change the boundaries so the overall Type I error stays at `alpha`?
- Why does the measured false-positive rate grow with `n_looks`, and why does it grow more slowly than a Bonferroni sum?
- Does `per_look` change the expected false-positive rate? Why or why not?
- How would you vectorize the simulation, and what would that do to reproducibility against this procedure?
Overview: Write a seeded simulation of A/A tests in which the analyst checks a fixed-alpha z-test after every batch of data and stops at the first significant result. It tests whether you can reproduce a specified random procedure exactly and explain how repeated looks change the Type I error of an experiment.