neg_binomial_cdf
Evaluates the cumulative distribution function (CDF) of the negative binomial distribution.
Synopsis
#include <imsls.h>
float imsls_f_neg_binomial_cdf (int k, float r, float p)
The type double function is imsls_d_neg_binomial_cdf.
Required Arguments
int k (Input)
Argument for which the CDF is to be evaluated. k must be non-negative.
float r (Input)
The negative binomial parameter. If r is equal to an integer, it represents the number of target successes. r must be greater than 0.
float p (Input)
The negative binomial parameter. If r is equal to an integer, p represents the probability of success in each independent Bernoulli trial. p must be a valid probability.
Return Value
The probability that a discrete negative binomial random variable takes on a value less than or equal to k. A value of NaN is returned if an error occurs.
Description
A discrete random variable taking values
has the negative binomial distribution with parameters
when
where Î(a) is the complete gamma function,
If r is an integer, an equivalent expression is
and in this case X can be interpreted as the number of failures before obtaining r successes in binomial trials with probability of success, p.
For the negative binomial distribution with parameters (r,p) , the cumulative distribution function (CDF) is
Where Ip(a,b) is the regularized incomplete beta function.
Where
are the incomplete and complete beta functions, respectively.
Example
This example illustrates calling the negative binomial pdf, cdf, and inverse cdf with p = 0.5 and r = 1.0.
#include <imsls.h>
#include <stdio.h>
int main()
{
int k;
float p = 0.5, r = 1.0;
float pdf, cdf;
int invcdf;
printf("\nr: %f\n", r);
printf("p: %f\n", p);
printf(" k pdf cdf quantile \n");
for (k = 0; k < 12; k++) {
pdf = imsls_f_neg_binomial_pdf(k, r, p);
cdf = imsls_f_neg_binomial_cdf(k, r, p);
invcdf = imsls_f_neg_binomial_inverse_cdf(cdf, r, p);
printf(" %10d %12.8f %12.8f %5d \n", k, pdf, cdf, invcdf);
}
}
Output
r: 1.000000
p: 0.500000
k pdf cdf quantile
0 0.50000000 0.50000000 0
1 0.25000000 0.75000000 1
2 0.12500000 0.87500000 2
3 0.06250000 0.93750000 3
4 0.03125000 0.96875000 4
5 0.01562500 0.98437500 5
6 0.00781250 0.99218750 6
7 0.00390625 0.99609375 7
8 0.00195313 0.99804688 8
9 0.00097656 0.99902344 9
10 0.00048828 0.99951172 10
11 0.00024414 0.99975586 11
Informational Errors
IMSLS_LESS_THAN_ZERO |
Since âkâ = # is less than zero the distribution function is set to 0. |