[431c9e0] | 1 | /* chdtr.c |
---|
| 2 | * |
---|
| 3 | * Chi-square distribution |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * |
---|
| 7 | * SYNOPSIS: |
---|
| 8 | * |
---|
| 9 | * double df, x, y, chdtr(); |
---|
| 10 | * |
---|
| 11 | * y = chdtr( df, x ); |
---|
| 12 | * |
---|
| 13 | * |
---|
| 14 | * |
---|
| 15 | * DESCRIPTION: |
---|
| 16 | * |
---|
| 17 | * Returns the area under the left hand tail (from 0 to x) |
---|
| 18 | * of the Chi square probability density function with |
---|
| 19 | * v degrees of freedom. |
---|
| 20 | * |
---|
| 21 | * |
---|
| 22 | * inf. |
---|
| 23 | * - |
---|
| 24 | * 1 | | v/2-1 -t/2 |
---|
| 25 | * P( x | v ) = ----------- | t e dt |
---|
| 26 | * v/2 - | | |
---|
| 27 | * 2 | (v/2) - |
---|
| 28 | * x |
---|
| 29 | * |
---|
| 30 | * where x is the Chi-square variable. |
---|
| 31 | * |
---|
| 32 | * The incomplete gamma integral is used, according to the |
---|
| 33 | * formula |
---|
| 34 | * |
---|
| 35 | * y = chdtr( v, x ) = igam( v/2.0, x/2.0 ). |
---|
| 36 | * |
---|
| 37 | * |
---|
| 38 | * The arguments must both be positive. |
---|
| 39 | * |
---|
| 40 | * |
---|
| 41 | * |
---|
| 42 | * ACCURACY: |
---|
| 43 | * |
---|
| 44 | * See igam(). |
---|
| 45 | * |
---|
| 46 | * ERROR MESSAGES: |
---|
| 47 | * |
---|
| 48 | * message condition value returned |
---|
| 49 | * chdtr domain x < 0 or v < 1 0.0 |
---|
| 50 | */ |
---|
| 51 | /* chdtrc() |
---|
| 52 | * |
---|
| 53 | * Complemented Chi-square distribution |
---|
| 54 | * |
---|
| 55 | * |
---|
| 56 | * |
---|
| 57 | * SYNOPSIS: |
---|
| 58 | * |
---|
| 59 | * double v, x, y, chdtrc(); |
---|
| 60 | * |
---|
| 61 | * y = chdtrc( v, x ); |
---|
| 62 | * |
---|
| 63 | * |
---|
| 64 | * |
---|
| 65 | * DESCRIPTION: |
---|
| 66 | * |
---|
| 67 | * Returns the area under the right hand tail (from x to |
---|
| 68 | * infinity) of the Chi square probability density function |
---|
| 69 | * with v degrees of freedom: |
---|
| 70 | * |
---|
| 71 | * |
---|
| 72 | * inf. |
---|
| 73 | * - |
---|
| 74 | * 1 | | v/2-1 -t/2 |
---|
| 75 | * P( x | v ) = ----------- | t e dt |
---|
| 76 | * v/2 - | | |
---|
| 77 | * 2 | (v/2) - |
---|
| 78 | * x |
---|
| 79 | * |
---|
| 80 | * where x is the Chi-square variable. |
---|
| 81 | * |
---|
| 82 | * The incomplete gamma integral is used, according to the |
---|
| 83 | * formula |
---|
| 84 | * |
---|
| 85 | * y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ). |
---|
| 86 | * |
---|
| 87 | * |
---|
| 88 | * The arguments must both be positive. |
---|
| 89 | * |
---|
| 90 | * |
---|
| 91 | * |
---|
| 92 | * ACCURACY: |
---|
| 93 | * |
---|
| 94 | * See igamc(). |
---|
| 95 | * |
---|
| 96 | * ERROR MESSAGES: |
---|
| 97 | * |
---|
| 98 | * message condition value returned |
---|
| 99 | * chdtrc domain x < 0 or v < 1 0.0 |
---|
| 100 | */ |
---|
| 101 | /* chdtri() |
---|
| 102 | * |
---|
| 103 | * Inverse of complemented Chi-square distribution |
---|
| 104 | * |
---|
| 105 | * |
---|
| 106 | * |
---|
| 107 | * SYNOPSIS: |
---|
| 108 | * |
---|
| 109 | * double df, x, y, chdtri(); |
---|
| 110 | * |
---|
| 111 | * x = chdtri( df, y ); |
---|
| 112 | * |
---|
| 113 | * |
---|
| 114 | * |
---|
| 115 | * |
---|
| 116 | * DESCRIPTION: |
---|
| 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 | * |
---|
| 128 | * |
---|
| 129 | * |
---|
| 130 | * ACCURACY: |
---|
| 131 | * |
---|
| 132 | * See igami.c. |
---|
| 133 | * |
---|
| 134 | * ERROR MESSAGES: |
---|
| 135 | * |
---|
| 136 | * message condition value returned |
---|
| 137 | * chdtri domain y < 0 or y > 1 0.0 |
---|
| 138 | * v < 1 |
---|
| 139 | * |
---|
| 140 | */ |
---|
| 141 | |
---|
| 142 | /* chdtr() */ |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | /* |
---|
| 146 | Cephes Math Library Release 2.8: June, 2000 |
---|
| 147 | Copyright 1984, 1987, 2000 by Stephen L. Moshier |
---|
| 148 | */ |
---|
| 149 | |
---|
| 150 | #include "mconf.h" |
---|
| 151 | #ifdef ANSIPROT |
---|
| 152 | extern double igamc ( double, double ); |
---|
| 153 | extern double igam ( double, double ); |
---|
| 154 | extern double igami ( double, double ); |
---|
| 155 | #else |
---|
| 156 | double igamc(), igam(), igami(); |
---|
| 157 | #endif |
---|
| 158 | |
---|
| 159 | double chdtrc(df,x) |
---|
| 160 | double df, x; |
---|
| 161 | { |
---|
| 162 | |
---|
| 163 | if( (x < 0.0) || (df < 1.0) ) |
---|
| 164 | { |
---|
| 165 | mtherr( "chdtrc", DOMAIN ); |
---|
| 166 | return(0.0); |
---|
| 167 | } |
---|
| 168 | return( igamc( df/2.0, x/2.0 ) ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | double chdtr(df,x) |
---|
| 174 | double df, x; |
---|
| 175 | { |
---|
| 176 | |
---|
| 177 | if( (x < 0.0) || (df < 1.0) ) |
---|
| 178 | { |
---|
| 179 | mtherr( "chdtr", DOMAIN ); |
---|
| 180 | return(0.0); |
---|
| 181 | } |
---|
| 182 | return( igam( df/2.0, x/2.0 ) ); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | double chdtri( df, y ) |
---|
| 188 | double df, y; |
---|
| 189 | { |
---|
| 190 | double x; |
---|
| 191 | |
---|
| 192 | if( (y < 0.0) || (y > 1.0) || (df < 1.0) ) |
---|
| 193 | { |
---|
| 194 | mtherr( "chdtri", DOMAIN ); |
---|
| 195 | return(0.0); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | x = igami( 0.5 * df, y ); |
---|
| 199 | return( 2.0 * x ); |
---|
| 200 | } |
---|