SSJ  3.3.1
Stochastic Simulation in Java
Classes | Public Member Functions | Static Public Member Functions | List of all members

Extends the class DiscreteDistributionInt for the binomial distribution [118]  (page 321) with parameters \(n\) and \(p\), where \(n\) is a positive integer and \(0\le p\le1\). More...

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

Public Member Functions

 BinomialDist (int n, double p)
 Creates an object that contains the binomial terms ( fmass-binomial ), for \(0\le x\le n\), and the corresponding cumulative function. More...
 
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.
 
int getN ()
 Returns the parameter \(n\) of this object.
 
double getP ()
 Returns the parameter \(p\) of this object.
 
double [] getParams ()
 Returns a table that contains the parameters \((n,p)\) of the current distribution, in regular order: [ \(n\), \(p\)].
 
void setParams (int n, double p)
 Resets the parameters to these new values and recomputes everything as in the constructor. 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 (int n, double p, int x)
 Computes and returns the binomial probability \(p(x)\) in eq. More...
 
static double prob (int n, double p, double q, int x)
 A generalization of the previous method. More...
 
static double cdf (int n, double p, int x)
 Computes \(F(x)\), the distribution function of a binomial random variable with parameters \(n\) and \(p\), evaluated at \(x\). More...
 
static double barF (int n, double p, int x)
 Returns \(\bar{F}(x) = P[X \ge x]\), the complementary distribution function. More...
 
static int inverseF (int n, double p, double u)
 Computes \(x = F^{-1}(u)\), the inverse of the binomial distribution. More...
 
static double [] getMLE (int[] x, int m)
 Estimates the parameters \((n,p)\) of the binomial distribution using the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1,…, m-1\). More...
 
static BinomialDist getInstanceFromMLE (int[] x, int m)
 Creates a new instance of a binomial distribution with both parameters \(n\) and \(p\) 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, int n)
 Estimates the parameter \(p\) of the binomial distribution with given (fixed) parameter \(n\), by the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1,…, m-1\). More...
 
static BinomialDist getInstanceFromMLE (int[] x, int m, int n)
 Creates a new instance of a binomial distribution with given (fixed) parameter \(n\), and with parameter \(p\) estimated by the maximum likelihood method based on the \(m\) observations \(x[i]\), \(i = 0, 1, …, m-1\). More...
 
static double getMean (int n, double p)
 Computes the mean \(E[X] = np\) of the binomial distribution with parameters \(n\) and \(p\). More...
 
static double getVariance (int n, double p)
 Computes the variance \(\mbox{Var}[X] = np(1 - p)\) of the binomial distribution with parameters \(n\) and \(p\). More...
 
static double getStandardDeviation (int n, double p)
 Computes the standard deviation of the Binomial distribution with parameters \(n\) and \(p\). More...
 

Static Public Attributes

Constant
static double MAXN = 100000
 The value of the parameter \(n\) above which the tables are not precomputed by the constructor.
 
- 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...
 

Additional Inherited Members

- 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
 
- Static Protected Attributes inherited from DiscreteDistributionInt
static final double EPS_EXTRA = 1.0e-6
 

Detailed Description

Extends the class DiscreteDistributionInt for the binomial distribution [118]  (page 321) with parameters \(n\) and \(p\), where \(n\) is a positive integer and \(0\le p\le1\).

Its mass function is given by

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

and its distribution function is

\[ F (x) = \sum_{j=0}^x \binom{n}{j}\; p^j (1-p)^{n-j} \qquad\mbox{for } x = 0, 1, 2, …n, \tag{Fbinomial} \]

where nCr \((n,x)\) is the number of possible combinations of \(x\) elements chosen among a set of \(n\) elements.

Constructor & Destructor Documentation

◆ BinomialDist()

BinomialDist ( int  n,
double  p 
)

Creates an object that contains the binomial terms ( fmass-binomial ), for \(0\le x\le n\), and the corresponding cumulative function.

These values are computed and stored in dynamic arrays, unless \(n\) exceeds MAXN.

Member Function Documentation

