Count Significant P-Values With Bonferroni
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Write a Python function `count_significant(pvals, alpha=0.05)` that takes the p-values from a family of tests (for example, one per metric in an A/B test) and returns a dict with exactly two keys:
- `'uncorrected'`: the number of p-values `<= alpha`.
- `'bonferroni'`: the number of p-values `<= alpha / len(pvals)`.
Use the inclusive `<=` comparison for both counts. Both values must be plain Python `int`, not NumPy `int64`.
```python
count_significant([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}
```
```hint Check the return type
Counting with NumPy, for example by summing a boolean array, gives a NumPy integer. Make sure the values that end up in the dict have the type the prompt asks for.
```
### Constraints & Assumptions
- `pvals` is a list of floats between 0 and 1 with at least one entry.
- `alpha` is between 0 and 1 and defaults to 0.05.
- The Bonferroni divisor is the total number of p-values passed in, `len(pvals)`.
### What a Strong Answer Covers
- Computes the corrected cutoff once from `alpha` and the number of tests, and counts against both cutoffs with `<=`.
- Returns exactly the two required keys with native Python `int` values, and says where a NumPy scalar could slip in.
- States the cost (linear time, constant extra space) and what the function does with an empty list.
- Explains what the Bonferroni correction controls and why its count is never larger than the uncorrected count.
### Follow-up Questions
- Holm's step-down procedure also controls the family-wise error rate. What count does it give for the example, and why is it never smaller than the Bonferroni count?
- How would you count discoveries under Benjamini-Hochberg, and when would you prefer false discovery rate control for an experiment with many metrics?
- If the ten metrics are strongly correlated (several of them measure engagement, say), what does Bonferroni cost you, and what would you do instead?
Overview: Write a Python function that counts how many p-values from a family of tests are significant at the raw alpha and after a Bonferroni correction. It tests multiple comparison reasoning, inclusive thresholds, and returning native Python integers from NumPy-friendly code.