Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.ALGLIB-2.5.0/ALGLIB-2.5.0/chisquaredistr.cs @ 5229

Last change on this file since 5229 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.8 KB
Line 
1/*************************************************************************
2Cephes Math Library Release 2.8:  June, 2000
3Copyright 1984, 1987, 2000 by Stephen L. Moshier
4
5Contributors:
6    * Sergey Bochkanov (ALGLIB project). Translation from C to
7      pseudocode.
8
9See subroutines comments for additional copyrights.
10
11>>> SOURCE LICENSE >>>
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation (www.fsf.org); either version 2 of the
15License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20GNU General Public License for more details.
21
22A copy of the GNU General Public License is available at
23http://www.fsf.org/licensing/licenses
24
25>>> END OF LICENSE >>>
26*************************************************************************/
27
28
29namespace alglib {
30  public class chisquaredistr {
31    /*************************************************************************
32    Chi-square distribution
33
34    Returns the area under the left hand tail (from 0 to x)
35    of the Chi square probability density function with
36    v degrees of freedom.
37
38
39                                      x
40                                       -
41                           1          | |  v/2-1  -t/2
42     P( x | v )   =   -----------     |   t      e     dt
43                       v/2  -       | |
44                      2    | (v/2)   -
45                                      0
46
47    where x is the Chi-square variable.
48
49    The incomplete gamma integral is used, according to the
50    formula
51
52    y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
53
54    The arguments must both be positive.
55
56    ACCURACY:
57
58    See incomplete gamma function
59
60
61    Cephes Math Library Release 2.8:  June, 2000
62    Copyright 1984, 1987, 2000 by Stephen L. Moshier
63    *************************************************************************/
64    public static double chisquaredistribution(double v,
65        double x) {
66      double result = 0;
67
68      System.Diagnostics.Debug.Assert((double)(x) >= (double)(0) & (double)(v) >= (double)(1), "Domain error in ChiSquareDistribution");
69      result = igammaf.incompletegamma(v / 2.0, x / 2.0);
70      return result;
71    }
72
73
74    /*************************************************************************
75    Complemented Chi-square distribution
76
77    Returns the area under the right hand tail (from x to
78    infinity) of the Chi square probability density function
79    with v degrees of freedom:
80
81                                     inf.
82                                       -
83                           1          | |  v/2-1  -t/2
84     P( x | v )   =   -----------     |   t      e     dt
85                       v/2  -       | |
86                      2    | (v/2)   -
87                                      x
88
89    where x is the Chi-square variable.
90
91    The incomplete gamma integral is used, according to the
92    formula
93
94    y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
95
96    The arguments must both be positive.
97
98    ACCURACY:
99
100    See incomplete gamma function
101
102    Cephes Math Library Release 2.8:  June, 2000
103    Copyright 1984, 1987, 2000 by Stephen L. Moshier
104    *************************************************************************/
105    public static double chisquarecdistribution(double v,
106        double x) {
107      double result = 0;
108
109      System.Diagnostics.Debug.Assert((double)(x) >= (double)(0) & (double)(v) >= (double)(1), "Domain error in ChiSquareDistributionC");
110      result = igammaf.incompletegammac(v / 2.0, x / 2.0);
111      return result;
112    }
113
114
115    /*************************************************************************
116    Inverse of complemented Chi-square distribution
117
118    Finds the Chi-square argument x such that the integral
119    from x to infinity of the Chi-square density is equal
120    to the given cumulative probability y.
121
122    This is accomplished using the inverse gamma integral
123    function and the relation
124
125       x/2 = igami( df/2, y );
126
127    ACCURACY:
128
129    See inverse incomplete gamma function
130
131
132    Cephes Math Library Release 2.8:  June, 2000
133    Copyright 1984, 1987, 2000 by Stephen L. Moshier
134    *************************************************************************/
135    public static double invchisquaredistribution(double v,
136        double y) {
137      double result = 0;
138
139      System.Diagnostics.Debug.Assert((double)(y) >= (double)(0) & (double)(y) <= (double)(1) & (double)(v) >= (double)(1), "Domain error in InvChiSquareDistribution");
140      result = 2 * igammaf.invincompletegammac(0.5 * v, y);
141      return result;
142    }
143  }
144}
Note: See TracBrowser for help on using the repository browser.