Skip to content
DeepForgeby svx
All problems
HardStatisticsst-259

Clopper-Pearson Lite

Problem

Return the exact Clopper-Pearson interval [low, high] for k successes in n trials at significance alpha. Solve the binomial tail equations by bisection over p in [0, 1] using the exact binomial CDF built from math.comb. Return [0.0, 0.0] when n <= 0 and [0.0, 1.0] when alpha lies outside (0, 1).

Hint

The lower bound solves P(X >= k; n, p) = alpha/2 and the upper bound solves P(X <= k; n, p) = alpha/2.

Test cases

case 1
in: [10,20,0.05]
expected: [0.2719578495607916,0.7280421504392083]
case 2
in: [0,10,0.05]
expected: [0,0.3084971078187607]
case 3
in: [10,10,0.05]
expected: [0.6915028921812392,1]
case 4
in: [3,10,0.1]
expected: [0.08726443391415034,0.6066242161054134]
Starter codePython
import math
def clopper_pearson(k, n, alpha):
    # Your code here
    pass

4 test cases · run your code against them in the editor