0%
DQDigital Qasas Courses/Medical Statistics with R and Python
Sign inAll courses
  • Why R and Python, and running them in your browser
  • Data frames, import, and tidy medical data
  • Tables and summaries
  • Variables, types, and the question behind the data
  • Displaying data: frequency distributions, histograms, and shape
  • Means, standard deviations and standard errors
  • The normal distribution
  • Confidence interval for a mean
  • Using P-values and confidence intervals
  • Comparison of two means
  • Analysis of variance
  • Linear regression and correlation
  • Multiple regression and diagnostics
  • Transformations
  • Risk, odds, and how to compare them
  • Proportions and the binomial distribution
  • Two proportions: risk ratio, odds ratio, risk difference, and confidence intervals
  • Chi-squared: 2x2 tables, larger tables, trend, and exact tests
  • Confounding and stratification
  • Logistic regression
  • Matched studies
  • Rates and the Poisson distribution
  • Comparing rates and Poisson regression
  • Standardization: direct, indirect, and the SMR
  • Kaplan-Meier survival curves and the log-rank test
  • Cox proportional-hazards regression
  • Likelihood and the generalized linear model
  • Building models, checking assumptions, and clustered data
  • Systematic reviews and meta-analysis
  • Bayesian statistics
  • Linking analysis to study design
  • Sample size and power
  • Measurement error and its consequences
  • Capstone: from a messy dataset to a reported result
7. Binary outcomes: risk, odds, proportions, the binomial

Proportions and the binomial distribution

Last updated 30 June 2026

A proportion is a count divided by a total. Out of 1,000 vaccinated infants, 23 ran a fever afterwards: the proportion is 0.023. That single number carries sampling error, the same way a sample mean does. Run the survey again on a fresh 1,000 infants and you would not see exactly 23. This lesson works out how much a proportion bounces from sample to sample, and how to turn that spread into a confidence interval you can report.

The chance model behind a proportion is the binomial distribution. Once you have it, the standard error, the confidence interval, and the z-test all follow from it. We write (the Greek letter pi) for the true population proportion, and for the proportion you measured in your sample. Here has nothing to do with 3.14159; it is just the symbol for the underlying risk.

The sampling distribution of a proportion

Suppose the true risk of a fever after a vaccine is . You vaccinate 1,000 infants and count the fevers. You will not get exactly 20 every time. One sample gives 17, the next gives 26. The full list of counts you could observe, each tagged with its probability, is the sampling distribution of the count. Divide every count by and you have the sampling distribution of the proportion. They are one distribution drawn on two scales.

That distribution is discrete. For a sample of 1,000 the proportion can be 17/1000 or 18/1000 but nothing in between, so it steps rather than flows. Its shape has a name and a formula. It is the binomial distribution, fixed by two numbers: the sample size and the true proportion .

The binomial distribution and its assumptions

The binomial distribution gives the probability of getting exactly events out of people. It holds when four things are true.

  • Fixed n. You decide the number of people before you look at any outcome.
  • Two outcomes. Each person is an event or not: fever or no fever, dead or alive, positive or negative.
  • Constant probability. Every person shares the same probability of being an event.
  • Independence. One person's outcome tells you nothing about the next person's.

Key term

The binomial distribution is the sampling distribution of a count (or proportion) of yes-or-no events under the four assumptions above. It is set by and , and it is discrete.

The probability of seeing exactly events is:

The first part counts the number of different orders in which events could fall among people. The exclamation mark is the factorial: , and is defined as 1. The second part is the probability of any one such order: events each with probability , and non-events each with probability .

Worked example 1: a four-child family

Beta-thalassaemia carrier status is common in parts of Malaysia and the wider region. Suppose both parents carry the trait. By Mendel's rule, each child has probability of inheriting thalassaemia major, independently of the other children. A couple has four children. What is the chance that 0, 1, 2, 3, or 4 of them have the major form?

Take . Plug , into the formula:

