smile.stat.distribution

## Class NegativeBinomialDistribution

• All Implemented Interfaces:
java.io.Serializable, Distribution

```public class NegativeBinomialDistribution
extends DiscreteDistribution```
Negative binomial distribution arises as the probability distribution of the number of successes in a series of independent and identically distributed Bernoulli trials needed to get a specified (non-random) number r of failures. If r is an integer, it is usually called Pascal distribution. Otherwise, it is often called Polya distribution for the real-valued case. When r = 1 we get the probability distribution of number of successes before the first failure, which is a geometric distribution.

An alternative definition is that X is the total number of trials needed to get r failures, not simply the number of successes. This alternative parameterization can be used as an alternative to the Poisson distribution. It is especially useful for discrete data over an unbounded positive range whose sample variance exceeds the sample mean. If a Poisson distribution is used to model such data, the model mean and variance are equal. In that case, the observations are overdispersed with respect to the Poisson model. Since the negative binomial distribution has one more parameter than the Poisson, the second parameter can be used to adjust the variance independently of the mean. In the case of modest overdispersion, this may produce substantially similar results to an overdispersed Poisson distribution.

The negative binomial distribution also arises as a continuous mixture of Poisson distributions where the mixing distribution of the Poisson rate is a gamma distribution. That is, we can view the negative binomial as a Poisson(λ) distribution, where λ is itself a random variable, distributed according to Γ(r, p/(1 - p)).

Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
`double` `p`
The success probability in each experiment.
`double` `r`
The number of failures until the experiment is stopped.
• ### Constructor Summary

Constructors
Constructor and Description
```NegativeBinomialDistribution(double r, double p)```
Constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `cdf(double k)`
Cumulative distribution function.
`double` `entropy()`
Shannon entropy.
`int` `length()`
The number of parameters of the distribution.
`double` `logp(int k)`
The probability mass function in log scale.
`double` `mean()`
The mean of distribution.
`double` `p(int k)`
The probability mass function.
`double` `quantile(double p)`
The quantile, the probability to the left of quantile is p.
`double` `rand()`
Generates a random number following this distribution.
`double` `sd()`
The standard deviation of distribution.
`java.lang.String` `toString()`
`double` `variance()`
The variance of distribution.
• ### Methods inherited from class smile.stat.distribution.DiscreteDistribution

`likelihood, logLikelihood, logp, p, quantile, randi, randi`
• ### Methods inherited from class smile.stat.distribution.AbstractDistribution

`inverseTransformSampling, quantile, quantile, rejection`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Methods inherited from interface smile.stat.distribution.Distribution

`likelihood, logLikelihood, rand`
• ### Field Detail

• #### r

`public final double r`
The number of failures until the experiment is stopped.
• #### p

`public final double p`
The success probability in each experiment.
• ### Constructor Detail

• #### NegativeBinomialDistribution

```public NegativeBinomialDistribution(double r,
double p)```
Constructor.
Parameters:
`r` - the number of failures until the experiment is stopped.
`p` - success probability in each experiment.
• ### Method Detail

• #### length

`public int length()`
Description copied from interface: `Distribution`
The number of parameters of the distribution. The "length" is in the sense of the minimum description length principle.
• #### mean

`public double mean()`
Description copied from interface: `Distribution`
The mean of distribution.
• #### variance

`public double variance()`
Description copied from interface: `Distribution`
The variance of distribution.
• #### sd

`public double sd()`
Description copied from interface: `Distribution`
The standard deviation of distribution.
• #### entropy

`public double entropy()`
Shannon entropy. Not supported.
• #### toString

`public java.lang.String toString()`
Overrides:
`toString` in class `java.lang.Object`
• #### rand

`public double rand()`
Description copied from interface: `Distribution`
Generates a random number following this distribution.
• #### p

`public double p(int k)`
Description copied from class: `DiscreteDistribution`
The probability mass function.
Specified by:
`p` in class `DiscreteDistribution`
• #### logp

`public double logp(int k)`
Description copied from class: `DiscreteDistribution`
The probability mass function in log scale.
Specified by:
`logp` in class `DiscreteDistribution`
• #### cdf

`public double cdf(double k)`
Description copied from interface: `Distribution`
Cumulative distribution function. That is the probability to the left of x.
• #### quantile

`public double quantile(double p)`
Description copied from interface: `Distribution`
The quantile, the probability to the left of quantile is p. It is actually the inverse of cdf.