org.apache.commons.math.distribution
Class ChiSquaredDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractContinuousDistribution
          extended by org.apache.commons.math.distribution.ChiSquaredDistributionImpl
All Implemented Interfaces:
java.io.Serializable, ChiSquaredDistribution, ContinuousDistribution, Distribution

public class ChiSquaredDistributionImpl
extends AbstractContinuousDistribution
implements ChiSquaredDistribution, java.io.Serializable

The default implementation of ChiSquaredDistribution

Version:
$Id: ChiSquaredDistributionImpl.java 1178295 2011-10-03 04:36:27Z psteitz $
See Also:
Serialized Form

Field Summary
static double DEFAULT_INVERSE_ABSOLUTE_ACCURACY
          Default inverse cumulative probability accuracy
 
Fields inherited from class org.apache.commons.math.distribution.AbstractContinuousDistribution
randomData, SOLVER_DEFAULT_ABSOLUTE_ACCURACY
 
Constructor Summary
ChiSquaredDistributionImpl(double degreesOfFreedom)
          Create a Chi-Squared distribution with the given degrees of freedom.
ChiSquaredDistributionImpl(double degreesOfFreedom, double inverseCumAccuracy)
          Create a Chi-Squared distribution with the given degrees of freedom and inverse cumulative probability accuracy.
 
Method Summary
protected  double calculateNumericalMean()
          Use this method to actually calculate the mean for the specific distribution.
protected  double calculateNumericalVariance()
          Use this method to actually calculate the variance for the specific distribution.
 double cumulativeProbability(double x)
          For this distribution, X, this method returns P(X < x).
 double density(double x)
          Probability density for a particular point.
 double getDegreesOfFreedom()
          Access the number of degrees of freedom.
protected  double getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a CDF root.
protected  double getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a CDF root.
protected  double getInitialDomain(double p)
          Access the initial domain value, based on p, used to bracket a CDF root.
protected  double getSolverAbsoluteAccuracy()
          Return the absolute accuracy setting of the solver used to estimate inverse cumulative probabilities.
 double getSupportLowerBound()
          Access the lower bound of the support.
 double getSupportUpperBound()
          Access the upper bound of the support.
 double inverseCumulativeProbability(double p)
          For this distribution, X, this method returns the critical point x, such that P(X < x) = p.
 boolean isSupportLowerBoundInclusive()
          Use this method to get information about whether the lower bound of the support is inclusive or not.
 boolean isSupportUpperBoundInclusive()
          Use this method to get information about whether the upper bound of the support is inclusive or not.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractContinuousDistribution
reseedRandomGenerator, sample, sample
 
Methods inherited from class org.apache.commons.math.distribution.AbstractDistribution
cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.math.distribution.ContinuousDistribution
reseedRandomGenerator, sample, sample
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected
 

Field Detail

DEFAULT_INVERSE_ABSOLUTE_ACCURACY

public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY
Default inverse cumulative probability accuracy

Since:
2.1
See Also:
Constant Field Values
Constructor Detail

ChiSquaredDistributionImpl

public ChiSquaredDistributionImpl(double degreesOfFreedom)
Create a Chi-Squared distribution with the given degrees of freedom.

Parameters:
degreesOfFreedom - Degrees of freedom.

ChiSquaredDistributionImpl

public ChiSquaredDistributionImpl(double degreesOfFreedom,
                                  double inverseCumAccuracy)
Create a Chi-Squared distribution with the given degrees of freedom and inverse cumulative probability accuracy.

Parameters:
degreesOfFreedom - Degrees of freedom.
inverseCumAccuracy - the maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).
Since:
2.1
Method Detail

getDegreesOfFreedom

public double getDegreesOfFreedom()
Access the number of degrees of freedom.

Specified by:
getDegreesOfFreedom in interface ChiSquaredDistribution
Returns:
the degrees of freedom.

density

public double density(double x)
Probability density for a particular point.

