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
use crategamcdf;
/// Chi-squared cumulative distribution function (CDF).
///
/// Returns the probability that a Chi-squared random variable with <math><mi>v</mi></math>
/// degrees of freedom is less than or equal to <math><mi>x</mi></math>.
///
/// # Mathematical Definition
/// For a Chi-squared distribution with <math><mi>v</mi></math> degrees of freedom:
/// - Lower tail (`upper = false`):
/// <math display="block">
/// <mi>F</mi><mo>(</mo><mi>x</mi><mo>;</mo><mi>v</mi><mo>)</mo>
/// <mo>=</mo>
/// <mi>P</mi><mo>(</mo><mi>v</mi><mo>/</mo><mn>2</mn><mo>,</mo><mi>x</mi><mo>/</mo><mn>2</mn><mo>)</mo>
/// <mo>=</mo>
/// <mfrac><mn>1</mn><mrow><mi>Γ</mi><mo>(</mo><mi>v</mi><mo>/</mo><mn>2</mn><mo>)</mo></mrow></mfrac>
/// <msubsup><mo>∫</mo><mn>0</mn><mrow><mi>x</mi><mo>/</mo><mn>2</mn></mrow></msubsup>
/// <msup><mi>t</mi><mrow><mi>v</mi><mo>/</mo><mn>2</mn><mo>-</mo><mn>1</mn></mrow></msup><msup><mi>e</mi><mrow><mo>-</mo><mi>t</mi></mrow></msup><mi>dt</mi>
/// </math>
/// - Upper tail (`upper = true`):
/// <math display="block">
/// <mn>1</mn><mo>-</mo><mi>F</mi><mo>(</mo><mi>x</mi><mo>;</mo><mi>v</mi><mo>)</mo>
/// <mo>=</mo>
/// <mi>Q</mi><mo>(</mo><mi>v</mi><mo>/</mo><mn>2</mn><mo>,</mo><mi>x</mi><mo>/</mo><mn>2</mn><mo>)</mo>
/// </math>
///
/// # Examples
/// ```
/// use abax::chi2cdf;
///
/// // For v=2, the distribution is Exponential with mean 2: F(x) = 1 - exp(-x/2)
/// let p = chi2cdf(2.0, 2.0, false);
/// assert!((p - (1.0 - (-1.0f64).exp())).abs() < 1e-15);
/// ```