SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.probdist.NegativeBinomialDist Class Reference

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

Inheritance diagram for umontreal.ssj.probdist.NegativeBinomialDist:
umontreal.ssj.probdist.DiscreteDistributionInt umontreal.ssj.probdist.Distribution umontreal.ssj.probdist.PascalDist

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)
 Returns \(p(x)\), the probability of \(x\).
double cdf (int x)
 Returns the distribution function \(F\) evaluated at \(x\) (see ( FDistDisc )).
double barF (int x)
 Returns \(\bar{F}(x)\), the complementary distribution function.
int inverseFInt (double u)
 Returns the inverse distribution function \(F^{-1}(u)\), where.
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.
double[] getParams ()
 Return a table containing the parameters of the current distribution.
String toString ()
 Returns a String containing information about the current distribution.
Public Member Functions inherited from umontreal.ssj.probdist.DiscreteDistributionInt
double cdf (double x)
 Returns the distribution function \(F\) evaluated at \(x\) (see ( FDistDisc )).
double barF (double x)
 Returns \(\bar{F}(x)\), the complementary distribution function.
int getXinf ()
 Returns the lower limit \(x_a\) of the support of the probability mass function.
int getXsup ()
 Returns the upper limit \(x_b\) of the support of the probability mass function.
double inverseF (double u)
 Returns the inverse distribution function \(F^{-1}(u)\), where.

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\).
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]\),.
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 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]\),.
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 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 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\).
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 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.
static double getStandardDeviation (double n, double p)
 Computes and returns the standard deviation of the negative binomial distribution with parameters \(n\) and \(p\).

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 umontreal.ssj.probdist.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.

Detailed Description

Extends the class DiscreteDistributionInt for the negative binomial distribution [114]  (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 ).

 <div class="SSJ-bigskip"></div>

Definition at line 52 of file NegativeBinomialDist.java.

Constructor & Destructor Documentation

◆ NegativeBinomialDist()

umontreal.ssj.probdist.NegativeBinomialDist.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\).

Definition at line 169 of file NegativeBinomialDist.java.

Member Function Documentation

◆ barF() [1/2]

double umontreal.ssj.probdist.NegativeBinomialDist.barF ( double n,
double p,
int x )
static

Returns \(\bar{F}(x) = P[X \ge x]\), the complementary distribution function.

Definition at line 353 of file NegativeBinomialDist.java.

◆ barF() [2/2]

double umontreal.ssj.probdist.NegativeBinomialDist.barF ( int x)

Returns \(\bar{F}(x)\), the complementary distribution function.

See the WARNING above. The default implementation returns 1.0 - cdf(x - 1), which is not accurate when \(F(x)\) is near 1.

Parameters
xvalue at which the complementary distribution function must be evaluated
Returns
the complementary distribution function evaluated at x

Reimplemented from umontreal.ssj.probdist.DiscreteDistributionInt.

Definition at line 219 of file NegativeBinomialDist.java.

◆ cdf() [1/2]

double umontreal.ssj.probdist.NegativeBinomialDist.cdf ( double n,
double p,
int x )
static

Computes the distribution function.

Definition at line 298 of file NegativeBinomialDist.java.

◆ cdf() [2/2]

double umontreal.ssj.probdist.NegativeBinomialDist.cdf ( int x)

Returns the distribution function \(F\) evaluated at \(x\) (see ( FDistDisc )).

Parameters
xvalue at which the distribution function must be evaluated
Returns
the distribution function evaluated at x

Reimplemented from umontreal.ssj.probdist.DiscreteDistributionInt.

Definition at line 196 of file NegativeBinomialDist.java.

◆ getGamma()

double umontreal.ssj.probdist.NegativeBinomialDist.getGamma ( )

Returns the parameter \(n\) of this object.

Definition at line 704 of file NegativeBinomialDist.java.

◆ getInstanceFromMLE() [1/2]

NegativeBinomialDist umontreal.ssj.probdist.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

Reimplemented in umontreal.ssj.probdist.PascalDist.

Definition at line 600 of file NegativeBinomialDist.java.

◆ getInstanceFromMLE() [2/2]

NegativeBinomialDist umontreal.ssj.probdist.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

Definition at line 470 of file NegativeBinomialDist.java.

◆ getInstanceFromMLE1()

NegativeBinomialDist umontreal.ssj.probdist.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

Definition at line 516 of file NegativeBinomialDist.java.

◆ getMean() [1/2]

double umontreal.ssj.probdist.NegativeBinomialDist.getMean ( )

Returns the mean of the distribution function.

Implements umontreal.ssj.probdist.Distribution.

Definition at line 251 of file NegativeBinomialDist.java.

◆ getMean() [2/2]

double umontreal.ssj.probdist.NegativeBinomialDist.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\)

