BLOGLLM Logo
Go Pro
Guest
Not signed in
All BlogsCoursesPracticeInterview prepSeriesTagsBookmarksPricing
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboardGames
Articles
Practice / Probability and statistics24 of 24 in topic

824. Correct many A/B test p-values with Holm-Bonferroni

MediumProbability and statistics Pro

Why it matters Prompt and model A/B tests often compare many variants at once, and uncorrected p-values produce fake wins.

Test 20 prompt variants at alpha = 0.05 and one will look like a win by luck. Bonferroni divides alpha by the number of tests; Holm's step-down method controls the same family-wise error but rejects more often.

Write holm(pvals, alpha=0.05). Sort p-values ascending (ties: original order). For rank i = 1..m compare p_(i) with alpha / (m - i + 1). Reject in order until the first p-value that fails; that one and all later ones are kept. Return a list of bools in the ORIGINAL order, True where the hypothesis is rejected.

An empty pvals list returns an empty list.

Functiondef holm(pvals, alpha=0.05)

Example 1

Input: holm([0.01, 0.04, 0.03, 0.005], 0.05)

Output: [True, False, False, True]

Example 2

Input: pvals = [0.2, 0.001], alpha = 0.05

Output: [False, True]

Constraints

  • Python 3 standard library. Code runs in your browser.
  • Run checks the sample tests. Submit checks the full hidden test set (Pro).
Hint 1

Sort indices by p-value so you can map results back.

Hint 2

The threshold for 1-based rank i is alpha / (m - i + 1).

Hint 3

Stop at the first failure; nothing after it is rejected.

Common mistakes
  • Continuing after a failure, which breaks the error guarantee.
  • Returning answers in sorted order instead of the original order.
Understand the idea

Holm sorts p-values and uses a threshold that loosens as you go: alpha/m for the smallest, alpha/(m - 1) for the next, up to alpha. It stops at the first failure, which keeps the family-wise error at alpha.

Worked example

p = [0.01, 0.04, 0.03, 0.005], alpha 0.05. Sorted: 0.005 <= 0.0125 yes, 0.01 <= 0.0167 yes, 0.03 <= 0.025 no, stop. Rejected: the 0.005 and 0.01 tests.

reject p_(i) while p_(i) <= alpha / (m - i + 1)
Topics
Probability and statistics
Similar questions
  • Decide if a new prompt really converts better with a two-proportion z-testMedium
  • Update your belief about a model's pass rate with a Beta priorMedium
  • Put a bootstrap confidence interval on an evaluation scoreMedium
  • Compare two eval runs with Welch's t-test statisticMedium
All Probability and statistics problems
Report
824 / 903
Python 3solution.pyPython idle
1
2
3
4
def holm(pvals, alpha=0.05):
# your code here
pass
​

Run checks these cases in your browser, no sign-in needed. Submit checks the full hidden test set with Pro.

Ctrl/Cmd + Enter to run
© BlogLLM, Bengaluru, IndiaAboutTermsPrivacyRefundsDMCAContactRSS