EProportions · Guide test 054
Exact binomial test
Tests a binary success probability against a specified value using the binomial distribution.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- One proportion (exact binomial / score test) — Does the share of an outcome differ from a reference proportion?
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
Alternative
Your data
Edit the countsSuccesses 7 of 20
If H₀ were true
- The reference: how x varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the total probability of outcomes no more likely than yours (p = .037).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- observed successes
- trials
- 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 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
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.
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)
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.6Sources
- SciPy — SciPy · binomtestdocs.scipy.org
- scipy.stats.binomtestdocs.scipy.org
- 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.