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

Extends the class ContinuousDistribution for the chi-square distribution with \(n\) degrees of freedom, where \(n\) is a positive integer [99]  (page 416). More...

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

Public Member Functions

 ChiSquareDist (int n)
 Constructs a chi-square distribution with n degrees of freedom.
 
double density (double x)
 
double cdf (double x)
 Returns the distribution function \(F(x)\). More...
 
double barF (double x)
 Returns \(\bar{F}(x) = 1 - F(x)\). More...
 
double inverseF (double u)
 Returns the inverse distribution function \(F^{-1}(u)\), defined in ( inverseF ). More...
 
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.
 
void setN (int n)
 Sets the parameter \(n\) 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 ContinuousDistribution
abstract double density (double x)
 Returns \(f(x)\), the density evaluated at \(x\). More...
 
double barF (double x)
 Returns the complementary distribution function. More...
 
double inverseBrent (double a, double b, double u, double tol)
 Computes the inverse distribution function \(x = F^{-1}(u)\), using the Brent-Dekker method. More...
 
double inverseBisection (double u)
 Computes and returns the inverse distribution function \(x = F^{-1}(u)\), using bisection. More...
 
double inverseF (double u)
 Returns the inverse distribution function \(x = F^{-1}(u)\). More...
 
double getMean ()
 Returns the mean. More...
 
double getVariance ()
 Returns the variance. More...
 
double getStandardDeviation ()
 Returns the standard deviation. More...
 
double getXinf ()
 Returns \(x_a\) such that the probability density is 0 everywhere outside the interval \([x_a, x_b]\). More...
 
double getXsup ()
 Returns \(x_b\) such that the probability density is 0 everywhere outside the interval \([x_a, x_b]\). More...
 
void setXinf (double xa)
 Sets the value \(x_a=\) xa, such that the probability density is 0 everywhere outside the interval \([x_a, x_b]\). More...
 
void setXsup (double xb)
 Sets the value \(x_b=\) xb, such that the probability density is 0 everywhere outside the interval \([x_a, x_b]\). More...
 

Static Public Member Functions

static double density (int n, double x)
 Computes the density function ( Fchi2 ) for a chi-square distribution with \(n\) degrees of freedom.
 
static double cdf (int n, int d, double x)
 Computes the chi-square distribution function with \(n\) degrees of freedom, evaluated at \(x\). More...
 
static double barF (int n, int d, double x)
 Computes the complementary chi-square distribution function with \(n\) degrees of freedom, evaluated at \(x\). More...
 
static double inverseF (int n, double u)
 Computes an approximation of \(F^{-1}(u)\), where \(F\) is the chi-square distribution with \(n\) degrees of freedom. More...
 
static double [] getMLE (double[] x, int m)
 Estimates the parameter \(n\) of the chi-square distribution using the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1, …, m-1\). More...
 
static ChiSquareDist getInstanceFromMLE (double[] x, int m)
 Creates a new instance of a chi-square distribution with parameter \(n\) estimated using the maximum likelihood method based on the \(m\) observations \(x[i]\), \(i = 0, 1, …, m-1\). More...
 
static double getMean (int n)
 Computes and returns the mean \(E[X] = n\) of the chi-square distribution with parameter \(n\). More...
 
static double [] getMomentsEstimate (double[] x, int m)
 Estimates and returns the parameter [ \(\hat{n}\)] of the chi-square distribution using the moments method based on the \(m\) observations in table \(x[i]\), \(i = 0, 1, …, m-1\). More...
 
static double getVariance (int n)
 Returns the variance \(\mbox{Var}[X] = 2n\) of the chi-square distribution with parameter \(n\). More...
 
static double getStandardDeviation (int n)
 Returns the standard deviation of the chi-square distribution with parameter \(n\). More...
 

Protected Attributes

int n
 
double C1
 
- Protected Attributes inherited from ContinuousDistribution
double supportA = Double.NEGATIVE_INFINITY
 
double supportB = Double.POSITIVE_INFINITY
 

Additional Inherited Members

- Public Attributes inherited from ContinuousDistribution
int decPrec = 15
 
- Static Protected Attributes inherited from ContinuousDistribution
static final double XBIG = 100.0
 
