3 * Negative binomial distribution
10 * long double p, y, nbdtrl();
12 * y = nbdtrl( k, n, p );
18 * Returns the sum of the terms 0 through k of the negative
19 * binomial distribution:
27 * In a sequence of Bernoulli trials, this is the probability
28 * that k or fewer failures precede the nth success.
30 * The terms are not computed individually; instead the incomplete
31 * beta integral is employed, according to the formula
33 * y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
35 * The arguments must be positive, with p ranging from 0 to 1.
41 * Tested at random points (k,n,p) with k and n between 1 and 10,000
42 * and p between 0 and 1.
44 * arithmetic domain # trials peak rms
46 * IEEE 0,10000 10000 9.8e-15 2.1e-16
51 * Complemented negative binomial distribution
58 * long double p, y, nbdtrcl();
60 * y = nbdtrcl( k, n, p );
66 * Returns the sum of the terms k+1 to infinity of the negative
67 * binomial distribution:
75 * The terms are not computed individually; instead the incomplete
76 * beta integral is employed, according to the formula
78 * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
80 * The arguments must be positive, with p ranging from 0 to 1.
91 * Functional inverse of negative binomial distribution
98 * long double p, y, nbdtril();
100 * p = nbdtril( k, n, y );
106 * Finds the argument p such that nbdtr(k,n,p) is equal to y.
110 * Tested at random points (a,b,y), with y between 0 and 1.
112 * a,b Relative error:
113 * arithmetic domain # trials peak rms
119 Cephes Math Library Release 2.3: January,1995
120 Copyright 1984, 1995 by Stephen L. Moshier
125 extern long double incbetl ( long double, long double, long double );
126 extern long double powl ( long double, long double );
127 extern long double incbil ( long double, long double, long double );
129 long double incbetl(), powl(), incbil();
132 long double nbdtrcl( k, n, p )
138 if( (p < 0.0L) || (p > 1.0L) )
143 mtherr( "nbdtrl", DOMAIN );
148 return( 1.0L - powl( p, dn ) );
151 return( incbetl( dk, dn, 1.0L - p ) );
156 long double nbdtrl( k, n, p )
162 if( (p < 0.0L) || (p > 1.0L) )
167 mtherr( "nbdtrl", DOMAIN );
172 return( powl( p, dn ) );
175 return( incbetl( dn, dk, p ) );
179 long double nbdtril( k, n, p )
183 long double dk, dn, w;
185 if( (p < 0.0L) || (p > 1.0L) )
190 mtherr( "nbdtrl", DOMAIN );
195 w = incbil( dn, dk, p );