Fisher's exact test · r×c tables

Fisher–Freeman–Halton Calculator — Fisher's Exact Test for r×c Tables

This fisher freeman halton calculator runs Fisher's exact test on tables larger than 2×2 — 2×3, 3×3, 2×4 and any r×c contingency table up to the stated limits — by enumerating every table with your margins. It also reports the chi-square test, the G-test, Cramér's V and the expected counts for the same table, and it labels a simulated p-value as simulated in the result itself whenever a table is too large to enumerate.

Table 1. The r×c calculator. Add or remove rows and columns, type your counts, or paste a table; the row and column margins are held fixed, exactly as the test requires. Labels can be renamed.

Your table — add or remove rows and columns

Total
10
10
Total ——— 20

The grid grows from 2×2 to 6×6. A single zero cell is fine — the enumeration handles it. A whole row or column of zeros is a zero margin, and no test exists for that table.

Paste rows from a spreadsheet (tab-, comma- or space-separated, one row per line, up to 6×6) and the grid resizes to match.

Options

Examples:

The 2×3 worked example and the 3×3 example are constructed teaching examples, described as such in the text below. The 2×2 drug trial is the homepage's worked example — entered here, it returns the identical p-value, because both pages use the same definition.

Result — Fisher–Freeman–Halton test, two-sided by probability ordering

—

—

Your result — exact p-value and companion statistics

P(observed table)the multivariate hypergeometric probability of your exact table
—
Tables enumeratedevery table with your margins, counted in full
—
Grand total Nthe sum of all cells
—

Companion statistics for the same table — approximations, labelled as such

Pearson chi-square p
—
G-test p
—
Cramér's Veffect size for the r×c table, 0 (no association) to 1
—

Expected counts under independence

Your counts never leave your browser — the calculation runs on this page, and the share link encodes the table in the URL itself.

How to use the calculator

  1. Set the table's shape

    Use the add/remove row and column buttons until the grid matches your r×c contingency table — anything from 2×2 to 6×6 in the grid. Or paste the whole table from a spreadsheet and let the grid resize itself.

  2. Enter counts, not percentages

    Type the observed count in each cell and rename the row and column labels if it helps you read the result. The live totals check your margins as you type. Percentages cannot be tested — convert them back to counts with your group sizes first.

  3. Read the badge before the number

    The result opens with its badge. “Exact p-value — enumerated in full” means every table with your margins was counted. A headline reading “Simulated p-value (Monte Carlo, 10,000 replicates)” means the table exceeded the exact limits and the figure is an estimate from random tables — the word exact never appears on it.

  4. Read the p-value against your α

    The headline is the two-sided p-value by probability ordering. Compare it with the significance level you chose before seeing the data (0.05 by default), and read the verdict line for what that comparison does and does not say.

  5. Check the companions and the expected counts

    The same panel gives the chi-square test and G-test p-values, Cramér's V, the full expected-count table and the Cochran check for your table — so you can see whether an approximation would have been defensible, and how strong the association is, not only whether it is surprising.

What is the Fisher–Freeman–Halton test?

The Fisher–Freeman–Halton test is the extension of Fisher's exact test to a contingency table of any size — an r×c table with r rows and c columns. It asks the same question Fisher asked of a 2×2 table: if there were truly no association between the row variable and the column variable, and the row and column totals were held fixed, how surprising is the table you observed — counting every table with the same margins that is at least as unlikely? G. H. Freeman and J. H. Halton published the extension in 1951, and it is the test R's fisher.test and SciPy apply when the table is larger than 2×2.

How it extends Fisher's test beyond 2×2

Nothing about the logic changes — only the bookkeeping grows. In a 2×2 table, fixing the margins leaves one free cell, and the candidate tables form a single row of possibilities. In an r×c table there are (r − 1)(c − 1) free cells, and the candidates form a whole lattice of tables, each with its own probability. The two-sided p-value keeps the site definition used on every page here: probability ordering — sum the probabilities of all tables whose probability is at most the observed table's. A 2×2 table entered in this grid returns exactly the homepage's p-value for that table (0.0350 for the drug-trial example), because it is the same definition, not a re-implementation.

