How this calculation works
Two independent samples fix their own numbers of trials, while the total number of successes remains random. Under equality of success probabilities, that common probability is unknown. An unconditional test enumerates possible success pairs and maximizes the rejection-set probability over the common null probability. Barnard uses a pooled Wald statistic to define the set; Boschloo uses one-sided Fisher p-values as its ordering statistic. Both are available on this page.
p = sup₀≤π≤₁ Σ_(rejection set) C(n₁,i) C(n₂,j) π^(i+j)(1−π)^(n₁+n₂−i−j).A worked example
The default table has success counts seven and twelve, and failure counts eight and three. Both samples contain fifteen trials, with observed proportions 7/15 and 12/15. The pooled Wald statistic is approximately −1.8943380761. Including exact mathematical score ties gives Barnard two-sided p≈0.0682183093. Some floating-score implementations return a slightly different result because they exclude a tied table through rounding.
Good to know
The total sample size is at most 40. Both columns must represent independent binomial experiments. Sampling-space counts and ordering comparisons use exact integer arithmetic, but nuisance maximization uses floating-point Bernstein subdivision. Its lower and upper estimates are numerical bounds with a roundoff allowance, not certified interval arithmetic. No unpooled Barnard statistic, mid-p correction or matched-pair analysis is implemented.
Reference: SciPy — Barnard unconditional test and nuisance maximization (opens in a new tab) ↗
Table orientation determines the binomial experiments
Each column is one sample. The first row records success and the second failure. Transposing an unlabelled worksheet can therefore change which totals are fixed and change the unconditional test. Less and greater compare the first column’s success probability with the second column’s. Define success and the direction of the alternative before looking for a favorable result.
Fisher’s exact test conditions additionally on the total number of successes. Barnard and Boschloo do not impose that extra conditioning; they consider its variation under the common success probability. This explains why their p-values can differ even for the same four recorded counts. The tests answer related inferential questions under distinct reference experiments, rather than providing interchangeable rounding variants of one calculation.
The Fisher exact two by two calculator conditions on both margins. These unconditional methods instead fix the two sample sizes and maximize over the common null success probability.
Exact enumeration still needs careful numerical maximization
For every possible pair of success counts, exact comparisons decide whether it belongs in the rejection set. Grouping contributions by total successes expresses the rejection probability as a Bernstein polynomial. Subdivision bounds that polynomial on successive subintervals and narrows the gap between a known attained value and an upper estimate. A coarse search grid alone could miss a peak between sampled probabilities.
Boschloo two-sided inference here follows twice the smaller one-sided unconditional p-value, clipped at one. Its displayed ordering statistic is the smaller one-sided Fisher p-value, not a Barnard z score or a two-sided Fisher p-value. Numerical bound estimates are displayed separately, so their precision is visible. The method can still be inappropriate when observations are paired; use a matched binary method for repeated outcomes on the same units.
A few questions, answered
Why maximize over a common probability?
The null specifies equal probabilities but not their shared value. Maximization considers the largest rejection probability across that nuisance parameter.
Why can Barnard differ slightly from SciPy?
This implementation retains mathematically equal Wald scores using exact integer comparisons. Direct floating comparisons can split such ties; numerical optimizer tolerances can also differ.