Estimate the A/A test false-positive rate with a seeded Monte Carlo simulation
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `aa_false_positive_rate` in Python to estimate the A/A test false-positive rate by Monte Carlo. Run `n_sims` iterations, each sampling two independent Normal groups of size `n_per_group` and running a Welch two-sided t-test. Return the fraction of iterations with `pvalue < alpha`.
```python
def aa_false_positive_rate(n_sims: int, n_per_group: int, mu: float,
sigma: float, alpha: float, seed: int) -> float:
...
```
Requirements:
- Create `np.random.default_rng(seed)` exactly once and reuse it across all simulations (no reseeding).
- Per iteration, sample control first, then treatment, each via `rng.normal(mu, sigma, n_per_group)`.
- Use `scipy.stats.ttest_ind(control, treatment, equal_var=False)`.
- Count a false positive with strict `pvalue < alpha`.
- Return `(# false positives) / n_sims` as a `float`.
`numpy` and `scipy` are available.
Example:
```python
aa_false_positive_rate(2000, 500, 0.0, 1.0, 0.05, 42) # -> 0.057
```
```hint Reproducibility
The pinned value depends on the exact random stream: where the generator is created and how many values each call draws from it. Get that right before you think about the statistics.
```
### What a Strong Answer Covers
- Why a calibrated two-sided test should reject in about a fraction `alpha` of A/A runs, and what the p-value distribution looks like under the null
- How one generator, created once, and one `rng.normal` call of the stated size per group make the result reproducible
- The exact test call, the strict comparison and a float return value
- How far the simulated rate can sit from `alpha` by chance for a given `n_sims`
- Time and space cost of the simulation
### Follow-up Questions
- How would you check that the observed rate is statistically consistent with `alpha`?
- What does Welch's test (`equal_var=False`) buy you over Student's t-test here?
- How would you extend this to estimate statistical power instead of the false-positive rate?
- If a real experimentation pipeline showed an A/A rejection rate well above `alpha`, what would you look for first?
Overview: Write a seeded Monte Carlo simulation of an A/A test that draws two Normal groups per run, applies a two-sided Welch t-test, and returns how often the p-value falls below alpha. It tests reproducible random sampling and an understanding of type I error calibration.