🏆 US-Registered Digital Marketing Agency
Advertisement
Advertisement
STATISTICS

Fisher's Exact Test Calculator — 2x2 tables, one and two tailed

Enter the four counts of a 2x2 contingency table and get the exact hypergeometric p-value, both one-tailed versions, the odds ratio and the chi-square comparison.

The table is read as two rows (the groups) by two columns (the outcome). Counts must be whole numbers of subjects, never percentages or averages.
Used only to label the result. Choose it before you look at the data, not after.
Two-tailed exact p-value
 
One-tailed p (greater)
One-tailed p (less)
Sample odds ratio
Chi-square p for comparison
Advertisement

The Fisher's exact test calculator above computes the exact probability of a 2x2 contingency table, and every table at least as extreme, under the null hypothesis that the row and column classifications are independent. It reports the two-tailed p-value, both one-tailed versions, the sample odds ratio, the expected cell counts, and — deliberately — the chi-square p-value you would have got instead, so you can see the size of the difference on your own numbers.

Arb Digital built this page because of a specific and very common failure. Our chi-square calculator is the large-sample approximation to this test, and it is the tool almost everyone reaches for. It is fast, it generalises to bigger tables, and it is perfectly good when the counts are large. But it is an approximation whose accuracy depends on the expected counts being reasonably big, and when they are not, it produces p-values that are too small — which is to say, it declares significance that is not there. Fisher's exact test does not approximate anything. That is the entire reason this page exists.

What This Fisher's Exact Test Calculator Does

It enumerates every 2x2 table with the same row and column totals as yours, computes the exact hypergeometric probability of each one, and sums the probabilities of the tables that count as at least as extreme as what you observed. Because it enumerates rather than approximates, the p-value is correct for any counts, including zeros, and there is no minimum sample size below which it stops being valid.

It also reports the expected count for each cell and flags any that fall below five, which is the conventional threshold at which the chi-square approximation becomes unreliable. Where that flag appears, the chi-square p-value shown alongside is not a second opinion — it is the wrong answer, displayed so you can see how wrong.

The test is restricted to 2x2 tables here. Exact tests for larger tables exist but the enumeration grows explosively, and the usual practical route is a simulated exact test rather than complete enumeration.

How to Use It

  1. Lay the table out as two groups by two outcomes. Row one is the first group, row two the second; column one is the outcome occurring, column two the outcome not occurring.
  2. Enter counts of subjects. Never percentages, never rates, never averages. The exact test is built on whole units and a proportion tells it nothing about sample size.
  3. Read the two-tailed p first. It is the appropriate answer unless you committed to a direction before collecting the data.
  4. Check the expected counts panel. If any expected value is below five, the chi-square figure next to it should be ignored entirely.
  5. Look at the distribution bars. They show every possible table given your margins, with the observed one marked, which makes the meaning of "as extreme or more" concrete.

The Formula and How It Is Calculated

Condition on the row totals and column totals, treating them as fixed. Under independence, the count in the top-left cell then follows a hypergeometric distribution, and the probability of any particular table is P = (r1! r2! c1! c2!) / (N! a! b! c! d!), where r and c are the row and column totals and N is the grand total. This is the same expression our hypergeometric distribution calculator evaluates for sampling without replacement, which is exactly what a fixed-margin table describes.

The one-tailed p-values are the sums of P over all tables with a top-left count at least as large, or at least as small, as the observed one. The two-tailed p-value uses the standard definition: sum P over every possible table whose probability is less than or equal to the probability of the table you observed. Note that this is not double the smaller one-tailed value; because the hypergeometric distribution is generally asymmetric, doubling gives a different and occasionally impossible answer above one.

The calculator works in log-factorial space using a Lanczos approximation to the gamma function, so it stays accurate with totals in the thousands where direct factorials would overflow immediately. The NIST/SEMATECH e-Handbook sets out the same construction in its section on determining whether two processes produce the same proportion of defectives, describing the test as suited to analysing discrete data when the two independent samples are small.

Advertisement

Why Chi-Square Fails on Small Expected Counts

The chi-square statistic compares observed counts to expected counts and refers the result to a continuous chi-square distribution. Counts are discrete, so the reference distribution is an approximation to a lumpy reality, and the quality of that approximation depends on how many possible outcomes there are. With large expected counts the discrete distribution has many closely spaced steps and the smooth curve fits well. With small expected counts it has a handful of widely spaced steps and the smooth curve does not fit at all.

The error is not random, it is directional. The chi-square approximation systematically puts too much probability in the tail, so the p-value comes out too small and the test rejects the null hypothesis more often than its stated alpha allows. A test run at a nominal five percent can have a real error rate well above that on sparse tables. The conventional guard is that every expected count should be at least five, and the default example on this page has expected counts of exactly two in all four cells.

Look at what that does. The default table returns an exact two-tailed p of 0.486 and a chi-square p of 0.157. One of those crosses no threshold at all and the other is close enough to a five percent cut-off that a researcher might be tempted to describe it as a trend. They come from the same eight observations. Yates' continuity correction exists to patch the chi-square in this situation and pulls it back toward the exact answer, but it overcorrects in the other direction and remains an approximation. When the exact answer is computable in milliseconds, there is no reason to accept an approximation to it.

Why Fisher's Test Is Conservative

Exactness comes at a price worth understanding. Because the number of possible tables is finite, the achievable p-values are a discrete set. There may be no table whose p-value is exactly 0.05, so a test conducted at a nominal five percent level actually operates at whatever achievable value sits just below five percent. Its true rejection rate is therefore usually less than alpha rather than equal to it.

