EProportions · Guide test 061
Fisher–Freeman–Halton exact test
Extends Fisher conditional testing to larger rectangular contingency tables.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Exact test of independence for R × C tables (Fisher–Freeman–Halton) — Are two categorical variables associated when the table is too sparse for the χ² approximation?
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
0 = rows and columns independent.
Your data
Edit the counts| Low | Mid | High | Total | |
|---|---|---|---|---|
| Row A | 4E = 2.3 | 2E = 3.3 | 4E = 4.3 | 10 |
| Row B | 3E = 4.7 | 8E = 6.7 | 9E = 8.7 | 20 |
| Total | 7 | 10 | 13 | 30 |
E is the count expected if rows and columns were unrelated.
If H₀ were true
- 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).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .252).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- hypergeometric probability of a table with the observed margins
- 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 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
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.
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()
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
- R Fisher conditional exact testsstat.ethz.ch
- fisher.teststat.ethz.ch
- 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.