3
* Negative binomial distribution
10
* double p, y, nbdtr();
12
* y = nbdtr( k, n, p );
16
* Returns the sum of the terms 0 through k of the negative
17
* binomial distribution:
25
* In a sequence of Bernoulli trials, this is the probability
26
* that k or fewer failures precede the nth success.
28
* The terms are not computed individually; instead the incomplete
29
* beta integral is employed, according to the formula
31
* y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
33
* The arguments must be positive, with p ranging from 0 to 1.
37
* Tested at random points (a,b,p), with p between 0 and 1.
40
* arithmetic domain # trials peak rms
41
* IEEE 0,100 100000 1.7e-13 8.8e-15
47
* Complemented negative binomial distribution
54
* double p, y, nbdtrc();
56
* y = nbdtrc( k, n, p );
60
* Returns the sum of the terms k+1 to infinity of the negative
61
* binomial distribution:
69
* The terms are not computed individually; instead the incomplete
70
* beta integral is employed, according to the formula
72
* y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
74
* The arguments must be positive, with p ranging from 0 to 1.
78
* Tested at random points (a,b,p), with p between 0 and 1.
81
* arithmetic domain # trials peak rms
82
* IEEE 0,100 100000 1.7e-13 8.8e-15
88
* Complemented negative binomial distribution
95
* double p, y, nbdtrc();
97
* y = nbdtrc( k, n, p );
101
* Returns the sum of the terms k+1 to infinity of the negative
102
* binomial distribution:
110
* The terms are not computed individually; instead the incomplete
111
* beta integral is employed, according to the formula
113
* y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
115
* The arguments must be positive, with p ranging from 0 to 1.
123
* Functional inverse of negative binomial distribution
130
* double p, y, nbdtri();
132
* p = nbdtri( k, n, y );
136
* Finds the argument p such that nbdtr(k,n,p) is equal to y.
140
* Tested at random points (a,b,y), with y between 0 and 1.
142
* a,b Relative error:
143
* arithmetic domain # trials peak rms
144
* IEEE 0,100 100000 1.5e-14 8.5e-16
149
Cephes Math Library Release 2.3: March, 1995
150
Copyright 1984, 1987, 1995 by Stephen L. Moshier
155
double incbet(), incbi();
160
double nbdtrc( k, n, p )
166
if( (p < 0.0) || (p > 1.0) )
171
mtherr( "nbdtr", DOMAIN );
177
return( incbet( dk, dn, 1.0 - p ) );
182
double nbdtr( k, n, p )
188
if( (p < 0.0) || (p > 1.0) )
193
mtherr( "nbdtr", DOMAIN );
198
return( incbet( dn, dk, p ) );
203
double nbdtri( k, n, p )
209
if( (p < 0.0) || (p > 1.0) )
214
mtherr( "nbdtri", DOMAIN );
219
w = incbi( dn, dk, p );