~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to Lib/special/cephes/nbdtr.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*                                                      nbdtr.c
2
 
 *
3
 
 *      Negative binomial distribution
4
 
 *
5
 
 *
6
 
 *
7
 
 * SYNOPSIS:
8
 
 *
9
 
 * int k, n;
10
 
 * double p, y, nbdtr();
11
 
 *
12
 
 * y = nbdtr( k, n, p );
13
 
 *
14
 
 * DESCRIPTION:
15
 
 *
16
 
 * Returns the sum of the terms 0 through k of the negative
17
 
 * binomial distribution:
18
 
 *
19
 
 *   k
20
 
 *   --  ( n+j-1 )   n      j
21
 
 *   >   (       )  p  (1-p)
22
 
 *   --  (   j   )
23
 
 *  j=0
24
 
 *
25
 
 * In a sequence of Bernoulli trials, this is the probability
26
 
 * that k or fewer failures precede the nth success.
27
 
 *
28
 
 * The terms are not computed individually; instead the incomplete
29
 
 * beta integral is employed, according to the formula
30
 
 *
31
 
 * y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
32
 
 *
33
 
 * The arguments must be positive, with p ranging from 0 to 1.
34
 
 *
35
 
 * ACCURACY:
36
 
 *
37
 
 * Tested at random points (a,b,p), with p between 0 and 1.
38
 
 *
39
 
 *               a,b                     Relative error:
40
 
 * arithmetic  domain     # trials      peak         rms
41
 
 *    IEEE     0,100       100000      1.7e-13     8.8e-15
42
 
 * See also incbet.c.
43
 
 *
44
 
 */
45
 
/*                                                     nbdtrc.c
46
 
 *
47
 
 *      Complemented negative binomial distribution
48
 
 *
49
 
 *
50
 
 *
51
 
 * SYNOPSIS:
52
 
 *
53
 
 * int k, n;
54
 
 * double p, y, nbdtrc();
55
 
 *
56
 
 * y = nbdtrc( k, n, p );
57
 
 *
58
 
 * DESCRIPTION:
59
 
 *
60
 
 * Returns the sum of the terms k+1 to infinity of the negative
61
 
 * binomial distribution:
62
 
 *
63
 
 *   inf
64
 
 *   --  ( n+j-1 )   n      j
65
 
 *   >   (       )  p  (1-p)
66
 
 *   --  (   j   )
67
 
 *  j=k+1
68
 
 *
69
 
 * The terms are not computed individually; instead the incomplete
70
 
 * beta integral is employed, according to the formula
71
 
 *
72
 
 * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
73
 
 *
74
 
 * The arguments must be positive, with p ranging from 0 to 1.
75
 
 *
76
 
 * ACCURACY:
77
 
 *
78
 
 * Tested at random points (a,b,p), with p between 0 and 1.
79
 
 *
80
 
 *               a,b                     Relative error:
81
 
 * arithmetic  domain     # trials      peak         rms
82
 
 *    IEEE     0,100       100000      1.7e-13     8.8e-15
83
 
 * See also incbet.c.
84
 
 */
85
 
 
86
 
/*                                                      nbdtrc
87
 
 *
88
 
 *      Complemented negative binomial distribution
89
 
 *
90
 
 *
91
 
 *
92
 
 * SYNOPSIS:
93
 
 *
94
 
 * int k, n;
95
 
 * double p, y, nbdtrc();
96
 
 *
97
 
 * y = nbdtrc( k, n, p );
98
 
 *
99
 
 * DESCRIPTION:
100
 
 *
101
 
 * Returns the sum of the terms k+1 to infinity of the negative
102
 
 * binomial distribution:
103
 
 *
104
 
 *   inf
105
 
 *   --  ( n+j-1 )   n      j
106
 
 *   >   (       )  p  (1-p)
107
 
 *   --  (   j   )
108
 
 *  j=k+1
109
 
 *
110
 
 * The terms are not computed individually; instead the incomplete
111
 
 * beta integral is employed, according to the formula
112
 
 *
113
 
 * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
114
 
 *
115
 
 * The arguments must be positive, with p ranging from 0 to 1.
116
 
 *
117
 
 * ACCURACY:
118
 
 *
119
 
 * See incbet.c.
120
 
 */
121
 
/*                                                     nbdtri
122
 
 *
123
 
 *      Functional inverse of negative binomial distribution
124
 
 *
125
 
 *
126
 
 *
127
 
 * SYNOPSIS:
128
 
 *
129
 
 * int k, n;
130
 
 * double p, y, nbdtri();
131
 
 *
132
 
 * p = nbdtri( k, n, y );
133
 
 *
134
 
 * DESCRIPTION:
135
 
 *
136
 
 * Finds the argument p such that nbdtr(k,n,p) is equal to y.
137
 
 *
138
 
 * ACCURACY:
139
 
 *
140
 
 * Tested at random points (a,b,y), with y between 0 and 1.
141
 
 *
142
 
 *               a,b                     Relative error:
143
 
 * arithmetic  domain     # trials      peak         rms
144
 
 *    IEEE     0,100       100000      1.5e-14     8.5e-16
145
 
 * See also incbi.c.
146
 
 */
147
 
 
148
 
/*
149
 
Cephes Math Library Release 2.3:  March, 1995
150
 
Copyright 1984, 1987, 1995 by Stephen L. Moshier
151
 
*/
152
 
 
153
 
#include "mconf.h"
154
 
#ifndef ANSIPROT
155
 
double incbet(), incbi();
156
 
#endif
157
 
 
158
 
extern double NAN;
159
 
 
160
 
double nbdtrc( k, n, p )
161
 
int k, n;
162
 
double p;
163
 
{
164
 
double dk, dn;
165
 
 
166
 
if( (p < 0.0) || (p > 1.0) )
167
 
        goto domerr;
168
 
if( k < 0 )
169
 
        {
170
 
domerr:
171
 
        mtherr( "nbdtr", DOMAIN );
172
 
        return( NAN );
173
 
        }
174
 
 
175
 
dk = k+1;
176
 
dn = n;
177
 
return( incbet( dk, dn, 1.0 - p ) );
178
 
}
179
 
 
180
 
 
181
 
 
182
 
double nbdtr( k, n, p )
183
 
int k, n;
184
 
double p;
185
 
{
186
 
double dk, dn;
187
 
 
188
 
if( (p < 0.0) || (p > 1.0) )
189
 
        goto domerr;
190
 
if( k < 0 )
191
 
        {
192
 
domerr:
193
 
        mtherr( "nbdtr", DOMAIN );
194
 
        return( NAN );
195
 
        }
196
 
dk = k+1;
197
 
dn = n;
198
 
return( incbet( dn, dk, p ) );
199
 
}
200
 
 
201
 
 
202
 
 
203
 
double nbdtri( k, n, p )
204
 
int k, n;
205
 
double p;
206
 
{
207
 
double dk, dn, w;
208
 
 
209
 
if( (p < 0.0) || (p > 1.0) )
210
 
        goto domerr;
211
 
if( k < 0 )
212
 
        {
213
 
domerr:
214
 
        mtherr( "nbdtri", DOMAIN );
215
 
        return( NAN );
216
 
        }
217
 
dk = k+1;
218
 
dn = n;
219
 
w = incbi( dn, dk, p );
220
 
return( w );
221
 
}