Repeat for every value of and you get the whole distribution. The number of orders is the binomial coefficient : 1, 4, 6, 4, 1.

Children with major (d)Without (4−d)No. of ordersProbability
0410.3164
1340.4219
2260.2109
3140.0469
4010.0039
Total161.0000

The probabilities add to 1, as they must, because one of the five outcomes has to happen. The most likely single result is one affected child, not zero, even though no child is the commonest individual genotype.

Example

The chance that at least one of the four children has thalassaemia major is , about 68%. Adding the tail probabilities is often easier as one minus the opposite end.

Compute the binomial probabilities for n = 4, π = 0.25, then draw the distribution as a barplot.

n  <- 4
pi <- 0.25
d  <- 0:4
prob <- # fill in with dbinom()
prob <- dbinom(d, n, pi)
barplot(prob, names.arg = d,
        xlab = "No. of children with thalassaemia major",
        ylab = "Probability")
round(prob, 4)
# 0.3164 0.4219 0.2109 0.0469 0.0039

Compute the binomial probabilities for n = 4, π = 0.25, then draw the distribution as a bar chart.

import numpy as np
from scipy.stats import binom
import matplotlib.pyplot as plt
n, pi = 4, 0.25
d = np.arange(0, 5)
prob = # fill in with binom.pmf()
prob = binom.pmf(d, n, pi)
plt.bar(d, prob)
plt.xlabel("No. of children with thalassaemia major")
plt.ylabel("Probability")
plt.show()
print(np.round(prob, 4))
# [0.3164 0.4219 0.2109 0.0469 0.0039]

Standard error of a proportion

Two facts about the binomial drive everything that follows. Its mean is the count you expect, . Its standard deviation, read as a sampling distribution, is the standard error of the count.

Divide by to move from the count to the proportion. The mean of is , and its standard error, the spread of the proportion across repeated samples, is:

You almost never know . For a confidence interval you plug in your observed , giving the estimated standard error . Two things to notice. The spread is widest when and shrinks toward the ends. And it falls with , so to halve the standard error you have to quadruple the sample.

QuantityObserved valuePopulation meanStandard error
Number of events
Proportion
Percentage

Normal approximation to the binomial

Computing exact binomial tail probabilities by hand is slow once is large. The shortcut is that as grows, the binomial gets close to a normal distribution with the same mean and standard error. So you can borrow the z-based machinery you already use for means.

The approximation is good enough when both tails carry enough probability. The working rule is that and are both 10 or more. When you are estimating from data, check the same condition with : both and at least 10.

Watch out

Both conditions must hold, not just one. A rare outcome can satisfy easily while stays tiny. If 4 of 60 patients have the event, , so the normal approximation is not safe even though feels large. Use an exact method instead.

Confidence interval using the normal approximation

When the conditions hold, the confidence interval for a proportion takes the same form as the one for a mean: the estimate plus or minus a multiple of its standard error.

Here is the percentage point of the standard normal distribution. For a 95% interval, . This is the Wald interval, the one most software reports by default.

Worked example 2: a vaccine adverse-reaction rate

In a district immunisation programme, 23 of 1,000 infants showed an adverse reaction within 24 hours of a new vaccine. The observed proportion is , or 2.3%.

  1. Check the conditions: and , both well above 10, so the normal approximation is fine.
  2. Standard error: .
  3. Margin: .
  4. Interval: .

With 95% confidence, the true adverse-reaction rate is between 1.37% and 3.23%. You would tell parents the rate is about 2.3%, with that range as the honest uncertainty around it.

Compute the proportion, its standard error, and the 95% Wald confidence interval from the counts.

x <- 23
n <- 1000
p  <- # fill in
se <- # fill in
p  <- x / n
se <- sqrt(p * (1 - p) / n)
ci <- p + c(-1, 1) * 1.96 * se
round(c(p = p, se = se, lower = ci[1], upper = ci[2]), 5)
#       p      se   lower   upper
# 0.02300 0.00474 0.01371 0.03229

