Hauptinhalt

nbinpdf

Negative binomial probability density function

Description

y = nbinpdf(x,r,p) returns the negative binomial probability density function (pdf), evaluated at the values in x, using the corresponding number of successes r and the probability of success in a single trial p.

example

Examples

collapse all

Compute the probability density function (pdf) of the negative binomial distribution with the parameters r=3 and p=0.5 at integer values between –1 and 10.

x = -1:1:10;
r = 3;
p = 0.5;
y = nbinpdf(x,3,0.5);

Plot the pdf.

plot(x,y,"o")
grid on
ylabel("y")
xlabel("x")

Figure contains an axes object. The axes object with xlabel x, ylabel y contains a line object which displays its values using only markers.

The negative binomial pdf values are nonzero only for nonnegative integer values of x.

Input Arguments

collapse all

Values at which to evaluate the negative binomial pdf, specified as a nonnegative scalar or an array of nonnegative scalars. If x < 0 or is noninteger, the function returns a zero value for p.

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

Data Types: single | double

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

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

Data Types: single | double

Probability of success, specified as a positive scalar in the range (0,1] or an array of positive scalars in the range (0,1]. The function returns p=0 when x is less than 0 or is not an integer.

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

Data Types: single | double

Output Arguments

collapse all

Negative binomial pdf values, returned as a numeric scalar or array. y is the same size as x, r, and p after any necessary scalar expansion. Each element in y is the pdf value of the distribution specified by the corresponding elements in r and p, evaluated at the corresponding element in x.

More About

collapse all

Alternative Functionality

  • nbinpdf is a function specific to the negative binomial distribution. Statistics and Machine Learning Toolbox™ also offers the generic function pdf, which supports various probability distributions. To use pdf, 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 nbinpdf is faster than the generic function pdf.

  • Use the Probability Distribution Function Tool to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

Extended Capabilities

expand all

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

Version History

Introduced before R2006a