static final double XBIGM = 1000.0
 
static final double [] EPSARRAY
 

Detailed Description

Extends the class ContinuousDistribution for the chi-square distribution with \(n\) degrees of freedom, where \(n\) is a positive integer [99]  (page 416).

Its density is

\[ f(x) = \frac{x^{(n/2)-1}e^{-x/2}}{2^{n/2}\Gamma(n/2)},\qquad\mbox{for } x > 0 \tag{Fchi2} \]

where \(\Gamma(x)\) is the gamma function defined in ( Gamma ). The chi-square distribution is a special case of the gamma distribution with shape parameter \(n/2\) and scale parameter \(1/2\). Therefore, one can use the methods of GammaDist for this distribution.

The non-static versions of the methods cdf, barF, and inverseF call the static version of the same name.

Member Function Documentation

◆ barF() [1/2]

double barF ( double  x)

Returns \(\bar{F}(x) = 1 - F(x)\).

Parameters
xvalue at which the complementary distribution function is evaluated
Returns
complementary distribution function evaluated at x

Implements Distribution.

◆ barF() [2/2]

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

Computes the complementary chi-square distribution function with \(n\) degrees of freedom, evaluated at \(x\).

The method tries to return \(d\) decimals digits of precision, but there is no guarantee.

◆ cdf() [1/2]

double cdf ( double  x)

Returns the distribution function \(F(x)\).

Parameters
xvalue at which the distribution function is evaluated
Returns
distribution function evaluated at x

Implements Distribution.

◆ cdf() [2/2]

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

Computes the chi-square distribution function with \(n\) degrees of freedom, evaluated at \(x\).

The method tries to return \(d\) decimals digits of precision, but there is no guarantee.

◆ getInstanceFromMLE()

static ChiSquareDist getInstanceFromMLE ( double []  x,
int  m 
)
static

Creates a new instance of a chi-square distribution with parameter \(n\) 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 to use to evaluate parameters

◆ getMean()

static double getMean ( int  n)
static

Computes and returns the mean \(E[X] = n\) of the chi-square distribution with parameter \(n\).

Returns
the mean of the Chi-square distribution \(E[X] = n\)

◆ getMLE()

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

Estimates the parameter \(n\) of the chi-square distribution using the maximum likelihood method, from the \(m\) observations \(x[i]\), \(i = 0, 1, …, m-1\).

The estimate is returned in element 0 of the returned array.

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

◆ getMomentsEstimate()

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

Estimates and returns the parameter [ \(\hat{n}\)] of the chi-square distribution using the moments method based on the \(m\) observations in table \(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
Returns
returns the parameter [ \(\hat{n}\)]

◆ getStandardDeviation()

static double getStandardDeviation ( int  n)
static

Returns the standard deviation of the chi-square distribution with parameter \(n\).

Returns
the standard deviation of the chi-square distribution

◆ getVariance()

static double getVariance ( int  n)
static

Returns the variance \(\mbox{Var}[X] = 2n\) of the chi-square distribution with parameter \(n\).

Returns
the variance of the chi-square distribution \(\mbox{Var}X] = 2n\)

◆ inverseF() [1/2]

double inverseF ( double  u)

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

Parameters
uvalue in the interval \((0,1)\) for which the inverse distribution function is evaluated
Returns
the inverse distribution function evaluated at u

Implements Distribution.

◆ inverseF() [2/2]

static double inverseF ( int  n,
double  u 
)
static

Computes an approximation of \(F^{-1}(u)\), where \(F\) is the chi-square distribution with \(n\) degrees of freedom.

Uses the approximation given in [17]  and in Figure L.23 of [25] . It gives at least 6 decimal digits of precision, except far in the tails (that is, for \(u< 10^{-5}\) or \(u > 1 - 10^{-5}\)) where the function calls the method GammaDist.inverseF (n/2, 7, u) and multiplies the result by 2.0. To get better precision, one may call GammaDist.inverseF, but this method is slower than the current method, especially for large \(n\). For instance, for \(n = \) 16, 1024, and 65536, the GammaDist.inverseF method is 2, 5, and 8 times slower, respectively, than the current method.


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