Compute the proportion, its standard error, and the 95% Wald confidence interval from the counts.

import numpy as np
x, n = 23, 1000
p  = # fill in
se = # fill in
p  = x / n
se = np.sqrt(p * (1 - p) / n)
ci = p + np.array([-1, 1]) * 1.96 * se
print(round(p, 5), round(se, 5), np.round(ci, 5))
# 0.023 0.00474 [0.01371 0.03229]

In a Malaysian district, 6 of 80 dengue inpatients developed warning signs (p = 0.075). You want a 95% confidence interval for that proportion. Which method fits?

  • The exact binomial interval, because np = 6 is below 10, so the normal approximation is not reliable here.
  • The Wald (normal) interval, since n = 80 is a large sample.
  • No interval is possible because only 6 events were seen.
The normal approximation needs both np and n − np at least 10. Here n − np = 74 is fine, but np = 6 fails, so the Wald interval can be too narrow and may even run below 0. With a small event count you switch to the exact binomial interval, which is valid for any n. A small count still gives a valid interval; it is just wide.

Exact binomial confidence interval

When or drops below 10, the normal approximation is unreliable and the Wald interval can spill below 0 or above 1, which is nonsense for a proportion. The fix is an exact binomial confidence interval, also called the Clopper-Pearson interval. It is built directly from the binomial probabilities, so it is valid for any sample size. The price is that it is conservative: its real coverage is at least 95%, often a little more, so the interval runs slightly wide.

Take a small phase-2 trial where 9 of 12 patients responded to a drug, so . Here , below 10, so the normal approximation is out. The exact 95% interval runs from about 0.428 to 0.945. That is wide, and honestly so: twelve patients cannot pin a response rate down tightly.

Key term

The exact (Clopper-Pearson) interval inverts the binomial tail probabilities directly instead of using a normal curve. It never leaves the range 0 to 1, and it is the safe default for small samples or rare events.

Get the exact 95% confidence interval for 9 responders out of 12.

x <- 9
n <- 12
bt <- # call binom.test()
bt <- binom.test(x, n)
round(bt$conf.int, 4)
# 0.4281 0.9450
# attr 95 percent confidence interval

Get the exact (Clopper-Pearson) 95% confidence interval for 9 of 12 using the Beta quantiles.

from scipy.stats import beta
x, n = 9, 12
lower = # fill in
upper = # fill in
lower = beta.ppf(0.025, x, n - x + 1)
upper = beta.ppf(0.975, x + 1, n - x)
print(round(lower, 4), round(upper, 4))
# 0.4281 0.9451

Continuity correction

One more wrinkle joins the discrete binomial to the continuous normal. The binomial count can be 9 or 10 but nothing between, while the normal curve flows smoothly. To approximate a discrete probability like with the normal, you treat each whole number as a bar one unit wide, running from to . So becomes the normal area above 8.5, not above 9. That half-unit shift is the continuity correction.

See it in a case where the normal approximation is stretched: , , so the mean is 6 and the standard error is . The exact binomial probability of 9 or more events is 0.0730. Compare the two normal approximations.

Method for Pr(X ≥ 9), n = 12, π = 0.5Result
Exact binomial (sum of d = 9, 10, 11, 12)0.0730
Normal, area above 9 (no correction)0.0416
Normal, area above 8.5 (with correction)0.0745

Without the correction the normal undershoots badly, 0.0416 against the true 0.0730. With it, the approximation lands close at 0.0745. The continuity correction matters most when is small and the normal fit is rough.

Compare the exact binomial tail with the normal approximation, with and without the continuity correction.

