Fisher's Exact Test for a 2 by 2 Table

A 2 by 2 contingency table cross-classifies observations by two categorical variables. Fisher's exact test evaluates whether the row and column classifications are associated, and it is especially valuable when the sample is small enough that the chi-square approximation to the sampling distribution of the test statistic becomes unreliable.


The usual working rule is that the chi-square approximation needs every expected cell count to be reasonably large (a common classroom threshold is an expected count of at least 5 in each cell); when that fails, an exact conditional calculation is the safer choice.


The key idea is to condition on the observed row and column totals, called the margins.

A 2 by 2 contingency table with its four cell counts, both sets of margin totals, and the grand total labelled.

A 2 by 2 contingency table with its four cell counts, both sets of margin totals, and the grand total labelled.


With fixed margins under the null hypothesis of no association, the count in one cell follows a hypergeometric distribution. If the first row has total n1n_1, the first column has total m1m_1, the grand total is NN, and the upper-left cell is aa, then P(A=a)=(m1a)(N−m1n1−a)(Nn1)P(A=a)=\dfrac{\binom{m_1}{a}\binom{N-m_1}{n_1-a}}{\binom{N}{n_1}}. The other three cell counts are determined once aa and the margins are fixed.

How a p-value is assembled

First state the alternative before looking at the table. For a one-sided alternative that the first group has a higher success chance, add the probabilities of all tables whose upper-left count is at least as large as the observed one.


For a two-sided Fisher p-value, a common convention adds the probabilities of every fixed-margin table whose probability is no greater than that of the observed table. State the convention you used, because two-sided definitions differ across software.

A worked probability

Suppose a pilot study yields N=13N=13 subjects, a first row total of n1=7n_1=7, a first column total of m1=6m_1=6, and an upper-left count of a=5a=5. Then P(A=5)=(65)(72)(137)=6×211716=1261716≈0.0734P(A=5)=\dfrac{\binom{6}{5}\binom{7}{2}}{\binom{13}{7}}=\dfrac{6\times 21}{1716}=\dfrac{126}{1716}\approx 0.0734. That single number is the probability of one table, not a p-value; a p-value still requires summing over the tail that the stated alternative defines.

Scope, and what the test is not

Two boundaries are worth fixing early. First, an exact conditional test is not restricted to two rows: the same conditioning argument extends to an r×cr \times c table through the multivariate hypergeometric distribution (software often calls this the Fisher-Freeman-Halton test), so the number of rows is not what decides whether you need an exact test.


Second, Fisher's test assumes the two groups are independent samples. Binary outcomes measured twice on the same subjects are paired, and those data call for McNemar's test on the discordant pairs instead.


A common mistake is to use a rank test for these counts or to ignore the fixed margins. Fisher's method is conditional: it asks how unusual the observed allocation is among the allocations compatible with the margins.

A researcher cross-classifies a small sample of independently recruited subjects by treatment group and by a yes/no outcome, producing a 2 by 2 contingency table. In which situation does the usual chi-square test of association become unreliable, so that Fisher's exact test is the better choice?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A 2 by 2 table is laid out as in the figure, with cell counts aa, bb, cc, dd, row totals R1R_1 and R2R_2, and column totals C1C_1 and C2C_2. When Fisher's exact test builds its null reference distribution, which quantities are held fixed?

A 2 by 2 contingency table with its four cell counts, both sets of margin totals, and the grand total labelled.

A 2 by 2 contingency table with its four cell counts, both sets of margin totals, and the grand total labelled.

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Group A has 33 successes and 11 failure; group B has 11 success and 33 failures. Under fixed margins and the one-sided alternative that group A has the higher success probability, what is the Fisher exact p-value?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors