BiostatKit
Language

BiostatKit / Tests & intervals / Confidence interval for a proportion

Confidence Interval for a Proportion

A confidence interval for a proportion gives the range of true values compatible with x events out of n people. The Wilson score interval is the usual choice; the Clopper-Pearson interval is exact and a little wider. The simple Wald interval, p ± 1.96 x sqrt(p(1 - p)/n), fails for small samples.

Enter how many people had the outcome out of how many were assessed and get the proportion with its Wilson score interval, the Clopper-Pearson exact interval and the Wald interval, a sentence for your manuscript, and the R code that reproduces the numbers.

Your data never leaves your browser. No sign-up, no ads.

Your count

Counts of people, not percentages.

People who have the characteristic you are counting.
Everyone assessed, with or without the outcome.

Result

Proportion with its confidence interval.

Sentence for your manuscript

Written in AMA style from your numbers. Check it against your own study design before you submit.

Reporting checklist

  • STROBE 2007 (observational studies): describe the statistical methods (item 12) and give estimates with their precision, such as a 95% CI (item 16a). For a prevalence, give the numerator and the denominator.
  • STARD 2015 (diagnostic accuracy studies): sensitivity and specificity are proportions too; report them with 95% CIs (item 24).
  • Name the interval method. Wilson and Clopper-Pearson are the usual choices; avoid the Wald interval for small samples or proportions near 0% or 100%.

Methods wording. The proportion is reported with its 95% CI calculated by the Wilson score method [2] (BiostatKit [1]).
[1] BiostatKit. Confidence interval for a proportion calculator. Accessed [date]. [URL]
[2] Wilson EB. Probable inference, the law of succession, and statistical inference. J Am Stat Assoc. 1927;22(158):209-212.

Reproduce it in R

The script is filled in with your numbers. Paste it into R or RStudio and compare.

R 4.x · base R only

    

This calculator was checked against Python (statsmodels proportion_confint: wilson, beta and normal) on 4 reference cases and matched to 4 significant digits. See the verification log.

How the confidence interval of a proportion works

What it is

A proportion such as a prevalence, a response rate or a sensitivity is x people out of n. Its confidence interval gives the range of true proportions that are compatible with the data. The width depends on n and on how close the proportion is to 0% or 100%.

How this page computes it

With p = x/n and z the normal quantile for the confidence level (1.96 for 95%):

Wilson score: [ p + z²/(2n) ± z sqrt( p(1 - p)/n + z²/(4n²) ) ] / (1 + z²/n).

Clopper-Pearson exact: the limits are quantiles of the beta distribution, lower = B(α/2; x, n - x + 1) and upper = B(1 - α/2; x + 1, n - x), with lower = 0 when x = 0 and upper = 1 when x = n.

Wald: p ± z sqrt( p(1 - p)/n ), cut to between 0 and 1. It is shown for comparison only.

Assumptions

  • The n people are a simple random sample, or close to one, from the population you describe, and each is counted once.
  • Each person either has the outcome or not.
  • Cluster or weighted survey samples need a design-based interval, which is wider.

Common mistakes

  • Using the Wald interval with a small n or a proportion near 0% or 100%. It can even give a negative lower limit or a zero-width interval when x = 0.
  • Reporting 0% with no interval when x = 0. The upper limit still tells the reader how high the true proportion could be.
  • Entering a percentage instead of the count.

Worked example

Step by step

27 of 120 patients had the outcome.

p = 27 / 120 = 22.5%, z = 1.960.

Wilson 95% CI: 15.9% to 30.8%. Clopper-Pearson exact: 15.4% to 31.0%. Wald: 0.225 ± 1.96 x sqrt(0.225 x 0.775 / 120) = 15.0% to 30.0%.

Press Load example above to see these numbers in the calculator.

How to read the result

The data are compatible with a true proportion between about 16% and 31% (Wilson). The interval is not symmetric around 22.5%: Wilson and Clopper-Pearson correctly allow more room on the side away from 0%.

With 120 people the three methods are close. With small n or a proportion near 0% or 100% they differ more, and the Wald interval becomes unreliable.

Frequently asked questions

Wilson or Clopper-Pearson: which interval should I use?

Both are accepted. The Wilson interval is closer to the stated 95% coverage on average; the Clopper-Pearson interval is guaranteed to cover at least 95% and is therefore a little wider. Brown, Cai and DasGupta (2001) recommend Wilson. Name the one you report.

What if no one had the outcome (x = 0)?

The proportion is 0%, and the lower limit is 0. The upper limit is still informative: with 0 of 25, the 95% Wilson upper limit is about 13%. For x = 0, the rule of three (3/n) gives a quick approximation of the upper limit.

Why is the Wald interval not recommended?

It assumes the proportion is normally distributed around p, which fails for small samples and for proportions near 0% or 100%. Its true coverage can be well below 95%.

How many people do I need for a narrower interval?

The width shrinks roughly with the square root of n: four times as many people halve the width. To plan a study around a target margin of error, use the sample size calculator for a proportion.

Is my data stored or sent anywhere?

No. All calculations run in your browser tab. Nothing is uploaded, and the page works offline once loaded.

Related calculators