1 proportion test: exact binomial test and confidence interval

Updated

The 1 proportion test checks whether the proportion of units with some attribute, such as defective, passing or late, differs from a target value. With n units inspected and x of them defective, the sample proportion is p̂ = x/n. The exact test computes the p-value directly from the binomial distribution, and the exact (Clopper–Pearson) interval gives the range of proportions consistent with the data.

When to use it

  • A supplier claims a defect rate of at most some value and you want to check it from an incoming sample.
  • You want a confidence interval for a yield, a first-pass rate or a failure rate from pass/fail data.
  • You need to show that a rate meets a requirement, such as "at least 99% of seals pass".
  • For tracking a proportion over time, use a P chart instead; for comparing two groups, use the 2 proportions test.

How it works

Hypotheses, with p the true proportion and p₀ the target:

  • H₀: p = p₀.
  • H₁: p ≠ p₀, or p > p₀, or p < p₀.

Under H₀, the number of defectives X follows a binomial distribution with n trials and probability p₀. The exact test adds up binomial probabilities:

p-value (H₁: p > p₀) = P(X ≥ x) = 1 − Σ_{k=0}^{x−1} C(n, k) p₀ᵏ (1 − p₀)ⁿ⁻ᵏ

For H₁: p < p₀ it is P(X ≤ x). For a two-sided test, a common rule (used here) adds the probabilities of all outcomes no more likely than the one observed.

The normal approximation Z = (p̂ − p₀)/√(p₀(1 − p₀)/n) is fine when np₀ and n(1 − p₀) are both at least 5 or so. With low defect rates that is rarely true, and the exact test is the safe default.

Confidence intervals for p:

  • Exact (Clopper–Pearson): the lower limit is the p at which P(X ≥ x) = α/2, the upper limit the p at which P(X ≤ x) = α/2. They can be computed from the beta or F distribution. The interval is guaranteed to reach at least the stated confidence, so it is conservative (a little wide).
  • Wilson score: inverts the normal score test. Its coverage is close to the stated level, even for small counts.
(p̂ + z²/2n ± z√(p̂(1 − p̂)/n + z²/4n²)) / (1 + z²/n)
  • Agresti–Coull: add z²/2 successes and z²/2 failures (about 2 and 2 at 95%), then use the simple normal formula. Easy to compute by hand and close to Wilson.

Assumptions: each unit is independent and has the same probability of being defective.

Example

A packaging plant buys blister packs from a supplier that promises a seal-defect rate of at most 1%. Incoming inspection leak-tests a random sample of 250 packs from a new lot and finds 6 that leak, p̂ = 6/250 = 2.4%.

Is the lot worse than the promised 1%? The hypotheses are H₀: p = 0.01 and H₁: p > 0.01, one-sided, α = 0.05.

If the true rate were 1%, the expected count would be 250 × 0.01 = 2.5 leakers. The probability of 6 or more is:

  • P(X ≥ 6) = 1 − P(X ≤ 5) = 0.041.
Binomial probabilities of leakers in 250 packs if p = 1%0.00.10.2Probability0123456789
Binomial probabilities of leakers in 250 packs if p = 1%

The p-value of 0.041 is below 0.05, so the data are evidence that the lot's defect rate exceeds 1%. The matching one-sided 95% exact lower bound is 1.05%: the data say the rate is at least about 1.05%.

The two-sided 95% intervals for p by each method:

MethodLowerUpper
Exact (Clopper–Pearson)0.89%5.15%
Wilson1.10%5.14%
Agresti–Coull0.98%5.26%

The normal-approximation test would give Z = 2.22 and p = 0.013, a much stronger result than the exact 0.041. With an expected count of only 2.5, the normal curve is a poor fit to the binomial, and the approximation overstates the evidence.

How to read the results

  • The test answers the supplier question. At the 5% level, the lot does not meet the 1% promise. The evidence is not overwhelming (p = 0.041), so a reasonable next step is a larger sample or a review with the supplier, not an immediate rejection of every lot.
  • The interval says how bad it could be. The true rate is plausibly anywhere from about 1% to 5%. Six defectives in 250 cannot pin a rate down closely.
  • One-sided test, two-sided interval. The two-sided 95% exact interval starts at 0.89%, just below 1%, while the one-sided test rejects. There is no conflict: the two-sided interval puts 2.5% in each tail, the one-sided test puts 5% in one tail. The matching one-sided bound (1.05%) agrees with the test.
  • Low rates need big samples. To tell 1% from 2% reliably, you need many hundreds of units. See sample size for 1 proportion.

Common mistakes

  • Using the normal approximation with few defectives. With an expected count below about 5, it gives p-values that are too small and intervals that can go below zero.
  • Reporting "0 defects, so the rate is 0%". Zero defectives in 100 units still allows a rate up to about 3.6% at 95% confidence (exact upper limit).
  • Sampling from one corner of the lot. The binomial model needs a random sample; packs from one carton may share one sealing problem.
  • Picking the one-sided alternative after seeing the data. Decide the direction from the question before you inspect.

Frequently asked questions

Which confidence interval should I use for a proportion?

The exact Clopper–Pearson interval when you need guaranteed coverage, such as for a validation or a claim to a customer. Wilson or Agresti–Coull when you want an interval whose coverage is close to 95% on average and slightly narrower. All three agree closely for large counts.

Why is the exact test called exact?

Because it uses the binomial distribution itself instead of a normal approximation. The p-value is the actual probability of the observed result or a more extreme one under H₀.

What if I found zero defectives?

The point estimate is 0, but the exact upper limit is not. For x = 0 the exact 95% two-sided upper limit is 1 − 0.025^(1/n); with n = 100 that is 3.6%. A common shortcut for a one-sided 95% bound is the "rule of three": about 3/n.

Can I use this for yield instead of defects?

Yes. Count passes instead of failures and test against the target yield. The math is the same with p replaced by 1 − p.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab