Function fisher_two_tail_pvalue
pub fn fisher_two_tail_pvalue(a: u32, b: u32, c: u32, d: u32) -> Option<f64>Expand description
Fisher’s exact two-tail p-value for the 2×2 contingency table
| col 1 | col 2 |
--------+-------+-------+
row 1 | a | b |
row 2 | c | d |Returns Some(p) with p in [0.0, 1.0], or None if the
resulting hypergeometric distribution is degenerate (every row or
column sum is zero — Fisher’s test is undefined).
§Algorithm
Conditional on the row and column marginals, the count in the
top-left cell is hypergeometric with parameters N = a+b+c+d,
K = a+b (top row sum), and n = a+c (left column sum). The
two-tail p-value is the sum of probabilities of all 2×2
tables with the same marginals whose probability under the
hypergeometric model is at most that of the observed table —
the standard Fisher exact convention (and what the prior
fishers_exact crate computes).
All factorials are evaluated in log space via ln_factorial so
the algorithm is numerically stable on u32 inputs — the marginal
sums can reach a few million on a large monorepo coupling
analysis, well beyond what f64::MAX can represent as a plain
factorial.