n  <- 12
pi <- 0.5
exact <- # P(X >= 9) from pbinom
exact   <- pbinom(8, n, pi, lower.tail = FALSE)   # P(X >= 9)
mu      <- n * pi
sigma   <- sqrt(n * pi * (1 - pi))
no_cc   <- pnorm((9   - mu) / sigma, lower.tail = FALSE)
with_cc <- pnorm((8.5 - mu) / sigma, lower.tail = FALSE)
round(c(exact = exact, no_cc = no_cc, with_cc = with_cc), 4)
#   exact   no_cc with_cc
#  0.0730  0.0416  0.0745

Compare the exact binomial tail with the normal approximation, with and without the continuity correction.

import numpy as np
from scipy.stats import binom, norm
n, pi = 12, 0.5
exact = # P(X >= 9)
exact   = binom.sf(8, n, pi)            # P(X >= 9)
mu      = n * pi
sigma   = np.sqrt(n * pi * (1 - pi))
no_cc   = norm.sf((9   - mu) / sigma)
with_cc = norm.sf((8.5 - mu) / sigma)
print(round(exact, 4), round(no_cc, 4), round(with_cc, 4))
# 0.073 0.0416 0.0745

Tip

Modern analysis leans on exact methods and software, so you rarely hand-apply a continuity correction in practice. It also does not carry over to the logistic regression models you meet later. Learn it so you understand why discrete and continuous probabilities differ by half a unit, then let binom.test or scipy do the work.

Why does Pr(X ≥ 9) for a binomial map to the normal area above 8.5 rather than above 9?

  • The binomial is discrete, and the integer 9 is treated as a bar from 8.5 to 9.5, so "9 or more" starts at the lower edge 8.5 on the continuous scale.
  • 8.5 is the mean of the binomial distribution.
  • The normal curve is always shifted left by 0.5, whatever the direction of the inequality.
Each whole number covers a unit-wide bar centred on itself. To include the value 9 in a "9 or more" tail, the continuous region must start at its lower edge, 8.5. That is why the corrected area (0.0745) is far closer to the exact 0.0730 than the uncorrected area above 9 (0.0416). The shift direction depends on the inequality: for "9 or fewer" you would go up to 9.5 instead.

Common mistakes

  • Using the Wald interval when np is small. A rare event with a modest sample fails the np ≥ 10 check. The normal interval then runs too narrow and can dip below 0. Switch to the exact binomial interval.
  • Checking only one of the two conditions. Both and must reach 10. A common proportion can pass on one side and fail on the other when the event is rare or near-universal.
  • Confusing the count's standard error with the proportion's. The count uses ; the proportion divides inside the root, . Reporting one where you needed the other is off by a factor of .
  • Quoting a confidence interval outside 0 to 1. If the Wald formula returns a bound like −0.01 or 1.04, that is the approximation breaking, not a real result. It signals you should have used an exact interval.
  • Forgetting the binomial assumptions. Clustered or repeated observations on the same people break independence, so the plain binomial standard error understates the true spread. Outbreak data and repeated measures need a different model.

Tips

  • Before any normal-based interval, compute and . If either is below 10, reach for binom.test or the Clopper-Pearson interval without hesitation.
  • For sample-size planning, the standard error is largest at . Use 0.5 as a worst-case guess and you will never under-power.
  • Keep for the truth and for your data. Use the observed in the standard error for a confidence interval, but the hypothesised in the standard error for a z-test.
  • The width of a proportion's interval falls with . To halve it, plan for four times the sample, not twice.
  • Report exact intervals for small studies and rare outcomes. They stay inside 0 to 1 and they do not over-promise precision you do not have.
← PreviousRisk, odds, and how to compare themNext →Two proportions: risk ratio, odds ratio, risk difference, and confidence intervals
On this page
  • The sampling distribution of a proportion
  • The binomial distribution and its assumptions
  • Worked example 1: a four-child family
  • Standard error of a proportion
  • Normal approximation to the binomial
  • Confidence interval using the normal approximation
  • Worked example 2: a vaccine adverse-reaction rate
  • Exact binomial confidence interval
  • Continuity correction
  • Common mistakes
  • Tips