The binomial distribution inverse CDF

You're viewing an older version of this page (#216). View the current version.

View versions (1)

Interface

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

using namespace Statistics::Distributions::Discrete::Binomial;

Finds the event probability p such that the sum of the terms 0 through k of the Binomial probability density is equal to the given cumulative probability y.

\graph k=1 n=2:10:5 y=0:1

Example:

#include <stdio.h>
#include <codecogs/statistics/distributions/discrete/binomial/cdf_inv.h>
#include <codecogs/statistics/distributions/discrete/binomial/cdf.h>
using namespace Stats::Dists::Discrete::Binomial;
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, true );
    printf( "%f \t %f \t %f \n", x, y, z );
  }
  return getchar();
}

Output:

x              CDF              INV
0.000000         1.000000        0.000000
0.100000         0.999853        0.100000
0.200000         0.993631        0.200000
0.300000         0.952651        0.300000
0.400000         0.833761        0.400000
0.500000         0.623047        0.500000
0.600000         0.366897        0.600000
0.700000         0.150268        0.700000
0.800000         0.032793        0.800000
0.900000         0.001635        0.900000
1.000000         0.000000        1.000000

Accuracy:

Tested at random points (a,b,p).
      p         a,b domain   # trials      peak         rms
0.001 to 1        0,100       100000      2.3e-14     6.4e-16
0.001 to 1        0,10000     100000      6.6e-12     1.2e-13
10^-6 to 0.001    0,100       100000      2.0e-12     1.3e-14
10^-6 to 0.001    0,10000     100000      1.5e-12     3.2e-14

Parameters

k
the maximum number of successes, must be >= 0
n
the total number of trials, must be >= k
y
the probability of at most k successes in n trials, must be in range 0..1
upper
Default value = false

Returns

the probability of success for each trial
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

k
n
y
upper
Result