Wilson Confidence Interval Calculator

Wilson Confidence Interval Calculator

The confidence interval to use when a laboratory validates a qualitative method on a modest number of samples — and the one the textbook normal approximation gets badly wrong.

Wilson Confidence Interval

k of n → Wilson lower bound
How many of the samples gave the expected answer — concordant results, correct calls, positives detected, whatever the study was counting.
The total number of samples tested. Must be at least as large as the number correct. A qualitative method verification is often done on 20 to 50 samples, which is exactly where the choice of interval matters most.
95% is the convention for a method validation report. 99% gives a wider interval and therefore a lower — more cautious — lower bound.
76.4% lower confidence boundExample

A qualitative method verification: 19 of 20 samples gave the expected result, 95% confidence

The Wilson score interval

p̂ = k ÷ n
centre = (p̂ + z²⁄2n) ÷ (1 + z²⁄n)
half-width = [z ÷ (1 + z²⁄n)] × √(p̂(1 − p̂)⁄n + z²⁄4n²)
interval = centre ± half-width

compare the normal approximation: p̂ ± z√(p̂(1 − p̂)⁄n)
the observed proportion, k ÷ n. It is the best single estimate and it is not the centre of the Wilson interval
centre
p̂ pulled towards 0.5 by an amount that depends on n. At n = 20 the shrinkage is substantial; at n = 1,000 it is negligible. This is what stops the interval running off the end of the scale
z
1.96 for 95% confidence, 2.576 for 99%
half-width
the ordinary standard-error term p̂(1 − p̂)⁄n with z²⁄4n² added to it, all divided by (1 + z²⁄n). The extra term is what keeps the interval sensible when p̂ is 0 or 1 and the standard error collapses to zero
where it comes from
Wilson's interval inverts the score test. Instead of asking 'how far can the data be from p̂?', it asks which values of p the data would not reject — and solves the resulting quadratic. The normal approximation, by contrast, estimates the standard error at p̂ and then pretends that estimate holds everywhere
why not the exact interval
the Clopper–Pearson interval is exact in the sense of never having coverage below the nominal level, and it achieves that by being conservative — noticeably wider than necessary. Wilson's has coverage much closer to nominal on average and is the usual recommendation for general use
what the interval is not
a range of plausible values for the next sample. It is an interval for the underlying proportion, so it says what the method's true agreement rate might be, not what will happen to the next specimen

Worked example

A qualitative method verification: 19 of 20 samples gave the expected result, 95% confidence
p̂ = 19 ÷ 20 = 0.95, and z² = 1.96² = 3.8416
z²⁄n = 3.8416 ÷ 20 = 0.1921, so the denominator (1 + z²⁄n) = 1.1921
centre = (0.95 + 3.8416⁄40) ÷ 1.1921 = 1.0460 ÷ 1.1921 = 0.8775
half-width = (1.96 ÷ 1.1921) × √(0.95 × 0.05 ÷ 20 + 3.8416 ÷ 1600) = 1.6442 × √0.004776 = 0.1136
Interval = 0.8775 ± 0.1136 = 0.7639 to 0.9911, so 76.4% to 99.1%
The normal approximation on the same data: 0.95 ± 1.96 × √(0.0475 ÷ 20) = 0.95 ± 0.0955 = 85.4% to 104.6% — an upper limit above 100%, and a lower limit nine points too optimistic
Now the case that matters most. With 20 correct out of 20, the normal approximation gives 100% to 100%, because √(p̂(1 − p̂)⁄n) is zero when p̂ is 1. Wilson gives 83.9% to 100.0%, which is what 20 samples actually support

Wilson against the normal approximation

ResultObservedWilson 95% intervalNormal approximation
20 of 20100%83.9% – 100.0%100.0% – 100.0%
19 of 2095%76.4% – 99.1%85.4% – 104.6%
18 of 2090%69.9% – 97.2%76.9% – 103.1%
47 of 5094%83.8% – 97.9%87.4% – 100.7%
94 of 10094%87.5% – 97.2%89.3% – 98.7%
0 of 200%0.0% – 16.1%0.0% – 0.0%
The first and last rows are the ones to remember: with a perfect or an empty result the normal approximation returns a zero-width interval, which claims certainty from twenty samples. Three of the other rows breach 100%. By the last row, with n = 100 and a proportion away from the edge, the two methods have nearly converged — which is the whole point, because a validation study almost never lives there.

What twenty samples can and cannot establish

All samples correctWilson 95% lower boundIn words
10 of 1072.2%Consistent with one result in four being wrong
20 of 2083.9%Consistent with one result in six being wrong
30 of 3088.6%Consistent with one result in nine being wrong
50 of 5092.9%Consistent with one result in fourteen being wrong
100 of 10096.3%Consistent with one result in twenty-seven being wrong
300 of 30098.7%Now the claim of near-perfect agreement is supported
Every row here is a perfect score, and the lower bound is what separates them. This is the table to put in front of anyone who proposes to verify a qualitative assay on twenty samples and report 100% agreement: the observed figure is the same in all six rows and the evidence is not.

