Contenido principal

nbininv

Negative binomial inverse cumulative distribution function

Description

x = nbininv(y,r,p) returns the inverse cumulative distribution function (cdf) of the negative binomial distribution with the corresponding number of successes r and probability of success in a single trial p. Because the binomial distribution is discrete, nbininv returns the smallest integer x such that the negative binomial cdf evaluated at x equals or exceeds y.

The simplest application of the negative binomial is the case of successive random trials, each having a constant probability p of success. The number of extra trials you must perform in order to observe a given number r of successes has a negative binomial distribution. However, consistent with a more general interpretation of the negative binomial, nbininv allows r to be any positive value, including nonintegers.

example

Examples

collapse all

Use the inverse of the negative binomial distribution to calculate how many times you need to flip a fair coin to have a 99% probability of getting 10 heads.

fairCoinP = 0.5;
nHeads = 10;
nFlips = nbininv(0.99,nHeads,fairCoinP) + nHeads
nFlips = 
33

Note that you must flip the coin at least 10 times to get 10 heads, which is why nHeads must be added to the output of the nbininv function.

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 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 r and p using arrays. If one or more of the input arguments y, r, and p are arrays, then the array sizes must be the same. In this case, nbininv 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 r and p, evaluated at the corresponding element in y.

Data Types: single | double

Number of successes, specified as a positive scalar or an array of positive scalars.

To evaluate the icdf at multiple values, specify y using an array. To evaluate the icdfs of multiple distributions, specify r and p using arrays. If one or more of the input arguments y, r, and p are arrays, then the array sizes must be the same. In this case, nbininv 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 r and p, evaluated at the corresponding element in y.

Data Types: single | double

Probability of success, specified as a positive scalar or an array of positive scalars 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 r and p using arrays. If one or more of the input arguments y, r, and p are arrays, then the array sizes must be the same. In this case, nbininv 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 r and p, evaluated at the corresponding element in y.

Data Types: single | double

Output Arguments

collapse all

Inverse cdf 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, r, and p after any necessary scalar expansion. Each element in x is the icdf value of the distribution specified by the corresponding elements in r and p, evaluated at the corresponding element in y.

Alternative Functionality

  • nbininv is a function specific to the negative binomial distribution. Statistics and Machine Learning Toolbox™ also offers the generic function icdf, which supports various probability distributions. To use icdf, create a NegativeBinomialDistribution probability distribution object and pass the object as an input argument or specify the probability distribution name and its parameters. Note that the distribution-specific function nbininv is faster than the generic function icdf.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a