The negative binomial distribution inverse CDF

View versions (1)

Interface

#include <codecogs/statistics/distributions/discrete/negativebinomial/cdf_inv.h>

using namespace Statistics::Distributions::Discrete::Negativebinomial;

Functional inverse of negative binomial distribution CDF. Finds the argument p such that CDF(k,n,p) is equal to y.

Example:

#include <stdio.h>
#include <codecogs/stats/dists/discrete/negativebinomial/cdf_inv.h>
#include <codecogs/stats/dists/discrete/negativebinomial/cdf.h>
using namespace Stats::Dists::Discrete::NegativeBinomial;
int main()
{
  printf( "    x              CDF              INV \n" );
  for( double x=0; x<1; x+=0.1 )
  {
    double y = CDF( 5, 10, x );
    double z = CDF_inv( 5, 10, y );
    printf( "%f \t %f \t %f \n", x, y, z );
  }
  return getchar();
}

Output:

x              CDF              INV
0.000000         0.000000        0.000000
0.100000         0.000000        0.100000
0.200000         0.000113        0.200000
0.300000         0.003653        0.300000
0.400000         0.033833        0.400000
0.500000         0.150879        0.500000
0.600000         0.403216        0.600000
0.700000         0.721621        0.700000
0.800000         0.938949        0.800000
0.900000         0.997750        0.900000
1.000000         1.000000        1.000000

Accuracy:

Tested at random points (a,b,y) with y between 0 and 1.

a,b domain   # trials      peak         rms
  0,100       100000      1.5e-14     8.5e-16

Parameters

k
the maximum number of failures, must be >= 0
n
the number of sucesses
p
the probability that k or fewer failures precede the nth success in a sequence of Bernoulli trials, must be in range 0..1.
upper
Default value = false

Returns

the probability of success for each trial

in the example shownn above, the result loses accuracy toward x=1

GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

k
n
p
upper
Result