All problems
Wilson Interval Bounds
Problem
Return the Wilson score interval [low, high] for successes out of n with critical value z, clamping the bounds to [0, 1]. The center is (p + z^2 / (2n)) / (1 + z^2 / n) and the half-width is z * sqrt(p(1-p)/n + z^2/(4n^2)) / (1 + z^2 / n). Return [0.0, 0.0] when n <= 0.
Test cases
case 1
in: [10,20,1.96]
expected: [0.2992949144298199,0.7007050855701801]
case 2
in: [0,10,1.96]
expected: [0,0.2775401687666166]
case 3
in: [10,10,1.96]
expected: [0.7224598312333834,1]
case 4
in: [0,0,1.96]
expected: [0,0]
Starter codePython
def wilson_bounds(successes, n, z):
# Your code here
pass4 test cases · run your code against them in the editor