The multivariate hypergeometric distribution

Under the null hypothesis of independence, with the margins fixed, a table's probability is given by the multivariate hypergeometric distribution: P(T) = (∏ rᵢ! · ∏ cⱼ!) / (N! · ∏ xᵢⱼ!) — the product of the factorials of the row totals and the column totals, divided by the factorial of the grand total and the factorials of the individual cells. The image is the urn from the 2×2 case, generalised: deal N subjects into the columns in the observed column proportions, at random, and ask how often the rows come out looking like your table or stranger. When the counts are small, this exact calculation is the one to trust, because it never relies on a large-sample approximation.

How the exact p-value is computed — the Mehta–Patel network algorithm

Enumerating r×c tables naively is hopeless beyond small shapes: the number of tables with given margins grows explosively, and a 5×5 table can have millions of them. The calculation became practical with the network algorithm of Cyrus Mehta and Nitin Patel (1983), the method behind R's fisher.test for larger tables. Instead of listing tables one by one, the algorithm builds a network — a directed graph whose nodes are partial tables (the first few cells filled in, with the margins they must still meet) and whose paths are complete tables. Tables that share a partial beginning share the work: whole branches of the network are summed, or pruned as impossible, in a single step, and the probabilities are accumulated in log space so that tiny probabilities stay accurate.

This calculator follows the same idea at browser scale: it generates every table with your margins recursively, with feasibility pruning — a partial table is abandoned as soon as the remaining cells cannot meet the remaining margins — and computes each complete table's probability from the multivariate hypergeometric formula. Within the published limits below, the enumeration is complete: the count of tables found is printed in the result, and for the worked example you can audit all 42 of them yourself in the enumeration widget. “Exact” here describes how the null distribution is computed — by enumeration rather than approximation. It does not mean the conclusion is exactly right, and it says nothing about causation: an association in an observational table is an association, whatever test computed its p-value.

Exact vs simulated p-values — and how this tool labels them

An exact p-value is enumerated: every table with your margins is generated, its probability computed, and the counted probabilities summed. Run it twice and you get the identical number, digit for digit. A simulated p-value is estimated: a Monte Carlo procedure draws random tables with your margins — here, 10,000 replicates — and reports the fraction at least as extreme as yours. It is a good estimate, but it is an estimate: it carries sampling noise, and a different run (or a different replicate count) gives a slightly different figure. The two are not the same thing, and presenting a Monte Carlo estimate in the visual language of an exact result is the quiet dishonesty this page is built against.

So the labelling rule here is a policy, not a footnote. Within the exact limits, the result carries the badge “Exact p-value — enumerated in full” and prints the number of tables counted. Beyond them, the headline itself reads “Simulated p-value (Monte Carlo, 10,000 replicates)”, the replicate count is part of the result, and the word “exact” does not describe that result anywhere in the panel. Try both with the demo: the first button runs a 2×3 table inside the limits; the second runs a 6×6 table outside them, and the headline changes its words, not just its number. The mid-p value, a less conservative variant some packages offer, is not computed on this page at launch.

—

—

Table size limits — how large a table exact enumeration can handle

The published limits for this calculator. “Exact” means every same-margin table is enumerated; “Simulated” means a Monte Carlo estimate from 10,000 replicates, labelled simulated in the headline.
2×2Any N ≤ 200Exact enumerationExact p-value — enumerated in full
2×3 or 3×2Any N ≤ 200Exact enumerationExact p-value — enumerated in full
3×3Any N ≤ 200Exact enumerationExact p-value — enumerated in full
4×4Any N ≤ 200Exact enumerationExact p-value — enumerated in full
5×5N ≤ 200Exact enumerationExact p-value — enumerated in full
5×5N > 200Monte Carlo, 10,000 replicatesSimulated p-value (Monte Carlo, 10,000 replicates)
6×6 or largerAny NMonte Carlo, 10,000 replicatesSimulated p-value (Monte Carlo, 10,000 replicates)

