Solution (source code)

= Solution

For a <two-by-two contingency table>, <Fisher's exact test> conditions on both row totals and both column totals. Under the null of no association, the upper-left count $K$ then has the <hypergeometric distribution>
$$
\mathbb P(K=k\mid\text{margins})
=\frac{\binom{c_1}{k}\binom{n-c_1}{r_1-k}}{\binom n{r_1}},
$$
where $r_1$ and $c_1$ are the first row and column totals. A one-sided p-value sums the appropriate hypergeometric tail; a common two-sided p-value sums the probabilities of all feasible tables no more likely under the null than the observed table. Because the conditional distribution is discrete, the p-value is <super-uniform random variable> rather than generally exactly uniform.