Inverse binomial distribution Finds the event probability p such that the sum of the terms 0 through k of the Binomial probability density is equal to the given cumulative probability y. This is accomplished using the inverse beta integral function and the relation 1 - p = incbi( n-k, k+1, y ). ACCURACY: Tested at random points (a,b,p). a,b Relative error: a
| 194 | Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier |
| 195 | *************************************************************************/ |
| 196 | double invbinomialdistribution(int k, int n, double y) |
| 197 | { |
| 198 | double result; |
| 199 | double dk; |
| 200 | double dn; |
| 201 | double p; |
| 202 | |
| 203 | ap::ap_error::make_assertion(k>=0&&k<n, "Domain error in InvBinomialDistribution"); |
| 204 | dn = n-k; |
| 205 | if( k==0 ) |
| 206 | { |
| 207 | if( ap::fp_greater(y,0.8) ) |
| 208 | { |
| 209 | p = -expm1(log1p(y-1.0)/dn); |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | p = 1.0-pow(y, 1.0/dn); |
| 214 | } |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | dk = k+1; |
| 219 | p = incompletebeta(dn, dk, 0.5); |
| 220 | if( ap::fp_greater(p,0.5) ) |
| 221 | { |
| 222 | p = invincompletebeta(dk, dn, 1.0-y); |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | p = 1.0-invincompletebeta(dn, dk, y); |
| 227 | } |
| 228 | } |
| 229 | result = p; |
| 230 | return result; |
| 231 | } |
| 232 | |
| 233 | |
| 234 |
nothing calls this directly
no test coverage detected