1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! Statistical hypothesis tests and their effect-size reporting.
//!
//! This module defines the shared result vocabulary ([`TestResult`],
//! [`Alternative`]) and houses the categorical, parametric, nonparametric,
//! goodness-of-fit, and correlation test families in subgroup folders. Each test
//! computes its statistic and p-value against the framework distributions
//! ([`crate::distributions`]) to tight tolerances: statistic relative
//! error ≤ 1e-8, p-value absolute error ≤ 1e-8 (asymptotic ≤ 1e-6). Equivalence
//! is proven by the `tests/equiv.rs` suite (per-family modules under
//! `tests/stat/`) against committed scipy/statsmodels golden fixtures.
use crateChiSquaredDistribution;
use crate;
/// Upper-tail probability `P(χ²_k ≥ x)` of the chi-squared null distribution.
///
/// The asymptotic p-value of every chi-squared-distributed statistic
/// (independence, Kruskal–Wallis, Friedman, Bartlett, Cochran) routes through
/// this single helper so they all share the framework
/// [`ChiSquaredDistribution`] CDF.
///
/// # Arguments
///
/// * `x` — the observed statistic; values `≤ 0` yield `1.0`.
/// * `df` — the degrees of freedom (`> 0`).
///
/// # Returns
///
/// The upper-tail probability in `[0, 1]`.
pub
/// Natural log of the upper-tail probability `ln P(χ²_k ≥ x)` — the log-space
/// counterpart of [`chi_squared_upper_tail`].
///
/// The chi-squared-routed tests (independence, Kruskal–Wallis, Friedman,
/// Bartlett, Cochran) report a log p-value through this single helper so the
/// extreme tail stays finite where [`chi_squared_upper_tail`] underflows to `0.0`.
///
/// # Arguments
///
/// * `x` — the observed statistic; values `≤ 0` yield `0.0` (log of p = 1).
/// * `df` — the degrees of freedom (`> 0`).
///
/// # Returns
///
/// `ln P(χ²_k ≥ x) ∈ (−∞, 0]`.
pub
/// The sidedness of a hypothesis test, mirroring scipy's `alternative` argument.
///
/// Selects which tail (or both) contributes to the reported p-value. The exact
/// mapping from a statistic to a p-value is per-test, but the convention is
/// uniform: [`Self::TwoSided`] doubles the smaller tail (or integrates both),
/// [`Self::Less`] takes the lower tail, [`Self::Greater`] the upper tail.
/// The computation mode for a test that offers both an exact (combinatorial)
/// null distribution and an asymptotic (large-sample) approximation.
///
/// Mirrors scipy's `method` argument for the rank and goodness-of-fit tests.
/// [`Self::Exact`] enumerates the exact null distribution (correct for small
/// samples but combinatorially expensive); [`Self::Asymptotic`] uses the normal
/// or Kolmogorov approximation (cheap, accurate for large samples);
/// [`Self::Auto`] resolves to exact below a documented per-test sample-size
/// threshold and to asymptotic at or above it.
/// The outcome of a hypothesis test: its statistic, p-value, and — where the test
/// defines them — degrees of freedom and an effect size.
///
/// `df` and `effect_size` are `None` for tests that define no such quantity (e.g.
/// Shapiro–Wilk, Fisher exact), matching the reference's contract rather than
/// emitting a misleading numeric placeholder.
///
/// `log_p_value` is the natural log of the p-value (`ln(p_value)`, the
/// `scipy.stats` `logsf`/`logcdf` convention), populated for the tests whose null
/// is a continuous distribution with a numerically-stable log tail (the t-tests,
/// ANOVA/F, and the chi-squared-routed tests). It stays finite in the extreme tail
/// where the linear [`Self::p_value`] underflows to `0.0`. It is
/// `None` for tests that report no continuous-tail p-value in log space (e.g. the
/// exact rank tests and Shapiro–Wilk); [`Self::p_value`] is unchanged regardless.