Evaluates the negative binomial distribution CDF.

View versions (1)

Interface

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

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

This function returns the lower and upper tails of the comulative negative binomial distribution function. The negative binomial distribution, also known as the Pascal distribution or Pólya distribution, gives the probability of r-1 successes and x failures in x+r-1 trials, and success on the (x+r)th trial.

Example:

#include <stdio.h>
#include <codecogs/statistics/distributions/discrete/negativebinomial/cdf.h>
using namespace Stats::Dists::Discrete::NegativeBinomial;
int main()
{
  int k[10] = { 1, 3, 0, 5, 6, 5, 1, 5, 6, 3 };
  int n[10] = { 4, 3, 8, 1, 2, 4, 9, 5, 1, 2 };
  double p[10] = { 0.4, 0.1, 0.7, 0.2, 0.3, 0.6, 0.2, 0.7, 0.3, 0.2 };
  for( int i=0; i<10; i++ )
    printf( "CDF( %i, %i, %1.1f, true ) = %f \n",
      k[i], n[i], p[i], CDF(k[i],n[i],p[i],true) );
  return getchar();
}

Output:

CDF( 1, 4, 0.4, true ) = 0.912960
CDF( 3, 3, 0.1, true ) = 0.984150
CDF( 0, 8, 0.7, true ) = 0.942352
CDF( 5, 1, 0.2, true ) = 0.262144
CDF( 6, 2, 0.3, true ) = 0.255298
CDF( 5, 4, 0.6, true ) = 0.099353
CDF( 1, 9, 0.2, true ) = 0.999996
CDF( 5, 5, 0.7, true ) = 0.047349
CDF( 6, 1, 0.3, true ) = 0.082354
CDF( 3, 2, 0.2, true ) = 0.737280

Accuracy:

Tested at random points (a,b,p) with p between 0 and 1.
a,b domain   # trials      peak         rms
  0,100       100000      1.7e-13     8.8e-15

Parameters

k
the maximum number of failures, must be >= 0
n
the number of sucesses
p
the probability of success for each trial, must be in range 0..1
upper
Default value = false

Returns

the probability that more than k failures precede the nth success in a sequence of Bernoulli trials.
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

k
n
p
upper
Result