The shape limit and the N limit are both stated because either one can bind: a sparse 5×5 table at N = 200 (the worked limit case, with margins 196, 1, 1, 1, 1) has only 209 same-margin tables and enumerates instantly, while a balanced 5×5 at the same N can have far more. The grid in this tool accepts up to 6 rows and 6 columns, so the simulated route is reachable — and visibly labelled — rather than hidden.

When to use it instead of chi-square

Use the Fisher–Freeman–Halton exact test when the expected counts are small enough that the chi-square approximation's error matters. The check is Cochran's rule in its exact two-part form (Cochran, 1954): the chi-square approximation is trustworthy when every expected count is at least 1 and at least 80% of cells have an expected count of at least 5, where each expected count is E = row total × column total ÷ N. The calculator runs this check live on your table and prints the verdict beside the expected counts — for the 2×3 worked example the smallest expected count is 2.5 and 0 of the 6 cells reach 5, so Cochran's rule is not met and the exact test is the defensible choice. When the counts are large and the rule is comfortably met, the chi-square test is accurate, faster to explain, and entirely appropriate — the companion statistics in the result panel let you compare the two on your own table rather than on a generic one.

Worked example — a 2×3 table, enumerated

Two clinics, three outcomes — [[4, 4, 2], [1, 4, 5]]

A constructed teaching example (not a real study): two clinics, Clinic A and Clinic B, each with 10 patients, classified as Recovered, Improved or No change. Clinic A: 4, 4, 2. Clinic B: 1, 4, 5. The margins are rows 10 and 10, columns 5, 8 and 7, grand total N = 20. The question is whether outcome is associated with clinic.

  1. Fix the margins: rows 10 / 10, columns 5 / 8 / 7, N = 20. Only tables with exactly these margins are candidates.
  2. Compute the observed table's probability from the multivariate hypergeometric formula, P = (10! · 10! · 5! · 8! · 7!) / (20! · 4! · 4! · 2! · 1! · 4! · 5!) = 0.039782.
  3. Enumerate every table with these margins: there are 42 of them. The widget below lists each one with its probability.
  4. Count the tables whose probability is at most 0.039782 (probability ordering) and sum their probabilities.
  5. Check the companions for the same table: χ² = 3.086 (df = 2, p = 0.2138), G = 3.256 (p = 0.1963), Cramér's V = 0.393 — and the expected counts (2.5, 4, 3.5 in each row), which fail Cochran's rule, confirming the exact test was the right tool.

The counted probabilities sum to the exact two-sided p-value 0.2892: at α = 0.05 there is no evidence of association between clinic and outcome in these data — a statement about compatibility with independence, not proof that the clinics are identical.