◆ barF()

static double barF ( int  n,
double  p,
int  x 
)
static

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

The default implementation returns 1 - cdf(x-1), which is not accurate when \(F(x)\) is close to 1.

◆ cdf()

static double cdf ( int  n,
double  p,
int  x 
)
static

Computes \(F(x)\), the distribution function of a binomial random variable with parameters \(n\) and \(p\), evaluated at \(x\).

If \(n \le10000\), the non-negligible terms of the sum are added explicitly. If \(n > 10000\) and \(np (1-p) > 100\), the Camp-Paulson normal approximation [31], [181]  is used, otherwise, a Poisson approximation due to Bol’shev [22], [181]  is used.

◆ getInstanceFromMLE() [1/2]

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

Creates a new instance of a binomial distribution with both parameters \(n\) and \(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 estimate the parameters
mthe number of observations to use to estimate the parameters

◆ getInstanceFromMLE() [2/2]

static BinomialDist getInstanceFromMLE ( int []  x,
int  m,
int  n 
)
static

Creates a new instance of a binomial distribution with given (fixed) parameter \(n\), and with parameter \(p\) estimated by 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 to use to evaluate parameters
nthe parameter n of the binomial

◆ getMean()

static double getMean ( int  n,
double  p 
)
static

Computes the mean \(E[X] = np\) of the binomial distribution with parameters \(n\) and \(p\).

Returns
the mean of the Binomial distribution \(E[X] = np\)

◆ getMLE() [1/2]

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

Estimates the parameters \((n,p)\) of the 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})\) that satisfy the equations:

\begin{align*} \hat{n}\hat{p} & = \bar{x}_m \\ \sum_{i=0}^{R-1} \frac{f_i}{\hat{n} - i} & = - m \ln\left(1 - \frac{\bar{x}_m}{\hat{n}}\right) \end{align*}

where \(\bar{x}_m\) is the average of \(x[0],…,x[m-1]\), \(f_i\) is the number of \(x[i]\)’s that exceed \(i\), and \(R =\max(x[0],…,x[m-1])\) is the largest observation [97]  (page 57).

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

◆ getMLE() [2/2]

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

Estimates the parameter \(p\) of the binomial distribution with given (fixed) parameter \(n\), by the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1,…, m-1\).

Returns the estimator in an array with a single element.

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

◆ getStandardDeviation()

static double getStandardDeviation ( int  n,
double  p 
)
static

Computes the standard deviation of the Binomial distribution with parameters \(n\) and \(p\).

Returns
the standard deviation of the binomial distribution

◆ getVariance()

static double getVariance ( int  n,
double  p 
)
static

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

Returns
the variance of the binomial distribution \(\mbox{Var}[X] = np(1 - p)\)

◆ inverseF()

static int inverseF ( int  n,
double  p,
double  u 
)
static

Computes \(x = F^{-1}(u)\), the inverse of the binomial distribution.

If \(n\) is larger than 10000, the linear search starts from 0 and the cdf(int,double,int) static method is used to compute \(F(x)\) at different values of \(x\), which is much less efficient.

◆ prob() [1/2]

static double prob ( int  n,
double  p,
int  x 
)
static

Computes and returns the binomial probability \(p(x)\) in eq.

( fmass-binomial ).

◆ prob() [2/2]

static double prob ( int  n,
double  p,
double  q,
int  x 
)
static

A generalization of the previous method.

Computes and returns the binomial term

\[ f(x) = \binom{n}{x} p^x q^{n-x} = \frac{n!}{x!(n-x)!}\; p^x q^{n-x}, \tag{fmass-binom} \]

where \(p\) and \(q\) are arbitrary real numbers ( \(q\) is not necessarily equal to \(1-p\)). In the case where \(0 \le p \le1\) and \(q = 1-p\), the returned value is a probability term for the binomial distribution.

◆ setParams()

void setParams ( int  n,
double  p 
)

Resets the parameters to these new values and recomputes everything as in the constructor.

From the performance viewpoint, it is essentially the same as constructing a new BinomialDist object.


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