# nbinstat

Negative binomial mean and variance

## Description

## Examples

### Calculate Mean and Variance for Negative Binomial Distribution

Generate vectors of values for the number of successes and probability of success in each trial.

P = 0.1:0.2:0.9; R = 1:5;

For each pair of elements in `P`

and `R`

, calculate the mean and variance for the corresponding negative binomial distribution.

[M,V] = nbinstat(R,P)

`M = `*1×5*
9.0000 4.6667 3.0000 1.7143 0.5556

`V = `*1×5*
90.0000 15.5556 6.0000 2.4490 0.6173

Each pair of elements in the vectors `M`

and `V`

contains the mean and variance for the negative binomial distributions corresponding to the pairs of elements at the same positions in `P`

and `R`

.

## Input Arguments

`R`

— Number of successes

positive scalar value | array of positive scalar values

Number of successes, specified as a positive scalar value or an array of positive
scalar values. The elements of `R`

can be noninteger values. If both
`R`

and `P`

are arrays, they must be the same
size. If either `R`

or `P`

is a scalar, then
`nbinstat`

expands the scalar argument into a constant array of
the same size as the other argument.

**Example: **`[3 1 7]`

**Data Types: **`single`

| `double`

`P`

— Probability of success

positive scalar value | array of positive scalar values

Probability of success in a single trial, specified as a positive scalar value or an
array of positive scalar values. The elements of `P`

must be between
0 and 1. If both `P`

and `R`

are arrays, they must
be the same size. If either `P`

or `R`

is a
scalar, then `nbinstat`

expands the scalar argument into a
constant array of the same size as the other argument.

**Example: **`[0.5 0.25 0.75]`

**Data Types: **`single`

| `double`

## Output Arguments

`M`

— Mean

numeric scalar | array of numeric scalars

Mean for the negative binomial distribution, returned as a numeric scalar or an
array of numeric scalars. `M`

is the same size as
`R`

and `P`

. Each element in
`M`

is the mean of the negative binomial distribution specified by
the corresponding elements in `R`

and `P`

. For
more information, see Mean.

**Data Types: **`single`

| `double`

`V`

— Variance

numeric scalar | array of numeric scalars

Variance for the negative binomial distribution, returned as a numeric scalar or an
array of numeric scalars. `V`

is the same size as
`R`

and `P`

. Each element in
`V`

is the variance of the negative binomial distribution specified
by the corresponding elements in `R`

and `P`

. For
more information, see Variance.

**Data Types: **`single`

| `double`

## More About

### Mean

The mean *m* of the negative binomial distribution with
*r* successes and probability *p* of success in each
trial is given by the formula

$$m=\frac{r(1-p)}{p}.$$

### Variance

The variance *v* of the negative binomial distribution with
*r* successes and probability *p* of success in each
trial is given by the formula

$$v=\frac{r(1-p)}{{p}^{2}}.$$

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

### GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

## Version History

**Introduced before R2006a**

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)