Implement Holm step-down adjusted p-values without statsmodels
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement the function below so that it reproduces `multipletests(pvals, method='holm')[1]` from statsmodels exactly, without calling statsmodels. Let `m = len(pvals)`.
```python
def holm_adjust_manual(pvals: list[float]) -> np.ndarray:
```
The function must:
- Sort ascending and multiply `p_(i)` by `(m - i + 1)` at 1-indexed rank `i` (the smallest p by `m`, the largest by 1).
- Enforce monotonicity with a cumulative maximum scanning from the smallest p-value to the largest.
- Clip adjusted values at 1.0.
- Return a 1-D `float64` array in the original input order.
Example:
```python
pvals = [0.001, 0.008, 0.039, 0.041, 0.042, 0.06, 0.074, 0.205, 0.212, 0.216]
holm_adjust_manual(pvals)
# -> [0.01, 0.072, 0.312, 0.312, 0.312, 0.312, 0.312, 0.615, 0.615, 0.615]
```
```hint Building the multipliers
The multipliers fall from `m` to 1 across the sorted ranks. A single `np.arange` call produces them without a loop.
```
```hint Back to input order
You need the inverse of the sort permutation, not the permutation itself. Check which side of the assignment the sort order belongs on.
```
### What a Strong Answer Covers
- How the decreasing multiplier lines up with the 1-indexed sorted ranks
- Which direction the cumulative maximum runs, and why that gives adjusted values that never decrease with rank
- The clip at 1.0 and the mapping back to the original input order
- Whether tied p-values or the order of the clip and the running maximum can change the output
- Time and space complexity
### Follow-up Questions
- How do the multiplier and the monotonicity step differ from the Benjamini-Hochberg adjustment, and what error rate does each one control?
- Why does the cumulative maximum guarantee monotonic, valid output?
- How would you compute the Hochberg step-up adjustment, and what assumption does it need that Holm does not?
Overview: Implement Holm step-down adjusted p-values in NumPy so they match the statsmodels holm output without importing the library. Tests the decreasing rank multiplier, the cumulative maximum that enforces monotonicity, clipping at 1, and restoring the original input order.