org.apache.commons.math.distribution
Class KolmogorovSmirnovDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.KolmogorovSmirnovDistributionImpl
All Implemented Interfaces:
java.io.Serializable, KolmogorovSmirnovDistribution

public class KolmogorovSmirnovDistributionImpl
extends java.lang.Object
implements KolmogorovSmirnovDistribution, java.io.Serializable

The default implementation of KolmogorovSmirnovDistribution.

Treats the distribution of the two-sided P(Dn< d) where Dn= sup_x | G(x) - Gn (x) | for the theoretical cdf G and the emperical cdf Gn.

This implementation is based on [1] with certain quick decisions for extreme values given in [2].

In short, when wanting to evaluate P(Dn< d), the method in [1] is to write d = (k - h) / n for positive integer k and 0 <= h < 1. Then P(Dn< d) = (n!/nn) * t_kk where t_kk is the (k, k)'th entry in the special matrix Hn, i.e. H to the n'th power.

See also Kolmogorov-Smirnov test on Wikipedia for details.

References:

Note that [1] contains an error in computing h, refer to MATH-437 for details.

Version:
$Id: KolmogorovSmirnovDistributionImpl.java 1178235 2011-10-02 19:43:17Z luc $
See Also:
Serialized Form

Constructor Summary
KolmogorovSmirnovDistributionImpl(int n)
           
 
Method Summary
 double cdf(double d)
          Calculates P(Dn < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).
 double cdf(double d, boolean exact)
          Calculates P(Dn < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).
 double cdfExact(double d)
          Calculates P(Dn < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KolmogorovSmirnovDistributionImpl

public KolmogorovSmirnovDistributionImpl(int n)
Parameters:
n - Number of observations
Throws:
NotStrictlyPositiveException - if n <= 0
Method Detail

cdf

public double cdf(double d)
           throws MathArithmeticException
Calculates P(Dn < d) using method described in [1] with quick decisions for extreme values given in [2] (see above). The result is not exact as with cdfExact(double) because calculations are based on double rather than BigFraction.

Specified by:
cdf in interface KolmogorovSmirnovDistribution
Parameters:
d - statistic
Returns:
the two-sided probability of P(Dn < d)
Throws:
MathArithmeticException - if algorithm fails to convert h to a BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.

cdfExact

public double cdfExact(double d)
                throws MathArithmeticException
Calculates P(Dn < d) using method described in [1] with quick decisions for extreme values given in [2] (see above). The result is exact in the sense that BigFraction/BigReal is used everywhere at the expense of very slow execution time. Almost never choose this in real applications unless you are very sure; this is almost solely for verification purposes. Normally, you would choose cdf(double)

Parameters:
d - statistic
Returns:
the two-sided probability of P(Dn < d)
Throws:
MathArithmeticException - if algorithm fails to convert h to a BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.

cdf

public double cdf(double d,
                  boolean exact)
           throws MathArithmeticException
Calculates P(Dn < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).

Parameters:
d - statistic
exact - whether the probability should be calculated exact using BigFraction everywhere at the expense of very slow execution time, or if double should be used convenient places to gain speed. Almost never choose true in real applications unless you are very sure; true is almost solely for verification purposes.
Returns:
the two-sided probability of P(Dn < d)
Throws:
MathArithmeticException - if algorithm fails to convert h to a BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.


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