3 * Binomial distribution
10 * double p, y, bdtr();
12 * y = bdtr( k, n, p );
16 * Returns the sum of the terms 0 through k of the Binomial
17 * probability density:
25 * The terms are not summed directly; instead the incomplete
26 * beta integral is employed, according to the formula
28 * y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
30 * The arguments must be positive, with p ranging from 0 to 1.
34 * Tested at random points (a,b,p), with p between 0 and 1.
37 * arithmetic domain # trials peak rms
38 * For p between 0.001 and 1:
39 * IEEE 0,100 100000 4.3e-15 2.6e-16
44 * message condition value returned
45 * bdtr domain k < 0 0.0
51 * Complemented binomial distribution
58 * double p, y, bdtrc();
60 * y = bdtrc( k, n, p );
64 * Returns the sum of the terms k+1 through n of the Binomial
65 * probability density:
73 * The terms are not summed directly; instead the incomplete
74 * beta integral is employed, according to the formula
76 * y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
78 * The arguments must be positive, with p ranging from 0 to 1.
82 * Tested at random points (a,b,p).
85 * arithmetic domain # trials peak rms
86 * For p between 0.001 and 1:
87 * IEEE 0,100 100000 6.7e-15 8.2e-16
88 * For p between 0 and .001:
89 * IEEE 0,100 100000 1.5e-13 2.7e-15
93 * message condition value returned
94 * bdtrc domain x<0, x>1, n<k 0.0
98 * Inverse binomial distribution
105 * double p, y, bdtri();
107 * p = bdtr( k, n, y );
111 * Finds the event probability p such that the sum of the
112 * terms 0 through k of the Binomial probability density
113 * is equal to the given cumulative probability y.
115 * This is accomplished using the inverse beta integral
116 * function and the relation
118 * 1 - p = incbi( n-k, k+1, y ).
122 * Tested at random points (a,b,p).
124 * a,b Relative error:
125 * arithmetic domain # trials peak rms
126 * For p between 0.001 and 1:
127 * IEEE 0,100 100000 2.3e-14 6.4e-16
128 * IEEE 0,10000 100000 6.6e-12 1.2e-13
129 * For p between 10^-6 and 0.001:
130 * IEEE 0,100 100000 2.0e-12 1.3e-14
131 * IEEE 0,10000 100000 1.5e-12 3.2e-14
136 * message condition value returned
137 * bdtri domain k < 0, n <= k 0.0
145 Cephes Math Library Release 2.8: June, 2000
146 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
151 extern double incbet ( double, double, double );
152 extern double incbi ( double, double, double );
153 extern double pow ( double, double );
154 extern double log1p ( double );
155 extern double expm1 ( double );
157 double incbet(), incbi(), pow(), log1p(), expm1();
160 double bdtrc( k, n, p )
166 if( (p < 0.0) || (p > 1.0) )
174 mtherr( "bdtrc", DOMAIN );
184 dk = -expm1( dn * log1p(-p) );
186 dk = 1.0 - pow( 1.0-p, dn );
191 dk = incbet( dk, dn, p );
198 double bdtr( k, n, p )
204 if( (p < 0.0) || (p > 1.0) )
206 if( (k < 0) || (n < k) )
209 mtherr( "bdtr", DOMAIN );
219 dk = pow( 1.0-p, dn );
224 dk = incbet( dn, dk, 1.0 - p );
230 double bdtri( k, n, y )
236 if( (y < 0.0) || (y > 1.0) )
238 if( (k < 0) || (n <= k) )
241 mtherr( "bdtri", DOMAIN );
249 p = -expm1( log1p(y-1.0) / dn );
251 p = 1.0 - pow( y, 1.0/dn );
256 p = incbet( dn, dk, 0.5 );
258 p = incbi( dk, dn, 1.0-y );
260 p = 1.0 - incbi( dn, dk, y );