Class NegativeBinomialDistribution

java.lang.Object
smile.stat.distribution.DiscreteDistribution
smile.stat.distribution.NegativeBinomialDistribution
All Implemented Interfaces:
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)).

See Also:
  • Field Details

    • 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 Details

    • 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 Details

    • length

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

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

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

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

      public double entropy()
      Shannon's entropy. Not supported.
      Returns:
      Shannon entropy.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • rand

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

      public double p(int k)
      Description copied from class: DiscreteDistribution
      The probability mass function.
      Specified by:
      p in class DiscreteDistribution
      Parameters:
      k - a real value.
      Returns:
      the probability.
    • logp

      public double logp(int k)
      Description copied from class: DiscreteDistribution
      The probability mass function in log scale.
      Specified by:
      logp in class DiscreteDistribution
      Parameters:
      k - a real value.
      Returns:
      the log probability.
    • cdf

      public double cdf(double k)
      Description copied from interface: Distribution
      Cumulative distribution function. That is the probability to the left of x.
      Parameters:
      k - a real number.
      Returns:
      the probability.
    • 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.
      Parameters:
      p - the probability.
      Returns:
      the quantile.