MCPcopy Create free account
hub / github.com/BoevaLab/FREEC / invbinomialdistribution

Function invbinomialdistribution

src/binomialdistr.cpp:196–231  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

194Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
195*************************************************************************/
196double 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

Callers

nothing calls this directly

Calls 4

expm1Function · 0.85
log1pFunction · 0.85
incompletebetaFunction · 0.85
invincompletebetaFunction · 0.85

Tested by

no test coverage detected