# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# prob.NegativeBinomialDistribution class

Package: prob
Superclasses: prob.ToolboxFittableParametricDistribution

Negative binomial distribution object

## Description

`prob.NegativeBinomialDistribution` is an object consisting of parameters, a model description, and sample data for a negative binomial probability distribution.

Create a probability distribution object with specified parameter values using `makedist`. Alternatively, fit a distribution to data using `fitdist` or the Distribution Fitting app.

## Construction

`pd = makedist('NegativeBinomial')` creates a negative binomial probability distribution object using the default parameter values.

`pd = makedist('NegativeBinomial','R',R,'p',p)` creates a negative binomial probability distribution object using the specified parameter values.

### Input Arguments

expand all

Number of successes for the negative binomial distribution, specified as a positive scalar value.

Data Types: `single` | `double`

Probability of success of any individual trial for the negative binomial distribution, specified as a positive scalar value in the range (0,1].

Data Types: `single` | `double`

## Properties

expand all

Number of successes for the negative binomial distribution, stored as a positive scalar value.

Data Types: `single` | `double`

Probability of success of any individual trial for the negative binomial distribution, specified as a positive scalar value in the range (0,1].

Data Types: `single` | `double`

Probability distribution name, stored as a character vector. This property is read-only.

Data Types: `char`

Data used for distribution fitting, stored as a structure containing the following:

• `data`: Data vector used for distribution fitting.

• `cens`: Censoring vector, or empty if none.

• `freq`: Frequency vector, or empty if none.

Data Types: `struct`

Logical flag for truncated distribution, stored as a logical value. If `IsTruncated` equals `0`, the distribution is not truncated. If `IsTruncated` equals `1`, the distribution is truncated. This property is read-only.

Data Types: `logical`

Number of parameters for the probability distribution, stored as a positive integer value. This property is read-only.

Data Types: `single` | `double`

Covariance matrix of the parameter estimates, stored as a p-by-p matrix, where p is the number of parameters in the distribution. The (`i`,`j`) element is the covariance between the estimates of the `i`th parameter and the `j`th parameter. The (`i`,`i`) element is the estimated variance of the `i`th parameter. If parameter `i` is fixed rather than estimated by fitting the distribution to data, then the (`i`,`i`) elements of the covariance matrix are 0. This property is read-only.

Data Types: `single` | `double`

Distribution parameter descriptions, stored as a cell array of character vectors. Each cell contains a short description of one distribution parameter. This property is read-only.

Data Types: `char`

Logical flag for fixed parameters, stored as an array of logical values. If `0`, the corresponding parameter in the `ParameterNames` array is not fixed. If `1`, the corresponding parameter in the `ParameterNames` array is fixed. This property is read-only.

Data Types: `logical`

Distribution parameter names, stored as a cell array of character vectors. This property is read-only.

Data Types: `char`

Distribution parameter values, stored as a vector. This property is read-only.

Data Types: `single` | `double`

Truncation interval for the probability distribution, stored as a vector containing the lower and upper truncation boundaries. This property is read-only.

Data Types: `single` | `double`

## Methods

### Inherited Methods

 cdf Cumulative distribution function of probability distribution object icdf Inverse cumulative distribution function of probability distribution object iqr Interquartile range of probability distribution object median Median of probability distribution object pdf Probability density function of probability distribution object random Generate random numbers from probability distribution object truncate Truncate probability distribution object
 mean Mean of probability distribution object negloglik Negative log likelihood of probability distribution object paramci Confidence intervals for probability distribution parameters proflik Profile likelihood function for probability distribution object std Standard deviation of probability distribution object var Variance of probability distribution object

## Definitions

### Negative Binomial Distribution

The negative binomial distribution models the number of failures x before a specified number of successes is reached in a series of independent, identical trials. This distribution can also model count data, in which case r does not need to be an integer value.

The negative binomial distribution uses the following parameters.

ParameterDescriptionSupport
`R`Number of successes$r>0$
`p`Probability of success$0

The probability density function (pdf) when R is an integer is

`$f\left(x|R,p\right)=\left(\begin{array}{c}R+x+1\\ x\end{array}\right){p}^{R}{q}^{x}\text{ };\text{ }x=1,2,...,\infty \text{\hspace{0.17em}},$`

where $q=1-p$ and $\left(\begin{array}{c}R+x+1\\ x\end{array}\right)$ is the binomial coefficient.

When R is not an integer, the binomial coefficient in the definition of the pdf is replaced by the equivalent expression

`$\frac{\Gamma \left(r+x\right)}{\Gamma \left(r\right)\Gamma \left(x+1\right)}\text{\hspace{0.17em}},$`

where $\Gamma \left(\cdot \right)$ is the Gamma function.

## Examples

expand all

Create a negative binomial distribution object using the default parameter values.

`pd = makedist('NegativeBinomial')`
```pd = NegativeBinomialDistribution Negative Binomial distribution R = 1 P = 0.5```

Create a negative binomial distribution object by specifying the parameter values.

`pd = makedist('NegativeBinomial','r',5,'p',.1)`
```pd = NegativeBinomialDistribution Negative Binomial distribution R = 5 P = 0.1```

Compute the mean of the distribution.

`m = mean(pd)`
```m = 45```