Skip to main content

Module stats

Module stats 

Expand description

Statistical helpers used by the analyses.

Fisher’s exact two-tail p-value for a 2×2 contingency table, used by analyses::coupling to gate coupling pairs at p < fisher_significance.

In-tree port of the algorithm previously consumed via the fishers_exact crate (last release 2018-11). The crate had no live CVE but was unmaintained for 7+ years; we eliminated the supply-chain dependency by porting the algorithm here. The numeric contract is preserved: fisher_two_tail_pvalue(a, b, c, d) matches the upstream’s fishers_exact(&[a, b, c, d]) .two_tail_pvalue to ≤ 1e-12 relative error across the regression suite (see fisher_matches_upstream_* tests at the bottom of this file).

auc and precision_at_k are ranking-quality metrics for the own-repo defect-calibration validation pass: given a per-file score (e.g. a code-health structural-risk value) and a binary defect label, they answer whether the score actually separates the defective files from the rest. Both are sort-based with no external dependencies.

Functions§

auc
Area under the ROC curve for binary labels ranked by score, computed via the Mann-Whitney U statistic with midpoint tie handling. None when either class is empty.
bh_fdr_threshold
Benjamini-Hochberg FDR step-up p-value cutoff for a family of p-values at false-discovery-rate level q. Returns the largest p(k) with p(k) <= (k/m)*q (sorted ascending); every p <= the returned cutoff is a discovery. Returns f64::NEG_INFINITY (reject nothing) for an empty family or when no rank satisfies the criterion.
fisher_two_tail_pvalue
Fisher’s exact two-tail p-value for the 2×2 contingency table
precision_at_k
Of the k highest-scored items (ties broken by stable input order), the fraction labeled positive. None when k == 0 or k > len.
wilson_ci
Wilson score 95% confidence interval for a proportion k / n.
wilson_ci_from_proportion
Wilson score 95% confidence interval around an already-computed proportion p_hat observed over a pool of n.