Enumeration. All 42 tables with the worked example's margins (rows 10 and 10; columns 5, 8 and 7; N = 20), each with its multivariate hypergeometric probability. Rows marked “counted” are the tables summed into the two-sided p-value.
TableP(table)Counted in two-sided p?
0 | 3 | 7
5 | 5 | 0
0.000303 Counted
0 | 4 | 6
5 | 4 | 1
0.002652 Counted
0 | 5 | 5
5 | 3 | 2
0.006365 Counted
0 | 6 | 4
5 | 2 | 3
0.005304 Counted
0 | 7 | 3
5 | 1 | 4
0.001516 Counted
0 | 8 | 2
5 | 0 | 5
0.000114 Counted
1 | 2 | 7
4 | 6 | 0
0.000758 Counted
1 | 3 | 6
4 | 5 | 1
0.010609 Counted
1 | 4 | 5
4 | 4 | 2
0.039782 Counted
1 | 5 | 4
4 | 3 | 3
0.053043 —
1 | 6 | 3
4 | 2 | 4
0.026521 Counted
1 | 7 | 2
4 | 1 | 5
0.004547 Counted
1 | 8 | 1
4 | 0 | 6
0.000189 Counted
2 | 1 | 7
3 | 7 | 0
0.000433 Counted
2 | 2 | 6
3 | 6 | 1
0.010609 Counted
2 | 3 | 5
3 | 5 | 2
0.063652 —
2 | 4 | 4
3 | 4 | 3
0.132607 —
2 | 5 | 3
3 | 3 | 4
0.106086 —
2 | 6 | 2
3 | 2 | 5
0.031826 Counted
2 | 7 | 1
3 | 1 | 6
0.003031 Counted
2 | 8 | 0
3 | 0 | 7
0.000054 Counted
3 | 0 | 7
2 | 8 | 0
0.000054 Counted
3 | 1 | 6
2 | 7 | 1
0.003031 Counted
3 | 2 | 5
2 | 6 | 2
0.031826 Counted
3 | 3 | 4
2 | 5 | 3
0.106086 —
3 | 4 | 3
2 | 4 | 4
0.132607 —
3 | 5 | 2
2 | 3 | 5
0.063652 —
3 | 6 | 1
2 | 2 | 6
0.010609 Counted
3 | 7 | 0
2 | 1 | 7
0.000433 Counted
4 | 0 | 6
1 | 8 | 1
0.000189 Counted
4 | 1 | 5
1 | 7 | 2
0.004547 Counted
4 | 2 | 4
1 | 6 | 3
0.026521 Counted
4 | 3 | 3
1 | 5 | 4
0.053043 —
4 | 4 | 2
1 | 4 | 5 (observed)
0.039782 Counted
4 | 5 | 1
1 | 3 | 6
0.010609 Counted
4 | 6 | 0
1 | 2 | 7
0.000758 Counted
5 | 0 | 5
0 | 8 | 2
0.000114 Counted
5 | 1 | 4
0 | 7 | 3
0.001516 Counted
5 | 2 | 3
0 | 6 | 4
0.005304 Counted
5 | 3 | 2
0 | 5 | 5
0.006365 Counted
5 | 4 | 1
0 | 4 | 6
0.002652 Counted
5 | 5 | 0
0 | 3 | 7
0.000303 Counted

In total: 42 tables, the observed table's probability is 0.039782, and the counted probabilities sum to the two-sided p-value 0.2892.

Fisher–Freeman–Halton vs chi-square vs G-test

Three tests of independence for the same r×c table — the worked example [[4, 4, 2], [1, 4, 5]], N = 20, df = 2 for both approximations.
Fisher–Freeman–Halton— (enumerates all 42 tables)0.2892Exact
Pearson chi-squareχ² = 3.0860.2138Approximation
G-test (likelihood ratio)G = 3.2560.1963Approximation

The approximations scatter around the exact answer and both understate it here — with a smallest expected count of 2.5, that gap is the approximation error Cochran's rule warns about. As counts grow, all three converge; when they disagree on a small table, the enumerated figure is the one to report, with the approximations, if shown at all, labelled as approximations.

What this test does not give you — no single odds ratio for r×c

Users arriving from 2×2 tools often hunt this result panel for an odds ratio. There isn't one, and the absence is mathematics, not a missing feature. The familiar odds ratio is the cross-product ad/bc of four cells; a 3×3 table has nine cells and several overlapping 2×2 sub-tables, each with its own cross-product, and no one of them summarises the association in the whole table. Software that prints a single “odds ratio” for an r×c table has silently picked one sub-table or one collapsing of your categories — a choice you never made. This tool therefore never computes or implies an odds ratio for a table larger than 2×2, and neither does it print a confidence interval for one.

What you can report instead: the exact p-value for the association itself, and Cramér's V as the effect size — V = √(χ² / (N · min(r − 1, c − 1))), which is 0 when the rows and columns are independent and 1 at the strongest association a table of this shape can show (0.393 for the worked example). If your question really is about one specific 2×2 contrast — one outcome against the rest, say — state that contrast, build that 2×2 table, and take it to the odds ratio calculator, where the sample odds ratio and the conditional-MLE estimate are both printed and labelled. And if your table is 2×2 from the start, the Fisher exact test calculator on the homepage gives the full 2×2 workup — both odds ratios, the exact confidence interval and the enumeration — for the same counts.

Sources & method notes

