Package com.irurueta.statistics
Class ChiSqDist
java.lang.Object
com.irurueta.statistics.ChiSqDist
Contains methods to work with Chi squared distributions.
Methods of this class use methods of the Gamma class.
This class is based in code of Numerical Recipes 3rd ed. section 6.14.8.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
cdf
(double x2) Evaluates the cumulative distribution function (c.d.f.) of this Chi-square distribution.static double
cdf
(double x2, double nu) Evaluates the cumulative distribution function (c.d.f.) of a Chi-squared distribution having parameter nu.private static double
fac
(double nu) Computes constant factor to multiply p.d.f.double
getNu()
Returns nu parameter of chi square distribution.private static double
internalCdf
(double x2, double nu, Gamma gamma) Evaluates the cumulative distribution function (c.d.f.) of a Chi-squared distribution having parameter nu.private static double
internalInvcdf
(double p, double nu, Gamma gamma) Evaluates the inverse cumulative distribution function of a Chi squared distribution having parameter nu.private static double
internalP
(double x2, double nu, double fac) Evaluates the probability density function (p.d.f.) of a Chi square distribution.double
invcdf
(double p) Evaluates the inverse cumulative distribution function of this Chi squared distribution.static double
invcdf
(double p, double nu) Evaluates the inverse cumulative distribution function of a Chi squared distribution having parameter nu.double
p
(double x2) Evaluates the probability density function (p.d.f.) of this Chi square distribution.static double
p
(double x2, double nu) Evaluates the probability density function (p.d.f.) of a Chi square distribution.final void
setNu
(double nu) Sets nu parameter of chi square distribution.
-
Field Details
-
nu
private double nuNu parameter of chi square distribution. Typically, this parameter is provided as an integer value indicating the number of degrees of freedom. -
fac
private double facConstant factor to multiply p.d.f of chi squared by. This factor depends on nu parameter. -
gamma
A gamma function instance to be reused for memory efficiency.
-
-
Constructor Details
-
ChiSqDist
public ChiSqDist(double nu) Constructor.- Parameters:
nu
- parameter of chi square distribution.- Throws:
IllegalArgumentException
- if provided nu parameter is negative or zero.
-
-
Method Details
-
getNu
public double getNu()Returns nu parameter of chi square distribution. Typically, this parameter is an integer value indicating the number of degrees of freedom.- Returns:
- nu parameter of chi square distribution.
-
setNu
public final void setNu(double nu) Sets nu parameter of chi square distribution. Typically, this parameter is an integer value indicating the number of degrees of freedom.- Parameters:
nu
- nu parameter of chi square distribution.- Throws:
IllegalArgumentException
- if provided nu parameter is negative or zero.
-
p
public static double p(double x2, double nu) Evaluates the probability density function (p.d.f.) of a Chi square distribution.- Parameters:
x2
- chi square value where p.d.f. is evaluated. Must be greater than 0.0.nu
- nu parameter of chi square distribution. Typically, this is an integer value indicating the number of degrees of freedom. Must be greater than 0.0.- Returns:
- evaluation of p.d.f.
- Throws:
IllegalArgumentException
- if either x2 or nu are negative or zero.
-
p
public double p(double x2) Evaluates the probability density function (p.d.f.) of this Chi square distribution.- Parameters:
x2
- chi square value where p.d.f. is evaluated. Must be greater than 0.0.- Returns:
- evaluation of p.d.f.
- Throws:
IllegalArgumentException
- if x2 is negative or zero.
-
cdf
Evaluates the cumulative distribution function (c.d.f.) of a Chi-squared distribution having parameter nu.- Parameters:
x2
- chi square value where c.d.f. is evaluated. Must be positive or zero.nu
- nu parameter of chi square distribution. Typically, this is an integer value indicating the number of degrees of freedom. Must be greater than 0.0.- Returns:
- evaluation of c.d.f.
- Throws:
IllegalArgumentException
- if provided chi square value is negative or if provided nu parameter is negative or zero.MaxIterationsExceededException
- if convergence of incomplete gamma function cannot be reached. This is rarely thrown and happens usually for numerically unstable input values.
-
cdf
Evaluates the cumulative distribution function (c.d.f.) of this Chi-square distribution.- Parameters:
x2
- chi square value where c.d.f. is evaluated. Must be positive or zero.- Returns:
- evaluation of c.d.f.
- Throws:
IllegalArgumentException
- if provided chi square value is negative.MaxIterationsExceededException
- if convergence of incomplete gamma function cannot be reached. This is rarely thrown and happens usually for numerically unstable input values.
-
invcdf
Evaluates the inverse cumulative distribution function of a Chi squared distribution having parameter nu. Because the c.d.f is a monotonically increasing function with values between 0.0 and 1.0, its inverse is uniquely defined between such range of values.- Parameters:
p
- value to evaluate the inverse c.d.f. at. This value is equivalent to a probability and must be between 0.0 and 1.0.nu
- nu parameter of chi square distribution. Typically, this is an integer value indicating the number of degrees of freedom. Must be greater than 0.0.- Returns:
- the value x2 for which the c.d.f. has value p.
- Throws:
IllegalArgumentException
- if provided probability value is not between 0.0 and 1.0 of if provided nu parameter is negative or zero.MaxIterationsExceededException
- if convergence of inverse incomplete gamma function cannot be reached. This is rarely thrown and happens usually for numerically unstable values.
-
invcdf
Evaluates the inverse cumulative distribution function of this Chi squared distribution. Because the c.d.f is a monotonically increasing function with values between 0.0 and 1.0, its inverse is uniquely defined between such range of values.- Parameters:
p
- value to evaluate the inverse c.d.f. at. This value is equivalent to a probability and must be between 0.0 and 1.0.- Returns:
- the value x2 for which the c.d.f. has value p.
- Throws:
IllegalArgumentException
- if provided probability value is not between 0.0 and 1.0.MaxIterationsExceededException
- if convergence of inverse incomplete gamma function cannot be reached. This is rarely thrown and happens usually for numerically unstable values.
-
internalP
private static double internalP(double x2, double nu, double fac) Evaluates the probability density function (p.d.f.) of a Chi square distribution. This method is used internally.- Parameters:
x2
- chi square value where p.d.f. is evaluated. Must be greater than 0.0.nu
- nu parameter of chi square distribution. Typically, this is an integer value indicating the number of degrees of freedom. Must be greater than 0.0.fac
- actor to multiply p.d.f of chi squared by.- Returns:
- evaluation of p.d.f.
- Throws:
IllegalArgumentException
- if x2 is negative or zero.
-
internalCdf
private static double internalCdf(double x2, double nu, Gamma gamma) throws MaxIterationsExceededException Evaluates the cumulative distribution function (c.d.f.) of a Chi-squared distribution having parameter nu. This method is used internally.- Parameters:
x2
- chi square value where c.d.f. is evaluated. Must be positive or zero.nu
- nu parameter of chi square distribution. Typically, this is an integer value indicating the number of degrees of freedom. Must be greater than 0.0.gamma
- a gamma instance to evaluate the incomplete gamma function.- Returns:
- evaluation of c.d.f.
- Throws:
IllegalArgumentException
- if provided chi square value is negative.MaxIterationsExceededException
- if convergence of incomplete gamma function cannot be reached. This is rarely thrown and happens usually for numerically unstable values.
-
internalInvcdf
private static double internalInvcdf(double p, double nu, Gamma gamma) throws MaxIterationsExceededException Evaluates the inverse cumulative distribution function of a Chi squared distribution having parameter nu. Because the c.d.f is a monotonically increasing function with values between 0.0 and 1.0, its inverse is uniquely defined between such range of values. This method is used internally.- Parameters:
p
- value to evaluate the inverse c.d.f. at. This value is equivalent to a probability and must be between 0.0 and 1.0.nu
- nu parameter of chi square distribution. Typically, this is an integer value indicating the number of degrees of freedom. Must be greater than 0.0.gamma
- a gamma instance to evaluate the inverse incomplete gamma function.- Returns:
- the value x2 for which the c.d.f. has value p.
- Throws:
IllegalArgumentException
- if provided probability value is not between 0.0 and 1.0.MaxIterationsExceededException
- if convergence of inverse incomplete gamma function cannot be reached. This is rarely thrown and happens usually for numerically unstable values.
-
fac
private static double fac(double nu) Computes constant factor to multiply p.d.f. of chi squared by.- Parameters:
nu
- nu parameter of chi square distribution. Typically, this parameter is provided as an integer value indicating the number of degrees of freedom.- Returns:
- constant factor to multiply p.d.f. of chi squared.
-