SSJ
V. 2.6.2.

umontreal.iro.lecuyer.probdist
Class NegativeBinomialDist

java.lang.Object
  extended by umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
      extended by umontreal.iro.lecuyer.probdist.NegativeBinomialDist
All Implemented Interfaces:
Distribution
Direct Known Subclasses:
PascalDist

public class NegativeBinomialDist
extends DiscreteDistributionInt

Extends the class DiscreteDistributionInt for the negative binomial distribution with real parameters n and p, where n > 0 and 0 <= p <= 1. Its mass function is

p(x) = Γ(n + x)/(Γ(nx!)pn(1 - p)x,        for x = 0, 1, 2,…

where Γ(x) is the gamma function.

If n is an integer, p(x) can be interpreted as the probability of having x failures before the n-th success in a sequence of independent Bernoulli trials with probability of success p. This special case is implemented as the Pascal distribution (see PascalDist).


Field Summary
static double MAXN
           
 
Fields inherited from class umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
EPSILON
 
Constructor Summary
NegativeBinomialDist(double n, double p)
          Creates an object that contains the probability terms and the distribution function for the negative binomial distribution with parameters n and p.
 
Method Summary
static double barF(double n, double p, int x)
          Returns bar(F)(x) = P[X >= x], the complementary distribution function.
 double barF(int x)
          Returns bar(F)(x), the complementary distribution function.
static double cdf(double n, double p, int x)
          Computes the distribution function.
 double cdf(int x)
          Returns the distribution function F evaluated at x (see).
 double getGamma()
          Deprecated. 
static NegativeBinomialDist getInstanceFromMLE(int[] x, int m)
          Creates a new instance of a negative binomial distribution with parameters n and p estimated using the maximum likelihood method based on the m observations x[i], i = 0, 1,…, m - 1.
static NegativeBinomialDist getInstanceFromMLE(int[] x, int m, double n)
          Creates a new instance of a negative binomial distribution with parameters n given and hat(p) estimated using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.
static NegativeBinomialDist getInstanceFromMLE1(int[] x, int m, double p)
          Creates a new instance of a negative binomial distribution with parameters p given and hat(n) estimated using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.
 double getMean()
          Returns the mean of the distribution function.
static double getMean(double n, double p)
          Computes and returns the mean E[X] = n(1 - p)/p of the negative binomial distribution with parameters n and p.
static double[] getMLE(int[] x, int m)
          Estimates the parameter (n, p) of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.
static double[] getMLE(int[] x, int m, double n)
          Estimates the parameter p of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.
static double[] getMLE1(int[] x, int m, double p)
          Estimates the parameter n of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.
static double getMLEninv(int[] x, int m)
          Estimates and returns the parameter ν = 1/hat(n) of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.
 double getN()
          Returns the parameter n of this object.
 double getP()
          Returns the parameter p of this object.
 double[] getParams()
          Return a table containing the parameters of the current distribution.
 double getStandardDeviation()
          Returns the standard deviation of the distribution function.
static double getStandardDeviation(double n, double p)
          Computes and returns the standard deviation of the negative binomial distribution with parameters n and p.
 double getVariance()
          Returns the variance of the distribution function.
static double getVariance(double n, double p)
          Computes and returns the variance Var[X] = n(1 - p)/p2 of the negative binomial distribution with parameters n and p.
static int inverseF(double n, double p, double u)
          Computes the inverse function without precomputing tables.
 int inverseFInt(double u)
          Returns the inverse distribution function F-1(u), where 0 <= u <= 1.
static double prob(double n, double p, int x)
          Computes the probability p(x).
 double prob(int x)
          Returns p(x), the probability of x.
 void setParams(double n, double p)
          Sets the parameter n and p of this object.
 String toString()
           
 
Methods inherited from class umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
barF, cdf, getXinf, getXsup, inverseF
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAXN

public static double MAXN
Constructor Detail

NegativeBinomialDist

public NegativeBinomialDist(double n,
                            double p)
Creates an object that contains the probability terms and the distribution function for the negative binomial distribution with parameters n and p.

Method Detail

prob

public double prob(int x)
Description copied from class: DiscreteDistributionInt
Returns p(x), the probability of x.

Specified by:
prob in class DiscreteDistributionInt
Parameters:
x - value at which the mass function must be evaluated
Returns:
the mass function evaluated at x

cdf

public double cdf(int x)
Description copied from class: DiscreteDistributionInt
Returns the distribution function F evaluated at x (see).

Specified by:
cdf in class DiscreteDistributionInt
Parameters:
x - value at which the distribution function must be evaluated
Returns:
the distribution function evaluated at x

barF

public double barF(int x)
Description copied from class: DiscreteDistributionInt
Returns bar(F)(x), the complementary distribution function. See the WARNING above.

Overrides:
barF in class DiscreteDistributionInt
Parameters:
x - value at which the complementary distribution function must be evaluated
Returns:
the complementary distribution function evaluated at x

inverseFInt

public int inverseFInt(double u)
Description copied from class: DiscreteDistributionInt
Returns the inverse distribution function F-1(u), where 0 <= u <= 1. The default implementation uses binary search.

Overrides:
inverseFInt in class DiscreteDistributionInt
Parameters:
u - value in the interval (0, 1) for which the inverse distribution function is evaluated
Returns:
the inverse distribution function evaluated at u

getMean

public double getMean()
Description copied from interface: Distribution
Returns the mean of the distribution function.


getVariance

public double getVariance()
Description copied from interface: Distribution
Returns the variance of the distribution function.


getStandardDeviation

public double getStandardDeviation()
Description copied from interface: Distribution
Returns the standard deviation of the distribution function.


prob

public static double prob(double n,
                          double p,
                          int x)
Computes the probability p(x).


cdf

public static double cdf(double n,
                         double p,
                         int x)
Computes the distribution function.


barF

public static double barF(double n,
                          double p,
                          int x)
Returns bar(F)(x) = P[X >= x], the complementary distribution function.


inverseF

public static int inverseF(double n,
                           double p,
                           double u)
Computes the inverse function without precomputing tables.


getMLE

public static double[] getMLE(int[] x,
                              int m,
                              double n)
Estimates the parameter p of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1. The parameter n is assumed known. The estimate hat(p) is returned in element 0 of the returned array. The maximum likelihood estimator hat(p) satisfies the equation hat(p) = n/(n + bar(x)m), where bar(x)m is the average of x[0],…, x[m - 1].

Parameters:
x - the list of observations used to evaluate parameters
m - the number of observations used to evaluate parameters
n - the first parameter of the negative binomial
Returns:
returns the parameters [hat(p)]

getInstanceFromMLE

public static NegativeBinomialDist getInstanceFromMLE(int[] x,
                                                      int m,
                                                      double n)
Creates a new instance of a negative binomial distribution with parameters n given and hat(p) estimated using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.

Parameters:
x - the list of observations to use to evaluate parameters
m - the number of observations to use to evaluate parameters
n - the first parameter of the negative binomial

getMLE1

public static double[] getMLE1(int[] x,
                               int m,
                               double p)
Estimates the parameter n of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1. The parameter p is assumed known. The estimate hat(n) is returned in element 0 of the returned array.

Parameters:
x - the list of observations used to evaluate parameters
m - the number of observations used to evaluate parameters
p - the second parameter of the negative binomial
Returns:
returns the parameters [hat(n)]

getInstanceFromMLE1

public static NegativeBinomialDist getInstanceFromMLE1(int[] x,
                                                       int m,
                                                       double p)
Creates a new instance of a negative binomial distribution with parameters p given and hat(n) estimated using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.

Parameters:
x - the list of observations to use to evaluate parameters
m - the number of observations to use to evaluate parameters
p - the second parameter of the negative binomial

getMLE

public static double[] getMLE(int[] x,
                              int m)
Estimates the parameter (n, p) of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1. The estimates are returned in a two-element array, in regular order: [n, p].

Parameters:
x - the list of observations used to evaluate parameters
m - the number of observations used to evaluate parameters
Returns:
returns the parameters [hat(n), hat(p)]

getInstanceFromMLE

public static NegativeBinomialDist getInstanceFromMLE(int[] x,
                                                      int m)
Creates a new instance of a negative binomial distribution with parameters n and p estimated using the maximum likelihood method based on the m observations x[i], i = 0, 1,…, m - 1.

Parameters:
x - the list of observations to use to evaluate parameters
m - the number of observations used to evaluate parameters

getMLEninv

public static double getMLEninv(int[] x,
                                int m)
Estimates and returns the parameter ν = 1/hat(n) of the negative binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.

Parameters:
x - the list of observations used to evaluate parameter
m - the number of observations used to evaluate parameter
Returns:
returns the parameter ν

getMean

public static double getMean(double n,
                             double p)
Computes and returns the mean E[X] = n(1 - p)/p of the negative binomial distribution with parameters n and p.

Returns:
the mean of the negative binomial distribution E[X] = n(1 - p)/p

getVariance

public static double getVariance(double n,
                                 double p)
Computes and returns the variance Var[X] = n(1 - p)/p2 of the negative binomial distribution with parameters n and p.

Returns:
the variance of the negative binomial distribution Var[X] = n(1 - p)/p2

getStandardDeviation

public static double getStandardDeviation(double n,
                                          double p)
Computes and returns the standard deviation of the negative binomial distribution with parameters n and p.

Returns:
the standard deviation of the negative binomial distribution

getGamma

@Deprecated
public double getGamma()
Deprecated. 


getN

public double getN()
Returns the parameter n of this object.


getP

public double getP()
Returns the parameter p of this object.


setParams

public void setParams(double n,
                      double p)
Sets the parameter n and p of this object.


getParams

public double[] getParams()
Return a table containing the parameters of the current distribution. This table is put in regular order: [n, p].


toString

public String toString()
Overrides:
toString in class Object

SSJ
V. 2.6.2.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.