Biostatistics Study NotesFrom concepts and derivations to interpretation

CHAPTER 05 · TOPIC 06

Fisher’s Exact Test

Use hypergeometric probabilities with fixed marginal totals to perform an exact test for a small-sample 2×2 table.

On this page
  1. With Fixed Marginal Totals, Only One Cell Is Free
  2. Exact Probability of the Observed Table
  3. One-Sided p-Value
  4. Two-Sided p-Value
  5. Steps to enumerate all tables
  6. Comparison of Pearson, Yates, and Fisher

Fisher's exact test calculates the probability of each table meeting the null hypothesis directly from the hypergeometric distribution, under the condition that the marginal frequencies of the rows and columns of the 2 × 2 table are fixed. It does not rely on large-sample approximations, so it is important for small samples or when expected frequencies are small.

With Fixed Marginal Totals, Only One Cell Is Free#

marginal totalR1=a+b,R2=c+d,C1=a+c,C2=b+dR_1=a+b,\quad R_2=c+d,\quad C_1=a+c,\quad C_2=b+d
Determine other cells from ab=R1a,c=C1a,d=R2C1+ab=R_1-a,\quad c=C_1-a,\quad d=R_2-C_1+a
minimum value of aamin=max(0,R1C2)a_{\min}=\max(0,R_1-C_2)
maximum value of aamax=min(R1,C1)a_{\max}=\min(R_1,C_1)

Exact Probability of the Observed Table#

hypergeometric probabilityP(A=aR1,R2,C1,C2)=(C1a)(C2R1a)(NR1)P(A=a\mid R_1,R_2,C_1,C_2)=\frac{\binom{C_1}{a}\binom{C_2}{R_1-a}}{\binom{N}{R_1}}
factorial displayP(a,b,c,d)=R1!R2!C1!C2!a!b!c!d!N!P(a,b,c,d)=\frac{R_1!R_2!C_1!C_2!}{a!b!c!d!N!}

The denominator is how to choose R₁ items that go into the first row out of N items. The combination of selecting a pieces from the first column and R₁−a pieces from the second column becomes the numerator, and the probability of a table that maintains the marginal frequency is obtained.

(C1a)(C2b)(NR1)=R1!R2!C1!C2!a!b!c!d!N!\frac{\binom{C_1}{a}\binom{C_2}{b}}{\binom{N}{R_1}}=\frac{R_1!R_2!C_1!C_2!}{a!b!c!d!N!}

One-Sided p-Value#

right sidepright=aaobsP(A=amargins)p_{\mathrm{right}}=\sum_{a\geq a_{\mathrm{obs}}}P(A=a\mid\text{margins})
leftpleft=aaobsP(A=amargins)p_{\mathrm{left}}=\sum_{a\leq a_{\mathrm{obs}}}P(A=a\mid\text{margins})

Which tail supports the alternative hypothesis is determined by the row/column arrangement and the predetermined direction of the effect. Don't look at the data and choose the smaller one-sided p-value.

Two-Sided p-Value#

ptwo-sided=T:P(T)P(Tobs)P(T)p_{\mathrm{two\text{-}sided}}=\sum_{T:\,P(T)\leq P(T_{\mathrm{obs}})}P(T)

Steps to enumerate all tables#

  1. Calculate R₁, R₂, C₁, C₂, N from the observation table
  2. Enumerate possible a from a_min to a_max
  3. Calculate b, c, d and hypergeometric probability for each a
  4. Define one-sided or two-sided extreme tables depending on alternative hypothesis
  5. Sum the corresponding probabilities to get the p-value

Comparison of Pearson, Yates, and Fisher#

methodstatistical foundationsapproximationTypical use
Pearson χ²Σ(O−E)²/Echi-square approximationsufficient expectation
Yates χ²Σ(|O−E|−0.5)²/ECorrected chi-square approximationSmaller 2×2 table, conservative reasoning
Fisher accurateconditional hypergeometric distributionUnnecessarySmall sample/sparse 2×2 table

Even though the p-value of the Fisher test is accurate, it does not mean that there is no uncertainty in the effect estimate. Report the OR, appropriate confidence interval, and cell frequency, understanding that it is a conditional inference.