Main Content

binoinv

Binomial inverse cumulative distribution function

Description

x = binoinv(y,n,p) returns the smallest integer x such that the binomial cdf evaluated at x is equal to or greater than y. You can think of y as the probability of observing x successes in n independent trials where p is the probability of success in each trial. Each value in x is a positive integer less than or equal to n.

example

Examples

collapse all

Find an interval that contains 95% of the values from a binomial distribution with 100 trials and a 0.6 probability of success in each trial.

n = 100;
p = 0.6;
x = binoinv([0.025 0.975],n,p)
x = 1×2

    50    69

There is a 2.5% probability of getting less than or equal to 50 successes, and 97.5% probability of getting less than or equal to 69 successes. In other words, in 95% of the trials, the number of successes will be between 50 to 69.

Input Arguments

collapse all

Probability values at which to evaluate the inverse of the cdf (icdf), specified as a scalar value or an array of scalar values, where each element is in the range [0,1].

To evaluate the icdf at multiple values, specify y using an array. To evaluate the icdfs of multiple distributions, specify n and p using arrays. If one or more of the input arguments y, n, and p are arrays, then the array sizes must be the same. In this case, binoinv expands each scalar input into a constant array of the same size as the array inputs. Each element in x is the icdf value of the distribution specified by the corresponding elements in n and p, evaluated at the corresponding element in y.

Example: [0.1,0.5,0.9]

Data Types: single | double

Number of trials, specified as a positive integer or an array of positive integers.

To evaluate the icdfs of multiple distributions, specify n and p using arrays. If one or more of the input arguments y, n, and p are arrays, then the array sizes must be the same. In this case, binoinv expands each scalar input into a constant array of the same size as the array inputs. Each element in x is the icdf value of the distribution specified by the corresponding elements in n and p, evaluated at the corresponding element in y.

Example: [10 20 50 100]

Data Types: single | double

Probability of success for each trial, specified as a scalar value or an array of scalar values. All values of p must belong to the interval [0 1].

To evaluate the icdfs of multiple distributions, specify n and p using arrays. If one or more of the input arguments y, n, and p are arrays, then the array sizes must be the same. In this case, binoinv expands each scalar input into a constant array of the same size as the array inputs. Each element in x is the icdf value of the distribution specified by the corresponding elements in n and p, evaluated at the corresponding element in y.

Example: [0.01 0.1 0.5 0.7]

Data Types: single | double

Output Arguments

collapse all

icdf values, evaluated at the probability values in y, returned as a scalar value or an array of scalar values. x is the same size as y, n, and p after any necessary scalar expansion. Each element in x is the icdf value of the distribution specified by the corresponding elements in n and p, evaluated at the corresponding element in y.

Algorithms

The software uses various methods to approximate the inverse of the binomial cumulative distribution function:

  1. It applies an asymptotic inversion using the complementary error function under valid conditions specified in [1].

  2. For values of n greater than or equal to 20 and p less than or equal to 0.05, a Poisson approximation is used if the asymptotic method is not suitable.

  3. If neither of the previous methods are applicable, the software uses the Cornish-Fisher [2] expansion truncated at the first order to include skewness.

After computing the approximate inverse, the software finds the exact inverse by searching in the vicinity of the approximated value.

References

[1] Gil, A., J. Segura, and N. M. Temme. “Asymptotic Inversion of the Binomial and Negative Binomial Cumulative Distribution Functions.” ETNA - Electronic Transactions on Numerical Analysis 52 (2020): 270–80, Section 3, Pg 6.

[2] Cornish, E. A., and R. A. Fisher. “Moments and Cumulants in the Specification of Distributions.” Revue de l’Institut International de Statistique / Review of the International Statistical Institute 5, no. 4 (January 1938): 307.

Extended Capabilities

expand all

Version History

Introduced before R2006a

expand all