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

Extends the class DiscreteDistributionInt for the binomial distribution [114]  (page 321) with parameters \(n\) and. More...

Inheritance diagram for umontreal.ssj.probdist.BinomialDist:
umontreal.ssj.probdist.DiscreteDistributionInt umontreal.ssj.probdist.Distribution

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.
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.
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.
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 (int n, double p, int x)
 Computes and returns the binomial probability \(p(x)\) in eq.
static double prob (int n, double p, double q, int x)
 A generalization of the previous method.
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\).
static double barF (int n, double p, int x)
 Returns \(\bar{F}(x) = P[X \ge x]\), the complementary distribution function.
static int inverseF (int n, double p, double u)
 Computes \(x = F^{-1}(u)\), the inverse of the binomial distribution.
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.
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\).
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\).
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.
static double getMean (int n, double p)
 Computes the mean \(E[X] = np\) of the binomial distribution with parameters \(n\) and \(p\).
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\).
static double getStandardDeviation (int n, double p)
 Computes the standard deviation of the Binomial distribution with parameters \(n\) and \(p\).

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 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 binomial distribution [114]  (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.

Definition at line 50 of file BinomialDist.java.

Constructor & Destructor Documentation

◆ BinomialDist()

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

Definition at line 103 of file BinomialDist.java.

Member Function Documentation

◆ barF() [1/2]

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

Definition at line 430 of file BinomialDist.java.

◆ barF() [2/2]

double umontreal.ssj.probdist.BinomialDist.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 179 of file BinomialDist.java.

◆ cdf() [1/2]

double umontreal.ssj.probdist.BinomialDist.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 [30],

[176]  is used, otherwise, a Poisson approximation due to Bol’shev [21], [176]  is used.

Definition at line 330 of file BinomialDist.java.

◆ cdf() [2/2]

double umontreal.ssj.probdist.BinomialDist.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 137 of file BinomialDist.java.

◆ getInstanceFromMLE() [1/2]

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

Definition at line 587 of file BinomialDist.java.

◆ getInstanceFromMLE() [2/2]

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

Definition at line 630 of file BinomialDist.java.

◆ getMean() [1/2]

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

Returns the mean of the distribution function.

Implements umontreal.ssj.probdist.Distribution.

Definition at line 232 of file BinomialDist.java.

◆ getMean() [2/2]

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

Definition at line 642 of file BinomialDist.java.

◆ getMLE() [1/2]

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

Definition at line 535 of file BinomialDist.java.

◆ getMLE() [2/2]

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

Definition at line 604 of file BinomialDist.java.

◆ getN()

int umontreal.ssj.probdist.BinomialDist.getN ( )

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

Definition at line 789 of file BinomialDist.java.

◆ getP()

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

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

Definition at line 796 of file BinomialDist.java.

◆ getParams()

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

Returns a table that contains the parameters \((n,p)\) of the current distribution, in regular order: [ \(n\), \(p\)].

Implements umontreal.ssj.probdist.Distribution.

Definition at line 804 of file BinomialDist.java.

◆ getStandardDeviation() [1/2]

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

Returns the standard deviation of the distribution function.

Implements umontreal.ssj.probdist.Distribution.

Definition at line 240 of file BinomialDist.java.

◆ getStandardDeviation() [2/2]

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

Definition at line 673 of file BinomialDist.java.

◆ getVariance() [1/2]

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

Returns the variance of the distribution function.

Implements umontreal.ssj.probdist.Distribution.

Definition at line 236 of file BinomialDist.java.

◆ getVariance() [2/2]

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

Definition at line 658 of file BinomialDist.java.

◆ inverseF()

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

Definition at line 440 of file BinomialDist.java.

◆ inverseFInt()

int umontreal.ssj.probdist.BinomialDist.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 225 of file BinomialDist.java.

◆ prob() [1/3]

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

Definition at line 263 of file BinomialDist.java.

◆ prob() [2/3]

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

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

( fmass-binomial ).

Definition at line 248 of file BinomialDist.java.

◆ prob() [3/3]

double umontreal.ssj.probdist.BinomialDist.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 107 of file BinomialDist.java.

◆ setParams()

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

Definition at line 814 of file BinomialDist.java.

◆ toString()

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

Returns a String containing information about the current distribution.

Definition at line 821 of file BinomialDist.java.

Member Data Documentation

◆ MAXN

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

The value of the parameter \(n\) above which the tables are not precomputed by the constructor.

Definition at line 90 of file BinomialDist.java.


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