neg_binomial_inverse_cdf
Evaluates the inverse cumulative distribution function (CDF) of the negative binomial distribution.
Synopsis
#include <imsls.h>
float imsls_f_neg_binomial_inverse_cdf (float prob, float r, float p)
The type double function is imsls_d_neg_binomial_inverse_cdf.
Required Arguments
float prob (Input)
Argument for which the inverse CDF is to be evaluated. prob must be a valid probability value.
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
An integer, the inverse of the negative binomial CDF evaluated at prob. Note that the function returns the minimum value k satisfying F(k;r,p)>=prob, where F is the negative binomial CDF. A value of -1 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.
The inverse cumulative distribution or quantile function is the function Q(prob) =F-1(F(k)) = k, where k is the smallest integer satisfying
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