Definition at line 665 of file NegativeBinomialDist.java.

◆ getMLE() [1/2]

double[] umontreal.ssj.probdist.NegativeBinomialDist.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 [93]  (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}\)]

Reimplemented in umontreal.ssj.probdist.PascalDist.

Definition at line 539 of file NegativeBinomialDist.java.

◆ getMLE() [2/2]

double[] umontreal.ssj.probdist.NegativeBinomialDist.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}\)]

Definition at line 447 of file NegativeBinomialDist.java.

◆ getMLE1()

double[] umontreal.ssj.probdist.NegativeBinomialDist.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}\)]

Definition at line 491 of file NegativeBinomialDist.java.

◆ getMLEninv()

double umontreal.ssj.probdist.NegativeBinomialDist.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 [93]  (page 132)).

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

Definition at line 620 of file NegativeBinomialDist.java.

◆ getN()

double umontreal.ssj.probdist.NegativeBinomialDist.getN ( )

Returns the parameter \(n\) of this object.

Definition at line 711 of file NegativeBinomialDist.java.

◆ getP()

double umontreal.ssj.probdist.NegativeBinomialDist.getP ( )

Returns the parameter \(p\) of this object.

Definition at line 718 of file NegativeBinomialDist.java.

◆ getParams()

double[] umontreal.ssj.probdist.NegativeBinomialDist.getParams ( )

Return a table containing the parameters of the current distribution.

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

Implements umontreal.ssj.probdist.Distribution.

Definition at line 840 of file NegativeBinomialDist.java.

◆ getStandardDeviation() [1/2]

double umontreal.ssj.probdist.NegativeBinomialDist.getStandardDeviation ( )

Returns the standard deviation of the distribution function.

Implements umontreal.ssj.probdist.Distribution.

Definition at line 259 of file NegativeBinomialDist.java.

◆ getStandardDeviation() [2/2]

double umontreal.ssj.probdist.NegativeBinomialDist.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

Definition at line 696 of file NegativeBinomialDist.java.

◆ getVariance() [1/2]

double umontreal.ssj.probdist.NegativeBinomialDist.getVariance ( )

Returns the variance of the distribution function.

Implements umontreal.ssj.probdist.Distribution.

Definition at line 255 of file NegativeBinomialDist.java.

◆ getVariance() [2/2]

double umontreal.ssj.probdist.NegativeBinomialDist.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\)

Definition at line 681 of file NegativeBinomialDist.java.

◆ inverseF()

int umontreal.ssj.probdist.NegativeBinomialDist.inverseF ( double n,
double p,
double u )
static

Computes the inverse function without precomputing tables.

Definition at line 360 of file NegativeBinomialDist.java.

◆ inverseFInt()

int umontreal.ssj.probdist.NegativeBinomialDist.inverseFInt ( double u)

Returns the inverse distribution function \(F^{-1}(u)\), where.

\(0\le u\le1\). The default implementation uses binary search.

Parameters
uvalue in the interval \((0,1)\) for which the inverse distribution function is evaluated
Returns
the inverse distribution function evaluated at u
Exceptions
IllegalArgumentExceptionif \(u\) is not in the interval \((0,1)\)
ArithmeticExceptionif the inverse cannot be computed, for example if it would give infinity in a theoritical context

Reimplemented from umontreal.ssj.probdist.DiscreteDistributionInt.

Definition at line 244 of file NegativeBinomialDist.java.

◆ prob() [1/2]

double umontreal.ssj.probdist.NegativeBinomialDist.prob ( double n,
double p,
int x )
static

Computes the probability \(p(x)\) defined in ( fmass-negbin ).

Definition at line 267 of file NegativeBinomialDist.java.

◆ prob() [2/2]

double umontreal.ssj.probdist.NegativeBinomialDist.prob ( int x)

Returns \(p(x)\), the probability of \(x\).

Parameters
xvalue at which the mass function must be evaluated
Returns
the mass function evaluated at x

Reimplemented from umontreal.ssj.probdist.DiscreteDistributionInt.

Definition at line 173 of file NegativeBinomialDist.java.

◆ setParams()

void umontreal.ssj.probdist.NegativeBinomialDist.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.

Definition at line 725 of file NegativeBinomialDist.java.

◆ toString()

String umontreal.ssj.probdist.NegativeBinomialDist.toString ( )

Returns a String containing information about the current distribution.

Reimplemented in umontreal.ssj.probdist.PascalDist.

Definition at line 848 of file NegativeBinomialDist.java.

Member Data Documentation

◆ MAXN

double umontreal.ssj.probdist.NegativeBinomialDist.MAXN = 100000
static

If the maximum term is greater than this constant, then the tables will not be precomputed.

Definition at line 154 of file NegativeBinomialDist.java.


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