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. Returnsf64::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_hatobserved over a pool ofn.