Compare Multiple-Testing Corrections: Bonferroni, Holm and BH Rejection Counts
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `def compare_corrections(pvals: list[float], alpha: float = 0.05) -> dict` that counts how many hypotheses each correction rejects on the same `m` p-values. Return a dict with exactly four keys mapping to Python `int` rejection counts.
The four keys:
- `'uncorrected'`: count of raw p-values `<= alpha`.
- `'bonferroni'`, `'holm'`, `'fdr_bh'`: for each method, the sum of element `[0]` (the reject array) of `statsmodels.stats.multitest.multipletests(pvals, alpha=alpha, method=...)`.
Each value is a Python `int`, and `bonferroni <= holm <= fdr_bh <= uncorrected` always holds.
For example:
```python
compare_corrections([0.001, 0.008, 0.039, 0.041, 0.042, 0.06, 0.074, 0.205, 0.212, 0.216], 0.05)
# -> {'uncorrected': 5, 'bonferroni': 1, 'holm': 1, 'fdr_bh': 2}
```
```hint Where the counts live
Look at the structure `multipletests` returns. Only one of its elements is the per-hypothesis decision, and summing a NumPy array does not give a plain Python number.
```
```hint Checking the order
Write each method's threshold for the k-th smallest p-value and compare the thresholds rank by rank. Note which procedure stops at its first failure and which one looks for its last success.
```
### What a Strong Answer Covers
- Calls `multipletests` once per method and reads the reject array from the right element of the returned tuple.
- Returns exactly the four required keys with Python `int` values.
- Explains why the ordering of the four counts holds for any input, using the error rate each method controls and its per-rank thresholds.
- Traces the example by hand to confirm the expected counts.
- Handles edge cases such as an empty list, invalid p-values and values that sit on a threshold.
### Follow-up Questions
- Why does Benjamini-Hochberg assume independent or positively dependent tests, and what would you use under arbitrary dependence?
- Bonferroni and Holm both control the family-wise error rate. When would you prefer Holm, and is there any case for plain Bonferroni?
- An A/B test reports 10 metrics. Which correction would you apply, and how would you explain the choice to the product team?
Overview: Implement a Python function that counts how many hypotheses Bonferroni, Holm and Benjamini-Hochberg reject on the same set of p-values, next to the uncorrected count. It tests family-wise error versus false discovery rate control and why the four counts always fall in the same order.