SSJ  3.3.1
Stochastic Simulation in Java
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
NegativeBinomialDist Class Reference

Extends the class DiscreteDistributionInt for the negative binomial distribution [118]  (page 324) with real parameters \(n\) and \(p\), where \(n > 0\) and \(0\le p\le1\). More...

Inheritance diagram for NegativeBinomialDist:
[legend]
Collaboration diagram for NegativeBinomialDist:
[legend]

Public Member Functions

 NegativeBinomialDist (double n, double p)
 Creates an object that contains the probability terms ( fmass-negbin ) and the distribution function for the negative binomial distribution with parameters \(n\) and \(p\).
 
double prob (int x)
 
double cdf (int x)
 
double barF (int x)
 
int inverseFInt (double u)
 
double getMean ()
 Returns the mean of the distribution function.
 
double getVariance ()
 Returns the variance of the distribution function.
 
double getStandardDeviation ()
 Returns the standard deviation of the distribution function.
 
double getGamma ()
 Returns the parameter \(n\) of this object.
 
double getN ()
 Returns the parameter \(n\) of this object.
 
double getP ()
 Returns the parameter \(p\) of this object.
 
void setParams (double n, double p)
 Sets the parameter \(n\) and \(p\) of this object. More...
 
double [] getParams ()
 Return a table containing the parameters of the current distribution. More...
 
String toString ()
 Returns a String containing information about the current distribution.
 
- Public Member Functions inherited from DiscreteDistributionInt
abstract double prob (int x)
 Returns \(p(x)\), the probability of \(x\). More...
 
double cdf (double x)
 Returns the distribution function \(F\) evaluated at \(x\) (see ( FDistDisc )). More...
 
abstract double cdf (int x)
 Returns the distribution function \(F\) evaluated at \(x\) (see ( FDistDisc )). More...
 
double barF (double x)
 Returns \(\bar{F}(x)\), the complementary distribution function. More...
 
double barF (int x)
 Returns \(\bar{F}(x)\), the complementary distribution function. More...
 
int getXinf ()
 Returns the lower limit \(x_a\) of the support of the probability mass function. More...
 
int getXsup ()
 Returns the upper limit \(x_b\) of the support of the probability mass function. More...
 
double inverseF (double u)
 Returns the inverse distribution function \(F^{-1}(u)\), where. More...
 
int inverseFInt (double u)
 Returns the inverse distribution function \(F^{-1}(u)\), where. More...
 

Static Public Member Functions

static double prob (double n, double p, int x)
 Computes the probability \(p(x)\) defined in ( fmass-negbin ).
 
static double cdf (double n, double p, int x)
 Computes the distribution function.
 
static double barF (double n, double p, int x)
 Returns \(\bar{F}(x) = P[X \ge x]\), the complementary distribution function.
 
static int inverseF (double n, double p, double u)
 Computes the inverse function without precomputing tables.
 
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\). More...
 
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\). More...
 
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\). More...
 
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\). More...
 
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\). More...
 
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\). More...
 
static double getMLEninv (int[] x, int m)
 Estimates and returns the parameter \(\nu= 1/\hat{n}\) of the negative binomial distribution using the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1, …, m-1\). More...
 
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\). More...
 
static double getVariance (double n, double p)
 Computes and returns the variance \(\mbox{Var}[X] = n(1 - p)/p^2\) of the negative binomial distribution with parameters \(n\) and \(p\). More...
 
static double getStandardDeviation (double n, double p)
 Computes and returns the standard deviation of the negative binomial distribution with parameters \(n\) and \(p\). More...
 

Static Public Attributes

Constant
static double MAXN = 100000
 If the maximum term is greater than this constant, then the tables will not be precomputed.
 
- Static Public Attributes inherited from DiscreteDistributionInt
static double EPSILON = 1.0e-16
 Environment variable that determines what probability terms can be considered as negligible when building precomputed tables for distribution and mass functions. More...
 

Protected Attributes

double n
 
double p
 
- Protected Attributes inherited from DiscreteDistributionInt
double cdf [] = null
 
double pdf [] = null
 
int xmin = 0
 
int xmax = 0
 
int xmed = 0
 
int supportA = Integer.MIN_VALUE
 
int supportB = Integer.MAX_VALUE
 

Additional Inherited Members

- Static Protected Attributes inherited from DiscreteDistributionInt
static final double EPS_EXTRA = 1.0e-6
 

Detailed Description

Extends the class DiscreteDistributionInt for the negative binomial distribution [118]  (page 324) with real parameters \(n\) and \(p\), where \(n > 0\) and \(0\le p\le1\).

Its mass function is

\[ p(x) = \frac{\Gamma(n + x)}{\Gamma(n)\; x!} p^n (1 - p)^x, \qquad\mbox{for } x = 0, 1, 2, …\tag{fmass-negbin} \]

