ibinomcdf

The ibinomcdf function calculates the inverse binomial cumulative distribution function (CDF).

Synopsis

ibinomcdf(obs_prob,trials,success_prob)

Summary

The inverse binomial CDF returns the smallest number x such that the binomial CDF evaluated at x is equal to or greater than obs_prob for number of trials trials with probability success_prob.

Example

This example creates an array with the binomial CDF for tossing a fair coin 10 times, and then calculates the inverse binomial CDF to demonstrate that the result matches the original values. (For a fair coin, the probability of heads on any given toss is 0.5.)

 

  1. Create a 1-by-11 array called coin_toss:

    AFL% CREATE ARRAY coin_toss<heads:double>[i=0:10];
    AFL% store(build(coin_toss, double(i)), coin_toss); 


    The output is:

    {i} heads
    {0} 0
    {1} 1
    {2} 2
    {3} 3
    {4} 4
    {5} 5
    {6} 6
    {7} 7
    {8} 8
    {9} 9
    {10} 10
  2. Apply the direct binomcdf function to the values in the attribute heads and store the result in the cumulative_prob array:

    AFL% store(apply(coin_toss, direct, binomcdf(heads, 10.0, 0.5)), cumulative_prob);


    The output is:

    {i} heads,direct
    {0} 0,0.000976562
    {1} 1,0.0107422
    {2} 2,0.0546875
    {3} 3,0.171875
    {4} 4,0.376953
    {5} 5,0.623047
    {6} 6,0.828125
    {7} 7,0.945312
    {8} 8,0.989258
    {9} 9,0.999023
    {10} 10,1
  3. Apply ibinomcdf to the direct probability values the cumulative_prob array:

    AFL% apply(cumulative_prob, inverse, ibinomcdf(direct, 10.0, 0.5));


    The output is:

    {i} heads,direct,inverse
    {0} 0,0.000976562,0
    {1} 1,0.0107422,1
    {2} 2,0.0546875,2
    {3} 3,0.171875,3
    {4} 4,0.376953,4
    {5} 5,0.623047,5
    {6} 6,0.828125,6
    {7} 7,0.945312,7
    {8} 8,0.989258,8
    {9} 9,0.999023,9
    {10} 10,1,10

    Note that the inverse attribute's probabilities match the number of heads from the original coin_toss array.

  4. Remove the example arrays:

    AFL% remove(coin_toss); remove(cumulative_prob);

 

Â