This makes the test conservative: it under-rejects, and so it has somewhat lower power than a test that could hit its nominal level exactly. Some statisticians regard this as a flaw and prefer alternatives such as mid-p adjustments or the unconditional exact tests that do not fix both sets of margins. Others regard being conservative as clearly preferable to being anti-conservative, which is what the chi-square approximation is on the same data. Whichever position you take, conservatism is a known and bounded property, while the chi-square error on a sparse table is neither.

Reading the Odds Ratio Alongside the P-Value

The p-value says whether the association is distinguishable from chance. It says nothing about size, and on small tables it is capable of being unimpressive for a very large effect. The sample odds ratio, ad/bc, is the effect measure that belongs beside it, and the default table has an odds ratio of 9 with a p-value near 0.49 — a huge apparent effect that eight observations cannot establish.

Two cautions. First, the sample odds ratio is undefined when any cell is zero, and adding 0.5 to every cell is a common but arbitrary patch that changes the number you report. Second, the conditional maximum likelihood odds ratio that accompanies a formal Fisher's test differs slightly from the simple ad/bc ratio; this page reports the simple version, which is what most write-ups mean by the odds ratio. Our p-value calculator covers the interpretation of the probability itself, and our sample size calculator is the tool to reach for when a result like this tells you the study was simply too small.

A Worked Example You Can Check Yourself

The default is the structure of Fisher's original tea-tasting experiment: eight cups, four of each preparation, four guesses of each kind, and three of the four guesses correct. The table is a = 3, b = 1, c = 1, d = 3, so every margin totals four and N is eight.

There are five possible tables given those margins, indexed by the top-left count from 0 to 4. Their probabilities are 1/70, 16/70, 36/70, 16/70 and 1/70, since the total number of ways to choose four items from eight is 70. The observed table has a = 3, with probability 16/70 = 0.2286. The one-tailed p in the greater direction is (16 + 1)/70 = 17/70 = 0.2429.

For the two-tailed value, collect every table whose probability is at most 0.2286: that is a = 0, 1, 3 and 4, giving (1 + 16 + 16 + 1)/70 = 34/70 = 0.4857. Meanwhile the uncorrected chi-square statistic is N(ad − bc)2/(r1r2c1c2) = 8 × 64/256 = 2.0, which on one degree of freedom gives p = 0.157. The exact test says three correct guesses out of four proves nothing; the approximation says it is nearly interesting. Penn State's STAT 504 Analysis of Discrete Data course covers Fisher's exact test alongside the small-sample inference problem it solves. If you need probabilities for repeated independent trials rather than a fixed-margin table, our binomial distribution calculator is the right model, and our probability calculator handles the underlying combinatorics.

Running tests on small samples?

Arb Digital's analysts pick the test that is valid for the data in front of them, rather than the one the reporting tool happens to offer.

Browse All Free Tools Talk To Our Team

Common Mistakes to Avoid

  • Entering percentages instead of counts — the exact test is built entirely on whole units, and a percentage carries no information about how many observations produced it.
  • Doubling the one-tailed p to get the two-tailed one — the hypergeometric distribution is asymmetric, so doubling gives a different value and can exceed one.
  • Choosing the one-tailed test after seeing the direction — a tail selected once the data is in halves the p-value without any corresponding evidence.
  • Quoting the chi-square result when expected counts are small — the approximation is anti-conservative there, so it reports significance the data does not support.
  • Reporting a p-value with no effect measure — the odds ratio and the counts themselves say how large the difference is, which the p-value never does.

Related Free Tools From Arb Digital

Use the large-sample approximation on bigger tables with the chi-square calculator, work with the underlying distribution through the hypergeometric distribution calculator, interpret the probability itself with the p-value calculator, model independent trials with the binomial distribution calculator, plan a study that can actually detect the effect with the sample size calculator, or handle the combinatorics with the probability calculator. The free online tools hub lists every statistics tool we publish.

Frequently Asked Questions

When should I use Fisher's exact test instead of chi-square?

Whenever any expected cell count is small, conventionally below five, and for any 2x2 table where an exact answer is available. The chi-square version is an approximation that becomes anti-conservative on sparse tables, meaning it reports significance the data does not support.

What makes the test exact?

It enumerates every possible table with the same row and column totals and adds up the true probabilities of the ones at least as extreme as yours. Nothing is approximated by a continuous distribution, so the p-value is correct for any sample size.

Can I use Fisher's exact test on tables larger than 2x2?

Exact tests for larger tables exist, but complete enumeration becomes impractical very quickly. Statistical packages usually offer a simulated exact test in that situation, and this calculator is restricted to the 2x2 case.

Why is the two-tailed p not just twice the one-tailed p?

Because the hypergeometric distribution is generally asymmetric. The standard two-tailed definition adds the probabilities of every table no more likely than the observed one, which usually differs from doubling and never exceeds one.

What does it mean that the test is conservative?

The set of achievable p-values is discrete, so a test run at a nominal five percent usually operates at some slightly lower true level. It rejects the null hypothesis less often than the stated alpha, which costs a little power but never overstates the evidence.

Can I run the test if one cell is zero?

Yes. The exact test handles zero cells without difficulty, which is one of its advantages. The sample odds ratio is undefined in that case, so this page reports it as unavailable rather than patching the counts.

Should I use the one-tailed or the two-tailed p-value?

Use the two-tailed value unless you specified a direction before collecting the data and genuinely have no interest in an effect the other way. Selecting a tail after seeing the result is not a valid one-tailed test.

This page explains a statistical calculation for educational purposes only. It is not medical, legal or research advice, and a p-value from any test cannot establish that one treatment or condition causes an outcome.

Advertisement
Advertisement

Take it further