Freeman, G. H. & Halton, J. H. (1951). Note on an exact treatment of contingency, goodness of fit and other problems of significance. Biometrika, 38(1/2), 141–149 — the r×c extension this page is named for. Mehta, C. R. & Patel, N. R. (1983). A network algorithm for performing Fisher's exact test in r × c contingency tables. Journal of the American Statistical Association, 78(382), 427–434. Cochran, W. G. (1954). Some methods for strengthening the common χ² tests. Biometrics, 10(4), 417–451 — the expected-count rule, stated here in its two-part form. Method notes: the two-sided p-value is by probability ordering throughout, matching R's fisher.test on an r×c matrix and SciPy's r×c handling; exact enumeration is complete within the published limits (up to 5×5, N ≤ 200), and beyond them the Monte Carlo estimate (10,000 replicates, fixed margins, a seeded generator so the figure is reproducible) is labelled simulated in the headline itself. Paired data do not belong here — they route to McNemar's test — and stratified tables are Cochran–Mantel–Haenszel territory, named only, not calculated.

Frequently asked questions

Can Fisher's exact test be used for tables larger than 2×2?

Yes. Freeman and Halton extended Fisher's test to r×c tables in 1951: the margins are fixed, every table with those margins gets its multivariate hypergeometric probability, and the two-sided p-value sums the probabilities of the tables no more probable than yours (probability ordering). R's fisher.test implements exactly this for larger tables, and so does this calculator — within its published exact limits (up to 5×5, N ≤ 200); beyond them it reports a Monte Carlo estimate labelled simulated, never exact.

What is the Fisher–Freeman–Halton test?

It is Fisher's exact test generalised from a 2×2 table to an r×c contingency table, published by G. H. Freeman and J. H. Halton in 1951. The null hypothesis is independence between the row and column variables, conditional on the observed margins. For the 2×3 worked example on this page ([[4, 4, 2], [1, 4, 5]]), 42 tables share the margins, the observed table's probability is 0.039782, and the exact two-sided p-value is 0.2892.

How large a table can Fisher's exact test handle?

In principle any size; in practice the number of tables with given margins grows explosively, so exact enumeration needs the Mehta–Patel network algorithm (1983) and still runs out of room eventually. This calculator enumerates exactly up to 5×5 with N ≤ 200 — a sparse 5×5 at that limit has 209 same-margin tables — and beyond those limits it switches to a Monte Carlo estimate from 10,000 replicates, with the headline itself reading “Simulated p-value (Monte Carlo, 10,000 replicates)”.

Is a simulated p-value the same as an exact p-value?

No. An exact p-value is enumerated — every same-margin table is counted — so it is identical on every run. A simulated p-value is estimated from random tables with your margins (10,000 replicates here): it is close to the exact value but carries sampling noise, and a different run gives a slightly different number. One practical check: run the calculation twice. If the figure changes between runs, it is simulated, whatever the page calls it. This tool prints the word “simulated” and the replicate count in the headline result itself.

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

When the expected counts are small. Cochran's rule (1954), in its exact two-part form, says the chi-square approximation is trustworthy when every expected count is at least 1 and at least 80% of cells have an expected count of at least 5, with E = row total × column total ÷ N. The worked example fails it — smallest expected count 2.5, 0 of 6 cells at 5 — and its approximations (chi-square p = 0.2138, G-test p = 0.1963) both sit well below the exact 0.2892. When counts are large and the rule is comfortably met, chi-square is accurate and entirely appropriate.

Why is there no odds ratio for my 3×3 table?

Because the odds ratio is a four-cell quantity: ad/bc needs exactly a 2×2 table. A 3×3 table contains several different 2×2 sub-tables with different cross-products, and no single one of them is “the” odds ratio of the table. Report the exact p-value with Cramér's V as the effect size (0.393 for this page's worked example), or, if one specific 2×2 contrast is your real question, build that table and use the odds ratio calculator, where both odds-ratio estimators are printed and labelled.

Is my data uploaded anywhere?

No. Every calculation — enumeration, Monte Carlo sampling, the companion statistics — runs in your browser, on your device; the counts you type are never sent anywhere. If you use the share button, the table is encoded in the link itself and nothing is stored on a server, so only share links you are happy for the recipient to read.