Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/ALGLIB/chisquaredistr.cs @ 2563

Last change on this file since 2563 was 2563, checked in by gkronber, 14 years ago

Updated ALGLIB to latest version. #751 (Plugin for for data-modeling with ANN (integrated into CEDMA))

File size: 5.2 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
28using System;
29
30namespace alglib
31{
32    public class chisquaredistr
33    {
34        /*************************************************************************
35        Chi-square distribution
36
37        Returns the area under the left hand tail (from 0 to x)
38        of the Chi square probability density function with
39        v degrees of freedom.
40
41
42                                          x
43                                           -
44                               1          | |  v/2-1  -t/2
45         P( x | v )   =   -----------     |   t      e     dt
46                           v/2  -       | |
47                          2    | (v/2)   -
48                                          0
49
50        where x is the Chi-square variable.
51
52        The incomplete gamma integral is used, according to the
53        formula
54
55        y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
56
57        The arguments must both be positive.
58
59        ACCURACY:
60
61        See incomplete gamma function
62
63
64        Cephes Math Library Release 2.8:  June, 2000
65        Copyright 1984, 1987, 2000 by Stephen L. Moshier
66        *************************************************************************/
67        public static double chisquaredistribution(double v,
68            double x)
69        {
70            double result = 0;
71
72            System.Diagnostics.Debug.Assert((double)(x)>=(double)(0) & (double)(v)>=(double)(1), "Domain error in ChiSquareDistribution");
73            result = igammaf.incompletegamma(v/2.0, x/2.0);
74            return result;
75        }
76
77
78        /*************************************************************************
79        Complemented Chi-square distribution
80
81        Returns the area under the right hand tail (from x to
82        infinity) of the Chi square probability density function
83        with v degrees of freedom:
84
85                                         inf.
86                                           -
87                               1          | |  v/2-1  -t/2
88         P( x | v )   =   -----------     |   t      e     dt
89                           v/2  -       | |
90                          2    | (v/2)   -
91                                          x
92
93        where x is the Chi-square variable.
94
95        The incomplete gamma integral is used, according to the
96        formula
97
98        y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
99
100        The arguments must both be positive.
101
102        ACCURACY:
103
104        See incomplete gamma function
105
106        Cephes Math Library Release 2.8:  June, 2000
107        Copyright 1984, 1987, 2000 by Stephen L. Moshier
108        *************************************************************************/
109        public static double chisquarecdistribution(double v,
110            double x)
111        {
112            double result = 0;
113
114            System.Diagnostics.Debug.Assert((double)(x)>=(double)(0) & (double)(v)>=(double)(1), "Domain error in ChiSquareDistributionC");
115            result = igammaf.incompletegammac(v/2.0, x/2.0);
116            return result;
117        }
118
119
120        /*************************************************************************
121        Inverse of complemented Chi-square distribution
122
123        Finds the Chi-square argument x such that the integral
124        from x to infinity of the Chi-square density is equal
125        to the given cumulative probability y.
126
127        This is accomplished using the inverse gamma integral
128        function and the relation
129
130           x/2 = igami( df/2, y );
131
132        ACCURACY:
133
134        See inverse incomplete gamma function
135
136
137        Cephes Math Library Release 2.8:  June, 2000
138        Copyright 1984, 1987, 2000 by Stephen L. Moshier
139        *************************************************************************/
140        public static double invchisquaredistribution(double v,
141            double y)
142        {
143            double result = 0;
144
145            System.Diagnostics.Debug.Assert((double)(y)>=(double)(0) & (double)(y)<=(double)(1) & (double)(v)>=(double)(1), "Domain error in InvChiSquareDistribution");
146            result = 2*igammaf.invincompletegammac(0.5*v, y);
147            return result;
148        }
149    }
150}
Note: See TracBrowser for help on using the repository browser.