Compute Bonferroni-corrected p-values in NumPy

Quick Overview

Implement the Bonferroni correction in NumPy: multiply each p-value by the number of tests, cap the result at 1 and keep the input order. It tests family-wise error rate control, vectorized array code and how Bonferroni compares with the Holm step-down method.

Compute Bonferroni-corrected p-values in NumPy

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `bonferroni_adjust`, returning Bonferroni-corrected p-values: `min(p_i * m, 1.0)` where `m = len(pvals)`. ```python def bonferroni_adjust(pvals: list[float]) -> np.ndarray: ... ``` Requirements: - Multiply each p-value by `m` and clip at `1.0`. - Return a 1-D numpy array of dtype `float64`, length `m`, in input order. Example: ```python bonferroni_adjust([0.01, 0.04, 0.2, 0.5, 0.9]) # array([0.05, 0.2, 1.0, 1.0, 1.0]) ``` ```hint Valid range Think about what range a corrected p-value has to stay in, and what multiplying by `m` can do to it. ``` ### What a Strong Answer Covers - Multiplies every p-value by the number of tests `m` in one vectorized step. - Caps the result at 1 and explains why the cap never changes a reject decision. - Returns a `float64` array in input order without sorting. - Explains what Bonferroni controls and why it holds for any dependence between the tests. ### Follow-up Questions - How does this compare to the Holm-Bonferroni step-down method? - Why does Bonferroni lose power when the tests are strongly correlated? - When would you switch to Benjamini-Hochberg instead?

Overview: Implement the Bonferroni correction in NumPy: multiply each p-value by the number of tests, cap the result at 1 and keep the input order. It tests family-wise error rate control, vectorized array code and how Bonferroni compares with the Holm step-down method.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement bonferroni_adjust, returning Bonferroni-corrected p-values: min(p_i * m, 1.0) where m = len(pvals).

def bonferroni_adjust(pvals: list[float]) -> np.ndarray:
    ...

Requirements:

  • Multiply each p-value by m and clip at 1.0 .
  • Return a 1-D numpy array of dtype float64 , length m , in input order.

Example:

bonferroni_adjust([0.01, 0.04, 0.2, 0.5, 0.9])
# array([0.05, 0.2, 1.0, 1.0, 1.0])

What a Strong Answer Covers Guidance

  • Multiplies every p-value by the number of tests m in one vectorized step.
  • Caps the result at 1 and explains why the cap never changes a reject decision.
  • Returns a float64 array in input order without sorting.
  • Explains what Bonferroni controls and why it holds for any dependence between the tests.

Follow-up Questions Guidance

  • How does this compare to the Holm-Bonferroni step-down method?
  • Why does Bonferroni lose power when the tests are strongly correlated?
  • When would you switch to Benjamini-Hochberg instead?