Fisher’s Exact Test Calculator

Enter the four counts of a 2 × 2 table to get the exact p-value for an association between two yes/no variables. Fisher’s exact test needs no large-sample approximation, so it is the test to use when counts are small or an expected count is below 5. The calculator matches R’s fisher.test: two-sided and one-sided p-values, the conditional maximum likelihood odds ratio and its exact confidence interval.

Counts

2 × 2 table of counts
Total
10
6
Total9716

Type over the labels to rename the groups and outcomes.

Confidence level

Load a worked example

Fisher’s exact test, two-sided

0.0350p-value

The association is statistically significant at α = 0.05. N = 16.

Two-sided p
0.0350
One-sided p (OR < 1)
0.9991
P(top-left ≤ observed)
One-sided p (OR > 1)
0.0245
P(top-left ≥ observed)
Conditional MLE odds ratio
15.466
as reported by R
95% exact CI
1.009 to 1059.639
Sample odds ratio (ad/bc)
20.000

Every table with the same margins

Bars show the probability of each possible top-left count under no association. Dark bars are tables at most as likely as yours; their sum is the two-sided p-value.

a = 3your table: a = 8a = 9

Report it like this

Fisher’s exact test, p = .035 (two-sided), conditional OR = 15.47, 95% CI 1.01 to 1059.64.

How to use the calculator

  1. Enter the four counts. Put the groups in the rows (for example treatment and placebo) and the outcome in the columns (responded and did not respond). Each person is counted once.
  2. Rename the rows and columns by typing over the labels, so the table matches your study.
  3. Read the two-sided p-value. Use a one-sided p-value only if you stated the direction before seeing the data.
  4. Copy the report sentence under the results.

The test answers one question: are the row and column variables associated? It does not care which variable you put in the rows. For tables bigger than 2 × 2, use the chi-square calculator.

Fisher’s exact test or chi-square?

The chi-square test relies on an approximation that works when expected counts are large enough. The usual rule (Cochran 1954) is that no expected count should be below 1 and no more than 20% should be below 5. In a 2 × 2 table that means every expected count should be at least 5. If it is not, report Fisher’s exact test.

  • Small samples: use Fisher’s exact test. It gives an exact p-value whatever the counts.
  • Large samples: both tests give nearly the same p-value. Chi-square is quicker to describe; Fisher’s test is still valid.
  • A zero cell: Fisher’s test handles it without any correction. The odds ratio is then 0 or infinite, but its exact interval is still defined on one side.

Fisher’s test treats the row and column totals as fixed. When they are not fixed by design, it is slightly conservative (its p-values tend to be a little too large), which is why some statisticians prefer the mid-p version. Most journals accept the standard test.

How the p-value is calculated

Label the table a, b (first row) and c, d (second row), with row totals R₁, R₂, column totals C₁, C₂ and total N. With the totals fixed, the top-left count a decides the whole table, and under no association it follows the hypergeometric distribution:

P(a) = C(R₁, a) × C(R₂, C₁ − a) / C(N, C₁)

where C(n, k) is the number of ways to choose k items from n. The two-sided p-value adds up the probabilities of every possible table that is no more likely than the one observed. This is the method used by R’s fisher.test, SciPy and SPSS. Some older software doubles the one-sided p-value instead, which can give a slightly different answer.

The one-sided p-values add the probabilities of tables with a top-left count at least as small (odds ratio below 1) or at least as large (odds ratio above 1) as yours.

The odds ratio shown is the conditional maximum likelihood estimate, the value R reports. It is close to the sample odds ratio ad/bc but shrunk slightly towards 1. Its confidence interval is found by inverting the two one-sided exact tests, so it agrees with the p-value.

Worked example

In a small trial, 8 of 10 patients on treatment and 1 of 6 on placebo responded (the default table). The row totals are 10 and 6, the column totals 9 and 7, and N = 16.

  • The top-left count can range from 3 to 9. There are C(16, 9) = 11,440 ways to pick the 9 responders.
  • The observed table (a = 8) has probability C(10, 8) × C(6, 1) / 11,440 = 270 / 11,440 = .0236.
  • Tables at most that likely are a = 8 (.0236), a = 9 (10 / 11,440 = .0009) and a = 3 (120 / 11,440 = .0105).
  • Two-sided p = 400 / 11,440 = .035. One-sided p (more responders on treatment) = .024.
  • Conditional odds ratio 15.47, 95% CI 1.01 to 1059.64. The sample odds ratio is (8 × 5) / (2 × 1) = 20.

Here the expected count for placebo responders is 6 × 9 / 16 = 3.4, below 5, so Fisher’s test is the right choice. The very wide interval shows how little 16 patients can say about the size of the effect.

In Fisher’s own tea-tasting experiment, a lady tasted 8 cups and picked the 4 with milk poured first. Getting 3 of 4 right gives a one-sided p of 17/70 = .243 and a two-sided p of .486: not enough evidence. Only a perfect score (p = 1/70 = .014, one-sided) would have been.

How to report Fisher’s exact test

Give the counts or percentages in each group, name the test and say whether the p-value is two-sided. Add the odds ratio and its interval if your journal asks for an effect size:

Response was more common with treatment (8 of 10, 80%) than with placebo (1 of 6, 17%; Fisher’s exact test, two-sided p = .035; conditional odds ratio 15.47, 95% CI 1.01 to 1059.64).

For the odds ratio with a Woolf interval, the relative risk and the number needed to treat from the same table, use the odds ratio calculator. To plan how many participants you need, see the power analysis calculator.

Questions

When should I use Fisher’s exact test instead of chi-square?
Use Fisher’s exact test for a 2 × 2 table when any expected count is below 5, or whenever the sample is small. It gives an exact p-value without relying on a large-sample approximation. With large samples the two tests agree closely, so either is acceptable.
How is the two-sided p-value of Fisher’s exact test calculated?
Every table with the same row and column totals is listed, and its probability is computed from the hypergeometric distribution. The two-sided p-value is the sum of the probabilities of all tables that are no more likely than the observed one. R, SciPy and SPSS use this method.
Can Fisher’s exact test be used for larger tables?
Yes, the Fisher–Freeman–Halton extension works for larger tables, but it is slow for big samples and not offered here. For tables larger than 2 × 2, use the chi-square test if expected counts are large enough, or merge categories that make sense together.
Why is the odds ratio different from ad/bc?
The calculator reports the conditional maximum likelihood odds ratio, as R does. It is estimated from the hypergeometric distribution and is pulled slightly towards 1 compared with the sample odds ratio ad/bc. The sample odds ratio is shown too. With large counts the two are almost the same.
Does Fisher’s exact test work with a zero cell?
Yes. A zero cell is not a problem for the p-value. The odds ratio is then 0 or infinite, and only one end of its confidence interval is finite, which the calculator shows.
Should I report a one-sided or two-sided p-value?
Report the two-sided p-value unless you specified the direction of the effect before collecting the data and an effect in the other direction would have been treated as no effect. Most journals expect two-sided tests.

Sources