ABWex / Tools / Exact contingency tables

Fisher–Freeman–Halton exact test calculator

Compare categorical outcomes across variants. Calculate an exact p-value, inspect the tables behind it, and compare the chi-square approximation.

Enter your observed counts

One row per variant or group; one column per mutually exclusive outcome. Each independent participant belongs in exactly one cell.

2–4 rows and 2–4 columns; at most 200 observations in total. Separate rows with newlines and counts with commas, tabs or spaces. Enter whole counts, including zeros. Every row and column must have a positive total.

Changes the interpretation, not the p-value. The decision uses the exact rational p-value and the rule p < α.

Example counts are ready. Run the test to calculate results.

The table dimensions do not guarantee a fast calculation. Limits: 100,000 feasible tables, 250,000 search nodes and 20 seconds; an incomplete run never produces an exact p-value.

Reproduce with R

The command uses your current valid table and requests calculation without simulation. It has not been executed by this page.

Independent synthetic checks

The reference script enumerates fixed-margin tables with Python rational arithmetic, then checks their probabilities against SciPy. The table below is generated from its fixture JSON; displayed decimals are rounded from the exact fractions. Read the independent reference and download the fixture data.

Reference results for the examples available in the calculator
Synthetic caseObserved rowsTotal countFeasible tablesTail tablesObserved probabilityExact p fractionExact p decimal
Sparse 2 × 31, 4, 0 / 3, 0, 2101361/635/630.07936507937
Moderate 2 × 38, 2, 1 / 1, 5, 421441945/167967/4420.01583710407
Balanced 2 × 32, 2, 2 / 2, 2, 212191918/7711
Diagonal 3 × 33, 0, 0 / 0, 3, 0 / 0, 0, 395561/16801/2800.003571428571
Mixed 3 × 32, 1, 0 / 0, 2, 1 / 1, 0, 2955369/56041/1400.2928571429
Asymmetric 3 × 34, 1, 0 / 1, 2, 1 / 0, 1, 21295561/15479/4620.170995671
Compatibility 2 × 21, 9 / 11, 32411410/742941/148580.002759456185

Read each observed row between the slash separators. The feasible-table count covers the whole fixed-margin reference set; the tail count covers tables included by the probability rule. The fraction columns preserve the rational reference values. Reference calculation source.

The browser implementation and reference script are separate implementations. The browser uses a bounded iterative search; the reference uses recursive enumeration and rational probabilities. Browser calculation source and Python verification source.

What the exact p-value sums

Fisher’s exact test for a general R-by-C contingency table is also called the Fisher–Freeman–Halton test. IBM SPSS Support

For a general contingency table, the null model fixes the row and column sums and assumes independence between the row and column categories. SciPy

The probability-ordering tail sums the probabilities of tables whose probability is at most the observed-table probability, including ties. R Core Team

The probability calculation

SciPy evaluates the table log probability as the sum of row and column log-factorials minus the grand-total log-factorial and all cell log-factorials. SciPy maintainers

P(T) = (∏ row-total! × ∏ column-total!) / (N! × ∏ cell-count!)

The calculator compares integer factorial products to decide probability ties and uses numerical log-factorials for probability values. It withholds the exact p-value when enumeration is incomplete or the numerical checks fail. Inspect the calculation code.

Compare the chi-square approximation

Under independence, a cell’s expected count is its row total multiplied by its column total and divided by the grand total. Penn State Department of Statistics

Pearson’s statistic is the sum over cells of the squared observed-minus-expected count difference divided by the expected count. Penn State Department of Statistics

For an I-by-J independence table, the chi-square reference degrees of freedom are (I−1)(J−1). Penn State Department of Statistics

For small two-way table totals, the usual asymptotic chi-square p-value can be inaccurate. SciPy

The result panel labels Pearson’s p-value as an approximation without continuity correction. Expected-count flags help you inspect the table. Don’t select a method because its result is more favorable. Inspect the result display.

Read the result in context

A p-value does not give the probability that either tested hypothesis is true. Penn State Department of Statistics

Statistical significance alone does not imply an association or effect is important. American Statistical Association

Residuals can be examined to identify which cells are particularly revealing of an association. Penn State Department of Statistics

Common questions

Can I enter zero counts?

Contingency-table entries for this exact test must be nonnegative integers. SciPy

A sampling zero is an observed empty cell. Penn State Department of Statistics

Structural zeros represent theoretically impossible observations. Penn State Department of Statistics

Zero cells are accepted. The calculator rejects an empty row or column and asks you to remove that empty category. Structural-zero constraints are outside this tool’s scope. Input validation.

Why was the exact result withheld?

An exhausted search budget produces an incomplete result. A completed search that fails numerical verification produces a separate failure state. Neither state publishes an exact p-value. Completion and numerical checks.

Use the R command above to reproduce your entered table. The command requests calculation without simulation; it has not been run by this page. R command generator.

Paired and repeated observations

The fixed-margin table distribution models independent samples. SciPy

Treating correlated samples as independent can introduce large errors into the analysis. Penn State Department of Statistics

Use a model suited to your observation design before interpreting this test.

Inspecting the p-value

A completed result shows the observed-table probability, feasible-table count, included-tail count and probability-mass checksum. The display shows up to 12 tail examples and is complete when the tail has 12 or fewer tables. Download the JSON certificate for the inputs, method, limits and calculated result. Result and certificate code.

Assumptions and limits

Results assume independent observations and fixed row and column margins.

A p-value is not the probability that the null hypothesis is true.

Statistical significance does not measure the size or business value of an effect.

Synthetic examples illustrate the calculation and are not observed customer data.

Counts are passed to a worker in your browser. The supplied calculator code does not upload entered counts. Worker source and Interface source.