nbdtr.c
Go to the documentation of this file.
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 
155 double nbdtrc(int k, int n, double p)
156 {
157  double dk, dn;
158 
159  if ((p < 0.0) || (p > 1.0))
160  goto domerr;
161  if (k < 0) {
162  domerr:
163  sf_error("nbdtr", SF_ERROR_DOMAIN, NULL);
164  return (NAN);
165  }
166 
167  dk = k + 1;
168  dn = n;
169  return (incbet(dk, dn, 1.0 - p));
170 }
171 
172 
173 
174 double nbdtr(int k, int n, double p)
175 {
176  double dk, dn;
177 
178  if ((p < 0.0) || (p > 1.0))
179  goto domerr;
180  if (k < 0) {
181  domerr:
182  sf_error("nbdtr", SF_ERROR_DOMAIN, NULL);
183  return (NAN);
184  }
185  dk = k + 1;
186  dn = n;
187  return (incbet(dn, dk, p));
188 }
189 
190 
191 
192 double nbdtri(int k, int n, double p)
193 {
194  double dk, dn, w;
195 
196  if ((p < 0.0) || (p > 1.0))
197  goto domerr;
198  if (k < 0) {
199  domerr:
200  sf_error("nbdtri", SF_ERROR_DOMAIN, NULL);
201  return (NAN);
202  }
203  dk = k + 1;
204  dn = n;
205  w = incbi(dn, dk, p);
206  return (w);
207 }
incbi
double incbi(double aa, double bb, double yy0)
Definition: incbi.c:51
w
RowVector3d w
Definition: Matrix_resize_int.cpp:3
nbdtr
double nbdtr(int k, int n, double p)
Definition: nbdtr.c:174
n
int n
Definition: BiCGSTAB_simple.cpp:1
nbdtrc
double nbdtrc(int k, int n, double p)
Definition: nbdtr.c:155
incbet
double incbet(double aa, double bb, double xx)
Definition: incbet.c:283
nbdtri
double nbdtri(int k, int n, double p)
Definition: nbdtr.c:192
mconf.h
p
float * p
Definition: Tutorial_Map_using.cpp:9
sf_error
void sf_error(const char *func_name, sf_error_t code, const char *fmt,...)
Definition: sf_error.c:41
NULL
#define NULL
Definition: ccolamd.c:609
SF_ERROR_DOMAIN
@ SF_ERROR_DOMAIN
Definition: sf_error.h:16


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:33:49