Skip to main content

wilson_ci

Function wilson_ci 

pub fn wilson_ci(k: u32, n: u32) -> (f64, f64)
Expand description

Wilson score 95% confidence interval for a proportion k / n.

Returns (low, high) in [0.0, 1.0]. Returns (0.0, 0.0) when n = 0 (undefined proportion). Edge cases k = 0 and k = n are handled correctly by the formula without special-casing.

A thin wrapper over wilson_ci_from_proportion that forms the point estimate p_hat = k / n from an integer success count — the interval a k-of-n binomial proportion carries. Standard Wilson score interval (Wilson 1927); z = 1.96 for 95% coverage.

Parameters are u32 (not u64) to avoid precision-loss on the f64 conversion — all realistic counts fit comfortably in 32 bits.