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.8: June, 2000
150 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
155 extern double incbet ( double, double, double );
156 extern double incbi ( double, double, double );
158 double incbet(), incbi();
161 double nbdtrc( k, n, p )
167 if( (p < 0.0) || (p > 1.0) )
172 mtherr( "nbdtr", DOMAIN );
178 return( incbet( dk, dn, 1.0 - p ) );
183 double nbdtr( k, n, p )
189 if( (p < 0.0) || (p > 1.0) )
194 mtherr( "nbdtr", DOMAIN );
199 return( incbet( dn, dk, p ) );
204 double nbdtri( k, n, p )
210 if( (p < 0.0) || (p > 1.0) )
215 mtherr( "nbdtri", DOMAIN );
220 w = incbi( dn, dk, p );