Specified by:
density in interface ContinuousDistribution
Specified by:
density in class AbstractContinuousDistribution
Parameters:
x - Point at which the density should be computed.
Returns:
the pdf at point x.

cumulativeProbability

public double cumulativeProbability(double x)
For this distribution, X, this method returns P(X < x).

Specified by:
cumulativeProbability in interface Distribution
Parameters:
x - the value at which the CDF is evaluated.
Returns:
CDF for this distribution.

inverseCumulativeProbability

public double inverseCumulativeProbability(double p)
For this distribution, X, this method returns the critical point x, such that P(X < x) = p. It will return 0 when p = 0 and Double.POSITIVE_INFINITY when p = 1.

Specified by:
inverseCumulativeProbability in interface ContinuousDistribution
Overrides:
inverseCumulativeProbability in class AbstractContinuousDistribution
Parameters:
p - Desired probability.
Returns:
x, such that P(X < x) = p.
Throws:
OutOfRangeException - if p is not a valid probability.

getDomainLowerBound

protected double getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a CDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

Specified by:
getDomainLowerBound in class AbstractContinuousDistribution
Parameters:
p - the desired probability for the critical value
Returns:
domain value lower bound, i.e. P(X < 'lower bound') < p.

getDomainUpperBound

protected double getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a CDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

Specified by:
getDomainUpperBound in class AbstractContinuousDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
domain value upper bound, i.e. P(X < 'upper bound') > p.

getInitialDomain

protected double getInitialDomain(double p)
Access the initial domain value, based on p, used to bracket a CDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

Specified by:
getInitialDomain in class AbstractContinuousDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the initial domain value.

getSolverAbsoluteAccuracy

protected double getSolverAbsoluteAccuracy()
Return the absolute accuracy setting of the solver used to estimate inverse cumulative probabilities.

Overrides:
getSolverAbsoluteAccuracy in class AbstractContinuousDistribution
Returns:
the solver absolute accuracy.
Since:
2.1

getSupportLowerBound

public double getSupportLowerBound()
Access the lower bound of the support. The lower bound of the support is always 0 no matter the degrees of freedom.

Specified by:
getSupportLowerBound in class AbstractContinuousDistribution
Returns:
lower bound of the support (always 0)

getSupportUpperBound

public double getSupportUpperBound()
Access the upper bound of the support. The upper bound of the support is always positive infinity no matter the degrees of freedom.

Specified by:
getSupportUpperBound in class AbstractContinuousDistribution
Returns:
upper bound of the support (always Double.POSITIVE_INFINITY)

calculateNumericalMean

protected double calculateNumericalMean()
Use this method to actually calculate the mean for the specific distribution. Use AbstractDistribution.getNumericalMean() (which implements caching) to actually get the mean. For k degrees of freedom, the mean is k

Specified by:
calculateNumericalMean in class AbstractDistribution
Returns:
the mean or Double.NaN if it's not defined

calculateNumericalVariance

protected double calculateNumericalVariance()
Use this method to actually calculate the variance for the specific distribution. Use AbstractDistribution.getNumericalVariance() (which implements caching) to actually get the variance. For k degrees of freedom, the variance is 2 * k

Specified by:
calculateNumericalVariance in class AbstractDistribution
Returns:
the variance or Double.NaN if it's not defined

isSupportLowerBoundInclusive

public boolean isSupportLowerBoundInclusive()
Use this method to get information about whether the lower bound of the support is inclusive or not.

Specified by:
isSupportLowerBoundInclusive in interface Distribution
Specified by:
isSupportLowerBoundInclusive in class AbstractDistribution
Returns:
whether the lower bound of the support is inclusive or not

isSupportUpperBoundInclusive

public boolean isSupportUpperBoundInclusive()
Use this method to get information about whether the upper bound of the support is inclusive or not.

Specified by:
isSupportUpperBoundInclusive in interface Distribution
Specified by:
isSupportUpperBoundInclusive in class AbstractDistribution
Returns:
whether the upper bound of the support is inclusive or not


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.