Control false discoveries across many eval comparisons

Test fifty prompts against a baseline at p < 0.05 and you expect a couple of false wins by luck. Benjamini-Hochberg keeps the expected share of false discoveries below q.

Write bh_reject(pvals, q=0.05). Sort the m p-values ascending. Find the largest k with p_(k) <= k q / m. Reject the k smallest. Return a boolean array in the original order. If no k qualifies, reject nothing.

Signaturedef bh_reject(pvals, q=0.05)

Example

bh_reject([0.01, 0.04, 0.03, 0.2], q=0.1) rejects the first three.

Understand the idea

If you test 50 prompt variants at p < 0.05, a few will look like winners by luck alone. Benjamini-Hochberg controls the expected share of false wins among the ones you call significant. Sort the p-values and compare the k-th smallest with a rising threshold k * q / m. Find the largest k that passes; then reject all k smallest, even ones that missed their own threshold. That step-up rule is the key. Worked example: p-values [0.02, 0.025, 0.5], q = 0.05, m = 3. Thresholds: 0.0167, 0.0333, 0.05. The smallest, 0.02, fails 0.0167. The second, 0.025, passes 0.0333. The third, 0.5, fails. Largest passing k = 2, so reject both 0.02 and 0.025. Rule: sort ascending, find the largest k with p_(k) <= k * q / m, mark the k smallest as rejected and return the mask in the original order; if none passes, reject nothing. Rejecting only individual passes would miss 0.02 here. Used when comparing many models or prompts against a baseline, and in A/B testing platforms.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks the hidden tests with Pro.

  • Sample 1: examplebh_reject([0.01, 0.04, 0.03, 0.2], q=0.1)
  • Sample 2: step up rescues a middle valuebh_reject([0.001, 0.03, 0.026, 0.04], q=0.05)