SSJ
V. 2.0.

umontreal.iro.lecuyer.probdist
Class ChiSquareDist

java.lang.Object
  extended by umontreal.iro.lecuyer.probdist.ContinuousDistribution
      extended by umontreal.iro.lecuyer.probdist.ChiSquareDist
All Implemented Interfaces:
Distribution
Direct Known Subclasses:
ChiSquareDistQuick

public class ChiSquareDist
extends ContinuousDistribution

Extends the class ContinuousDistribution for the chi-square distribution with n degrees of freedom, where n is a positive integer. Its density is

f (x) = x(n/2)-1e-x/2/(2n/2Γ(n/2)),         for x > 0.

where Γ(x) is the gamma function defined in GammaDist. 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.


Field Summary
 
Fields inherited from class umontreal.iro.lecuyer.probdist.ContinuousDistribution
decPrec
 
Constructor Summary
ChiSquareDist(int n)
          Constructs a chi-square distribution with n degrees of freedom.
 
Method Summary
 double barF(double x)
          Returns bar(F)(x) = 1 - F(x).
static double barF(int n, int d, double x)
          Computes the complementary chi-square distribution function with n degrees of freedom.
 double cdf(double x)
          Computes and returns the distribution function F(x).
static double cdf(int n, int d, double x)
          Computes an approximation of the chi-square distribution function with n degrees of freedom.
 double density(double x)
          Returns f (x), the density evaluated at x.
static double density(int n, double x)
          Computes the density function for a chi-square distribution with n degrees of freedom.
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.
static double[] getMaximumLikelihoodEstimate(double[] x, int m)
          Deprecated.
 double getMean()
          Returns the mean of the distribution function.
static double getMean(int n)
          Computes and returns the mean E[X] = n of the chi-square distribution with parameter n.
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.
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.
 int getN()
          Returns the parameter n of this object.
 double[] getParams()
          Return a table containing the parameters of the current distribution.
 double getStandardDeviation()
          Returns the standard deviation of the distribution function.
static double getStandardDeviation(int n)
          Computes and returns the standard deviation of the chi-square distribution with parameter n.
 double getVariance()
          Returns the variance of the distribution function.
static double getVariance(int n)
          Computes and returns the variance Var[X] = 2n of the chi-square distribution with parameter n.
 double inverseF(double u)
          Computes and returns the inverse distribution function F-1(u), defined in.
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.
 void setN(int n)
          Sets the parameter n of this object.
 String toString()
           
 
Methods inherited from class umontreal.iro.lecuyer.probdist.ContinuousDistribution
inverseBisection, inverseBrent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChiSquareDist

public ChiSquareDist(int n)
Constructs a chi-square distribution with n degrees of freedom.

Method Detail

density

public double density(double x)
Description copied from class: ContinuousDistribution
Returns f (x), the density evaluated at x.

Specified by:
density in class ContinuousDistribution
Parameters:
x - value at which the density is evaluated
Returns:
density function evaluated at x

cdf

public double cdf(double x)
Description copied from interface: Distribution
Computes and returns the distribution function F(x).

Parameters:
x - value at which the distribution function is evaluated
Returns:
distribution function evaluated at x

barF

public double barF(double x)
Description copied from interface: Distribution
Returns bar(F)(x) = 1 - F(x).

Specified by:
barF in interface Distribution
Overrides:
barF in class ContinuousDistribution
Parameters:
x - value at which the complementary distribution function is evaluated
Returns:
complementary distribution function evaluated at x

inverseF

public double inverseF(double u)
Description copied from interface: Distribution
Computes and returns the inverse distribution function F-1(u), defined in.

Specified by:
inverseF in interface Distribution
Overrides:
inverseF in class ContinuousDistribution
Parameters:
u - value in the interval (0, 1) for which the inverse distribution function is evaluated
Returns:
the inverse distribution function evaluated at u

getMean

public double getMean()
Description copied from interface: Distribution
Returns the mean of the distribution function.


getVariance

public double getVariance()
Description copied from interface: Distribution
Returns the variance of the distribution function.


getStandardDeviation

public double getStandardDeviation()
Description copied from interface: Distribution
Returns the standard deviation of the distribution function.


density

public static double density(int n,
                             double x)
Computes the density function for a chi-square distribution with n degrees of freedom.


cdf

public static double cdf(int n,
                         int d,
                         double x)
Computes an approximation of the chi-square distribution function with n degrees of freedom. Uses the approximation given by Kennedy and Gentle (1980) for n <= 350 (which gives nearly 12 decimal digits of precision for 10-5 < u < 1 - 10-5). For n > 350, this implementation invokes the method GammaDist.cdf (n/2, d, x/2) instead, because it is faster and as accurate as the above approximation for such n.


barF

public static double barF(int n,
                          int d,
                          double x)
Computes the complementary chi-square distribution function with n degrees of freedom. Uses the approximation given by Kennedy and Gentle for n <= 350, and invokes the method GammaDist.barF (n/2, d, x/2) for n > 350.


inverseF

public 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. 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.


getMLE

public 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. The estimate is returned in element 0 of the returned array.

Parameters:
x - the list of observations to use to evaluate parameters
m - the number of observations to use to evaluate parameters
Returns:
returns the parameter [hat(n)]

getMaximumLikelihoodEstimate

public static double[] getMaximumLikelihoodEstimate(double[] x,
                                                    int m)
Deprecated. Same as getMLE.


getInstanceFromMLE

public 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.

Parameters:
x - the list of observations to use to evaluate parameters
m - the number of observations to use to evaluate parameters

getMean

public static double getMean(int n)
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

getMomentsEstimate

public 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.

Parameters:
x - the list of observations to use to evaluate parameters
m - the number of observations to use to evaluate parameters
Returns:
returns the parameter [hat(n)]

getVariance

public static double getVariance(int n)
Computes and returns the variance Var[X] = 2n of the chi-square distribution with parameter n.

Returns:
the variance of the chi-square distribution VarX] = 2n

getStandardDeviation

public static double getStandardDeviation(int n)
Computes and returns the standard deviation of the chi-square distribution with parameter n.

Returns:
the standard deviation of the chi-square distribution

getN

public int getN()
Returns the parameter n of this object.


setN

public void setN(int n)
Sets the parameter n of this object.


getParams

public double[] getParams()
Return a table containing the parameters of the current distribution.


toString

public String toString()
Overrides:
toString in class Object

SSJ
V. 2.0.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.