where \(\Gamma(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 ).

Member Function Documentation

◆ getInstanceFromMLE() [1/2]

static NegativeBinomialDist getInstanceFromMLE ( int []  x,
int  m,
double  n 
)
static

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
xthe list of observations to use to evaluate parameters
mthe number of observations to use to evaluate parameters
nthe first parameter of the negative binomial

◆ getInstanceFromMLE() [2/2]

static NegativeBinomialDist getInstanceFromMLE ( int []  x,
int  m 
)
static

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
xthe list of observations to use to evaluate parameters
mthe number of observations used to evaluate parameters

◆ getInstanceFromMLE1()

static NegativeBinomialDist getInstanceFromMLE1 ( int []  x,
int  m,
double  p 
)
static

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
xthe list of observations to use to evaluate parameters
mthe number of observations to use to evaluate parameters
pthe second parameter of the negative binomial

◆ getMean()

static double getMean ( double  n,
double  p 
)
static

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\)

◆ getMLE() [1/2]

static double [] getMLE ( int []  x,
int  m,
double  n 
)
static

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
xthe list of observations used to evaluate parameters
mthe number of observations used to evaluate parameters
nthe first parameter of the negative binomial
Returns
returns the parameters [ \(\hat{p}\)]

◆ getMLE() [2/2]

static double [] getMLE ( int []  x,
int  m 
)
static

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\)]. The maximum likelihood estimators are the values \((\hat{n}\), \(\hat{p})\) satisfying the equations

\begin{align*} \frac{\hat{n}(1 - \hat{p})}{\hat{p}} & = \bar{x}_m \\ \sum_{j=1}^{\infty} \frac{F_j}{(\hat{n} + j - 1)} & = -m\ln(\hat{p}) \end{align*}

where \(\bar{x}_m\) is the average of \(x[0],…,x[m-1]\), and \(F_j = \sum_{i=j}^{\infty} f_i\) = number of \(x_i \ge j\) (see [97]  (page 132)).

Parameters
xthe list of observations used to evaluate parameters
mthe number of observations used to evaluate parameters
Returns
returns the parameters [ \(\hat{n}\), \(\hat{p}\)]

◆ getMLE1()

static double [] getMLE1 ( int []  x,
int  m,
double  p 
)
static

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. The maximum likelihood estimator \(\hat{p}\) satisfies the equation

\[ \frac{1}{m}\sum_{j=0}^{m-1} \psi(n +x_j) = \psi(n) - \ln(p) \]

where \(\psi(x)\) is the digamma function, i.e. the logarithmic derivative of the Gamma function \(\psi(x) = \Gamma^{\prime}(x)/\Gamma(x)\).

Parameters
xthe list of observations used to evaluate parameters
mthe number of observations used to evaluate parameters
pthe second parameter of the negative binomial
Returns
returns the parameters [ \(\hat{n}\)]

◆ getMLEninv()

static double getMLEninv ( int []  x,
int  m 
)
static

Estimates and returns the parameter \(\nu= 1/\hat{n}\) of the negative binomial distribution using the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1, …, m-1\).

The maximum likelihood estimator is the value \(\nu\) satisfying the equation

\[ \sum_{j=1}^{\infty} \frac{\nu F_j}{1 + \nu(j - 1)} = m\ln(1 + \nu\bar{x}_m) \]

where \(\bar{x}_m\) is the average of \(x[0],…,x[m-1]\), and \(F_j = \sum_{i=j}^{\infty} f_i\) = number of \(x_i \ge j\) (see [97]  (page 132)).

Parameters
xthe list of observations used to evaluate parameter
mthe number of observations used to evaluate parameter
Returns
returns the parameter \(\nu\)

◆ getParams()

double [] getParams ( )

Return a table containing the parameters of the current distribution.

This table is put in regular order: [ \(n\), \(p\)].

Implements Distribution.

◆ getStandardDeviation()

static double getStandardDeviation ( double  n,
double  p 
)
static

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

◆ getVariance()

static double getVariance ( double  n,
double  p 
)
static

Computes and returns the variance \(\mbox{Var}[X] = n(1 - p)/p^2\) of the negative binomial distribution with parameters \(n\) and \(p\).

Returns
the variance of the negative binomial distribution \(\mbox{Var}[X] = n(1 - p) / p^2\)

◆ setParams()

void setParams ( double  n,
double  p 
)

Sets the parameter \(n\) and \(p\) of this object.

Compute all probability terms of the negative binomial distribution; start at the mode, and calculate probabilities on each side until they become smaller than EPSILON. Set all others to 0.



For mode > MAXN, we shall not use pre-computed arrays. mode < 0 should be impossible, unless overflow of long occur, in which case mode will be = LONG_MIN.

In theory, the negative binomial distribution has an infinite range. But for i > Nmax, probabilities should be extremely small. Nmax = Mean + 16 * Standard deviation.


The documentation for this class was generated from the following file: