Skip to content

EProportions · Guide test 054

Exact binomial test

Tests a binary success probability against a specified value using the binomial distribution.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Exact binomial test

20
0.35
0.60
0.050

Alternative

Your data

Edit the counts

Successes 7 of 20

If H₀ were true

x = 7
  1. The reference: how x varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the total probability of outcomes no more likely than yours (p = .037).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

P(X=k)=(nk) p0 k(1−p0) n−kP(X = k) = \binom{n}{k}\, p_0^{\,k} (1-p_0)^{\,n-k}

With your numbers

x=7,n=20,p^=0.35,p0=0.60x = 7,\quad n = 20,\quad \hat p = 0.35,\quad p_0 = 0.60
xx
observed successes
nn
trials
p0p_0
the probability H₀ claims

The verdict

x = 7 of 20, p = .037, p̂ = 0.35

p ≤ α = .050: reject H₀

Effect size: sample proportion p̂ = 0.350

No approximation: the p-value adds up the probabilities of every outcome at least as unlikely as yours under p0. Discreteness means the actual false-positive rate sits below α.

Statistic
7.000
p-value
0.0370
Exact binomial test on 7 successes in 20 trials: x = 7 of 20, p = .037, p̂ = 0.35. The p-value is below α = .050, so the data are hard to reconcile with H0.

Exact binomial test on 7 successes in 20 trials: x = 7 of 20, p = .037, p̂ = 0.35. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: success probability p=p0; H1 is two sided or directional.

Assumptions

Fixed number n of independent Bernoulli trials with common probability p.

Formula

P0(X=x)=(nx)p0x(1−p0)n−xP_0(X=x)=\binom nx p_0^x(1-p_0)^{n-x}

Parameters and notation

x successes,n trials,p0 null probability.

Structure of the method

Count successes in a fixed set of Bernoulli trials and sum binomial probabilities under the specified null success rate. A directional alternative uses one tail; the common two-sided implementation includes outcomes with null probability no larger than the observed outcome's probability. It therefore need not equal twice the smaller tail.

Estimated and nuisance parameters

The observed success proportion estimates the population probability, but the null probability is fixed when computing the test distribution. Sample size is fixed by the stated binomial design. No variance parameter is independently fitted because Bernoulli variance is determined by the probability under the null.

Settings and design choices

Prespecify the null rate, alternative direction, alpha, two-sided convention, and stopping plan. Mid-p, randomized, and exact probability-ordering methods are distinct choices with different conservatism guarantees. An exact confidence interval also needs its convention stated; 'exact test' does not uniquely identify every possible interval construction.

Fitting and adaptation

For a new fixed-size sample, recompute successes and the binomial tail under the same planned null. If monitoring continues until enough successes or significance is observed, derive a stopping-rule-compatible test instead of reusing fixed-n calibration. Unequal trial probabilities require another model, such as an explicitly specified Poisson-binomial construction.

Sensitivity and robustness

Discrete attainable p-values can make the test conservative, especially with small n or extreme null rates. Correlated trials and overdispersion violate the independent-common-probability model. A tiny p-value does not indicate a large practical improvement; report the observed proportion, difference from the target, and an appropriate uncertainty interval.

How to use and calibrate

Sum the appropriate binomial tail. A common exact two sided p value sums probabilities no greater than the observed probability; doubled smaller tails are a different convention.

Example application

Test whether 14 successes in 20 independent attempts is compatible with p0=0.5.

Interpretation and pitfalls

Watch out

Discrete p values are conservative at many α values. Dependence or variable trial probabilities violates the binomial model.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Exact two-sided binomial test; two-sided definitions can differ across implementations.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
print(stats.binomtest(18,30,p=.5))
Output
BinomTestResult(k=18, n=30, alternative='two-sided', statistic=0.6, pvalue=0.36159460805356514)
R

Validated — Executed successfully in the validation environment · needs Base/standard library

print(binom.test(18,30,p=.5,alternative="two.sided"))
Output
	Exact binomial test

data:  18 and 30
number of successes = 18, number of trials = 30, p-value = 0.3616
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.4060349 0.7734424
sample estimates:
probability of success 
                   0.6

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 054, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT054.