Practice in Lab: Report uncertainty for a measured success rate →
Report uncertainty for a measured success rate
A success rate from ten examples should not carry the same confidence as one from ten thousand. A Wilson interval adjusts a binomial proportion using the sample count and a chosen normal quantile. Unlike a naive symmetric interval, it behaves sensibly near zero and one.
The calculation assumes independent Bernoulli observations. Correlated sessions or repeated users violate that simple sampling model; resample at the independent group level instead. The exercise accepts z explicitly so the confidence convention is visible and testable. An interval describes sampling uncertainty under assumptions, not protection from dataset bias.
import math
n=10;p=.5;z=1.96
den=1+z*z/n
center=(p+z*z/(2*n))/den
half=z*math.sqrt(p*(1-p)/n+z*z/(4*n*n))/den
print(round(center-half,3),round(center+half,3))Review the design
The z value determines the nominal confidence level through a normal approximation. Independence and representative sampling matter more than the number of decimals printed in the interval.
Your task
Implement wilson(successes,total,z=1.96) returning lower,upper. Require integer 0<=successes<=total, total>0, and finite z>0. Clamp floating roundoff to [0,1].
The explanation opens here once every check passes.