Fisher's exact test

Statistics
Introduced by
R. A. Fisher
Year
1922
Type
Exact test of independence for categorical data

What does it do?

Fisher's exact test is a nonparametric test of independence for two categorical variables in a contingency table, most useful when the sample is small.

Instead of relying on a large-sample approximation, it computes the exact probability of the observed table under the null, using the hypergeometric distribution with the row and column totals held fixed. The test takes its name from R. A. Fisher and is also known as the Fisher–Irwin test.

The intuition behind the method

Sometimes you have two categorical variables cross-tabulated — for example treatment versus outcome — but the counts are too small for the chi-square test to be trustworthy. Fisher's exact test asks: holding the row and column totals fixed, how likely is it to see a table at least as lopsided as the one observed purely by chance? If that probability is tiny, the two variables are probably associated.

History

The test takes its name from R. A. Fisher and is also known as the Fisher–Irwin test. It is the standard exact method for categorical data and the usual small-sample alternative to the chi-square test of independence.

When to use it

Choose it to test whether two categorical variables are independent in a 2×2 or r×c contingency table, especially when the sample is small or expected cell frequencies fall below 5, the point at which the chi-square approximation becomes unreliable. The observations should be independent. Do not use it for paired binary data, such as the same subjects measured before and after treatment; the McNemar test in the related list is designed for that design. Because the test does not quantify effect size, pair it with an estimate such as the odds ratio for a 2×2 table. For tables larger than 2×2, only the two-sided p-value is available in common software, so the directional option applies only to 2×2 tables.

Limitations and considerations

  • Enumerating all tables with the observed margins becomes computationally heavy as the table grows or the total count increases.
  • Conditioning on fixed margins and working with discrete distributions can make the test conservative, so the actual false-positive rate may fall below the nominal level.
  • It tests association only and does not, on its own, give the size or direction of an effect.
  • For large samples it offers little advantage over the chi-square test, which is computationally lighter.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Gives an exact p-value that does not rely on a large-sample approximation, so it applies to small samples and sparse tables.
  • Does not depend on the expected-count requirement that limits the chi-square test at low counts.
  • Its exactness comes from the hypergeometric null distribution, which is conditioned on the observed margins.
  • Extends from the 2×2 case to r×c tables, although in common software only the two-sided p-value is available for tables larger than 2×2.

Applications

  • Testing association between a treatment and a binary outcome in small clinical trials.
  • Comparing proportions of an event across two groups when counts are low.
  • Analyzing rare-event 2×2 tables in epidemiology and laboratory studies.
  • Checking independence of two categorical survey items in small samples.

How it works

How it works

1

The null hypothesis states that the two categorical variables are independent, so the row classification gives no information about the column classification. The alternative states that they are associated.

Formula
H_0:\ \text{the two categorical variables are independent} \quad H_1:\ \text{they are associated}
2

Conditioning on the observed row and column totals, the probability of a single table with cells a, b, c and d follows the hypergeometric distribution. For a 2×2 table this is the closed-form ratio of factorials shown in the formula. This quantity is the probability of one specific arrangement, not a test statistic in the usual sense, and because it is computed exactly, no large expected counts are needed.

Formula
P(\text{table}) = \dfrac{\binom{a+b}{a}\binom{c+d}{c}}{\binom{n}{a+c}} = \dfrac{(a+b)!\,(c+d)!\,(a+c)!\,(b+d)!}{a!\,b!\,c!\,d!\,n!}
3

The p-value is the summed null probability of the observed table and of every other table with the same margins that is at least as extreme, in the direction set by the alternative hypothesis. For a one-sided test on a 2×2 table, this means the tables lying further in the stated direction. For the two-sided test, the standard convention is to add the probabilities of all tables with the same margins whose probability does not exceed that of the observed table. If the resulting p-value is below 0.05, the null hypothesis is rejected and a significant association is reported. A significant result indicates association but does not by itself measure how strong it is.

Formula
p = \sum_{T:\ \text{as or more extreme in the direction of the alternative}} P(T);\quad \text{reject } H_0 \text{ if } p < 0.05

Common pitfalls

  • Relying on the chi-square test when expected cell counts fall below 5; in that situation Fisher's exact test is the appropriate choice.
  • Reporting only the p-value without an effect measure such as the odds ratio for a 2×2 table.
  • Choosing a one-sided or two-sided p-value after seeing the data; for a 2×2 table the choice must be made in advance.

Frequently asked questions

When should I prefer it over the chi-square test?

Use Fisher's exact test when the sample is small or any expected cell frequency falls below 5, where the chi-square approximation is unreliable. For large samples with comfortably large expected counts, the chi-square test is the conventional and computationally lighter choice.

Does it work only for 2×2 tables?

No. The 2×2 case is the classic and simplest form, but the test generalizes to r×c contingency tables. Larger tables require summing probabilities over many more possible arrangements, and in common software such as R's fisher.test only the two-sided p-value is available for them.

One-sided or two-sided?

For a 2×2 table both are available. Use the two-sided p-value by default to test association in either direction, and reserve the one-sided version for a directional hypothesis stated before seeing the data.

What effect size should I report?

For a 2×2 table the odds ratio is the natural companion to the p-value, summarizing the strength and direction of the association. The p-value alone tells you only whether an association is detectable, not how strong it is.

Related methods

Sources

  1. Fisher, R. A. (1922). On the interpretation of chi-squared from contingency tables, and the calculation of P. Journal of the Royal Statistical Society, 85(1), 87–94.

    Open DOI reference
  2. 2015_Book_StatisticalAnalysisAndDataDisp, p. 545