Why the textbook interval fails exactly where you need it

A laboratory verifies a qualitative method — a rapid antigen test, a molecular target, a manual interpretation — on twenty samples, and all twenty give the expected answer. The validation report says 100% agreement. What confidence interval goes next to it? The interval taught in every introductory course, p̂ plus or minus z times the square root of p̂(1 − p̂)/n, returns 100% to 100%, because when p̂ is 1 the standard error term is exactly zero. Twenty samples have apparently established perfection with no uncertainty at all, which is plainly false.

The Wilson score interval, published in 1927, does not have this failure. Instead of estimating the standard error at the observed proportion and assuming it holds everywhere, it asks which values of the underlying proportion the data would not reject, and solves the resulting quadratic. The effect is that the interval is centred not on p̂ but on p̂ pulled towards one half by an amount that shrinks as n grows, and that the half-width contains an extra term which keeps it positive when p̂ hits 0 or 1. For twenty correct out of twenty at 95% confidence, Wilson gives 83.9% to 100.0%: the data are entirely consistent with a method that is wrong about one time in six.

The failure is not confined to the extremes. With 19 correct out of 20 the normal approximation gives 85.4% to 104.6% — an upper limit above one, which is a clear signal that the method has broken — while Wilson gives 76.4% to 99.1%. The lower bound differs by nine percentage points, and the lower bound is usually the number that matters, because acceptance criteria are written as 'at least X% agreement'. The normal approximation is optimistic there by roughly the amount that would let a marginal method pass.

Two of these problems are the same problem. The normal approximation is a large-sample method applied to a small sample, and its errors are worst at small n and at proportions near 0 or 1 — which is a precise description of a method validation study, where n is twenty or fifty because samples are scarce and the proportion is near 1 because the method is expected to work. It is wrong exactly where laboratories use it. Wilson is barely more difficult to compute, has coverage much closer to the nominal level across the whole range, and never produces an impossible interval. The exact Clopper–Pearson interval is another option and is reliably conservative — never under-covering, and correspondingly wider than it needs to be — but for routine use Wilson is the one to reach for. Whichever you choose, report the interval alongside the proportion: '20 of 20 (100%, 95% CI 83.9–100%)' is an honest sentence, and '100% agreement' on its own is not.

Frequently asked questions

Why not use the normal approximation for a proportion?

Because it fails at small n and near 0% or 100%, which is where laboratory validation studies live. With 20 correct out of 20 it returns an interval of 100% to 100%, claiming certainty from twenty samples; with 19 of 20 it returns an upper limit of 104.6%, which is impossible. The Wilson interval gives 83.9% to 100.0% and 76.4% to 99.1% respectively.

How do you calculate a Wilson confidence interval?

With p̂ = k/n and z = 1.96 for 95% confidence, the centre is (p̂ + z²/2n) divided by (1 + z²/n), and the half-width is z/(1 + z²/n) multiplied by the square root of p̂(1 − p̂)/n + z²/4n². The interval is the centre plus and minus the half-width, and it always lies between 0 and 1.

How many samples do I need to claim 95% agreement?

More than most protocols assume. A perfect score on 20 samples supports a lower bound of only 83.9%; 50 perfect results give 92.9% and 100 give 96.3%. If the acceptance criterion is a lower bound of 95%, a perfect result on about 75 samples is the minimum, and any errors at all push the requirement up sharply.

Is the Wilson interval better than the exact Clopper–Pearson interval?

For most purposes, yes. Clopper–Pearson is exact in the sense that its coverage never falls below the nominal level, but it achieves that by being conservative and is noticeably wider than necessary. Wilson's coverage is much closer to nominal on average, and it is the interval usually recommended for general use.

Why is the Wilson interval not centred on the observed proportion?

Because it is derived by inverting a test rather than by adding a symmetric margin to the estimate. The centre is the observed proportion shifted towards one half, by an amount that is substantial when n is small and negligible when n is large. That shift is what keeps the interval inside the possible range of a proportion.

Related calculators

References

  1. Wilson EB. Probable inference, the law of succession, and statistical inference. J Am Stat Assoc. 1927;22(158):209–212.
  2. Agresti A, Coull BA. Approximate is better than 'exact' for interval estimation of binomial proportions. Am Stat. 1998;52(2):119–126.
  3. Brown LD, Cai TT, DasGupta A. Interval estimation for a binomial proportion. Stat Sci. 2001;16(2):101–133.
  4. Newcombe RG. Two-sided confidence intervals for the single proportion: comparison of seven methods. Stat Med. 1998;17(8):857–872.

Medical Disclaimer: The tools and content provided here are for educational and reference purposes only. They are not intended to substitute for professional medical advice, diagnosis, or treatment. Clinical decisions should always be based on the comprehensive assessment of a qualified healthcare professional.