Skip to content

EProportions · Guide test 061

Fisher–Freeman–Halton exact test

Extends Fisher conditional testing to larger rectangular contingency tables.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Fisher–Freeman–Halton exact test

30
0.60

0 = rows and columns independent.

0.050

Your data

Edit the counts
LowMidHighTotal
Row A
4E = 2.3
2E = 3.3
4E = 4.3
10
Row B
3E = 4.7
8E = 6.7
9E = 8.7
20
Total7101330

E is the count expected if rows and columns were unrelated.

If H₀ were true

−ln P = 3.28
  1. The reference: how −ln P varies across samples when H₀ is true, every table with these margins (60) (exact: enumerated over every table with the observed margins).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .252).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

p=∑T: P(T)≤P(Tobs)P(T),P(T)=∏iri! ∏jcj!N! ∏ijtij!p=\sum_{T:\,P(T)\le P(T_{obs})} P(T),\quad P(T)=\dfrac{\prod_i r_i!\,\prod_j c_j!}{N!\,\prod_{ij} t_{ij}!}

With your numbers

P(Tobs)=0.04,tables=60P(T_{obs}) = 0.04,\qquad \text{tables} = 60
P(T)P(T)
hypergeometric probability of a table with the observed margins
ri, cjr_i,\ c_j
row and column totals, held fixed

The verdict

−ln P = 3.28, p = .252

p > α = .050: compatible with H₀

Fisher's exact test beyond 2 × 2: every table with the same margins is enumerated and the improbable ones add up to p. Conditioning on both margins makes it conservative for discrete data.

Statistic
3.284
p-value
0.2525
Fisher–Freeman–Halton exact test on a 2 × 3 table of 30 counts: −ln P = 3.28, p = .252. The p-value is above α = .050, so the data are compatible with H0.

Fisher–Freeman–Halton exact test on a 2 × 3 table of 30 counts: −ln P = 3.28, p = .252. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: row and column categories are independent in an r×c table.

Assumptions

Independent units; fixed margins or appropriate conditioning; no unmodeled structural zeros.

Formula

P(T∣margins)=∏iri!∏jcj!N!∏ijtij!P(T\mid\text{margins})=\frac{\prod_i r_i!\prod_j c_j!}{N!\prod_{ij}t_{ij}!}

Parameters and notation

T is a feasible nonnegative table with row totals ri and column totals cj.

Structure of the method

Extend conditional table enumeration to r-by-c tables with fixed margins. Each feasible table receives its multivariate hypergeometric probability; a probability-ordering rejection region sums tables no more probable than the observed one. Network algorithms reduce enumeration cost without changing the conditional sample space.

Estimated and nuisance parameters

No unconstrained marginal probabilities need estimation after conditioning. The row and column totals determine the sample space. In larger tables, a single odds ratio is not a complete association parameter; estimated cell residuals or model contrasts are supplementary summaries.

Settings and design choices

Specify exact enumeration, a hybrid approximation, or Monte Carlo sampling, including workspace and replicate limits. These are computational controls with different guarantees. Fix the table-extremeness ordering and category handling; ordinary 2-by-2 directional alternatives do not automatically generalize.

Fitting and adaptation

A new table needs a new fixed-margin distribution. For Monte Carlo inference, draw admissible tables under that distribution, count extremeness consistently, and include the usual observed-sample adjustment where the algorithm requires it. Report simulation uncertainty rather than silently calling the estimate exhaustive exact enumeration.

Sensitivity and robustness

High-dimensional sparse tables can exceed exact algorithm memory or runtime despite modest total counts. Zero margins should be handled explicitly. Structural impossibilities change the admissible tables. Increasing Monte Carlo draws improves precision but cannot repair an incorrectly specified sampling model.

How to use and calibrate

Enumerate tables with the same margins and sum probabilities at least as extreme under a stated ordering; use exact network algorithms or Monte Carlo when enumeration is large.

Example application

Test association in a sparse 3×4 contingency table.

Interpretation and pitfalls

Watch out

A Monte Carlo estimate has simulation error and is not an exhaustively enumerated exact p value. State the ordering and replicate count.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Conditional exact 2×3 Fisher–Freeman–Halton test. Large tables may require Monte Carlo instead of exact enumeration; declare that change explicitly.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: base R

# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
    raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
tab <- matrix(c(12,8,5,4,10,11),2,byrow=TRUE)
print(fisher.test(tab))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
                        text=True, capture_output=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)
result.check_returncode()
R

Validated — Executed successfully in the validation environment · needs Base/standard library

tab <- matrix(c(12,8,5,4,10,11),2,byrow=TRUE)
print(fisher.test(tab))
Output
	Fisher's Exact Test for Count Data

data:  tab
p-value = 0.03648
alternative hypothesis: two.sided

Sources

Statistics guide v4 (historical):
Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 061, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT061.