Java Statistical Classes

jsc.goodnessfit
Class KolmogorovCB

java.lang.Object
  |
  +--jsc.goodnessfit.KolmogorovCB
All Implemented Interfaces:
ConfidenceBand

public class KolmogorovCB
extends Object
implements ConfidenceBand

Kolmogorov-Smirnov confidence band for the distribution function of a continuous variable. Calculates the sample distribution function and a confidence band for the population distribution function using a critical value of the Kolmogorov-Smirnov goodness-of-fit D-statistic.

For sample sizes up to 100, the exact critical value can be calculated using an algorithm from Miller(1956). For larger samples, an approximation from Stephens(1970) can be used. If used to test a discrete distribution, the true confidence band may be wider than the calculated band.

References:
Miller,L.H.(1956). Table of percentage points of Kolmogorov statistics, J. Amer. Statist. Assoc., Vol.51, 111-121.
Neave,H.R.(1981). Elementary Statistics Tables. Allen and Unwin.
Stephens,M.A.(1970). Use of the Kolmogorov-Smirnov, Cramer-Von Mises and related statistics without extensive tables, J. R. Statist. Soc. B, Vol.32, 115-122.

Version:
1.0
Author:
A. J. Bertie.

Constructor Summary
KolmogorovCB(double[] x)
          Create confidence band from a sample of data.
KolmogorovCB(double[] x, double confidenceCoeff, boolean approx)
          Create confidence band from a sample of data.
KolmogorovCB(SampleDistributionFunction sdf, double confidenceCoeff, boolean approx)
          Create confidence band from a sample distribution function.
 
Method Summary
static double approxCriticalValue(int n, double alpha)
          Calculate an approximate critical value of the Kolmogorov-Smirnov statistic for completely specified continuous distributions.
static double exactCriticalValue(int n, double alpha)
          Calculate the exact critical value of the Kolmogorov-Smirnov statistic for completely specified continuous distributions.
 double getConfidenceCoeff()
          Returns the confidence coefficient.
 double getCriticalValue()
          Return the critical value of the Kolmogorov-Smirnov D-statistic used to calculate the confidence band.
 double getLowerLimit(int i)
          Returns the value of the lower confidence limit function at the ith x-value.
 int getN()
          Returns n, the number of indexed values that define the band.
 SampleDistributionFunction getSdf()
          Returns the sample distribution function S(x) calculated for the confidence band.
 double getUpperLimit(int i)
          Returns the value of the upper confidence limit function at the ith x-value.
 double getX(int i)
          Returns the ith x-value.
 void setConfidenceCoeff(double coeff)
          Specifies the confidence coefficient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KolmogorovCB

public KolmogorovCB(SampleDistributionFunction sdf,
                    double confidenceCoeff,
                    boolean approx)
Create confidence band from a sample distribution function.

Parameters:
sdf - the sample distribution function.
confidenceCoeff - the confidence coefficient; must be between 0 and 1.
approx - if true, Stephen's approximation is used to calculate the critical value.
Throws:
IllegalArgumentException - if confidenceCoeff less than 0 or greater than 1.

KolmogorovCB

public KolmogorovCB(double[] x,
                    double confidenceCoeff,
                    boolean approx)
Create confidence band from a sample of data.

Parameters:
x - the observations.
confidenceCoeff - the confidence coefficient; must be between 0 and 1.
approx - if true, Stephen's approximation is used to calculate the critical value.
Throws:
IllegalArgumentException - if confidenceCoeff less than 0 or greater than 1.
IllegalArgumentException - if less than 2 observations.

KolmogorovCB

public KolmogorovCB(double[] x)
Create confidence band from a sample of data. Stephen's approximation is used to calculate the SP and confidence band if n > 100. The confidence coefficient is set to 0.95.

Parameters:
x - the observations.
Throws:
IllegalArgumentException - if confidenceCoeff less than 0 or greater than 1.
IllegalArgumentException - if less than 2 observations.
Method Detail

approxCriticalValue

public static double approxCriticalValue(int n,
                                         double alpha)
Calculate an approximate critical value of the Kolmogorov-Smirnov statistic for completely specified continuous distributions. Given a significance level alpha, returns the value c such that approximately Prob(D >= c) = alpha. The method uses equation (11) of Miller(1956). The approximation is recommended for n > 20.

Parameters:
n - the sample size; must be > 0.
alpha - the significance level; must be greater than or equal to 0 and less than or equal to 1.
Returns:
the approximate critical value.
Throws:
IllegalArgumentException - if n < 1.
IllegalArgumentException - if alpha < 0 or > 1.

exactCriticalValue

public static double exactCriticalValue(int n,
                                        double alpha)
Calculate the exact critical value of the Kolmogorov-Smirnov statistic for completely specified continuous distributions. Given a significance level alpha, returns the value c such that Prob(D >= c) = alpha. The method uses equations (2) and (7) of Miller(1956).

N.B. This method is unreliable when alpha < 1.0e-9 or alpha > 1 - 1.0e-9.

Parameters:
n - the sample size; must be > 0.
alpha - the significance level; must be greater than or equal to 0 and less than or equal to 1.
Returns:
the critical value.
Throws:
IllegalArgumentException - if n < 1.
IllegalArgumentException - if alpha < 0 or > 1.

getConfidenceCoeff

public double getConfidenceCoeff()
Description copied from interface: ConfidenceBand
Returns the confidence coefficient.

Specified by:
getConfidenceCoeff in interface ConfidenceBand
Returns:
the confidence coefficient.

setConfidenceCoeff

public void setConfidenceCoeff(double coeff)
Specifies the confidence coefficient.

N.B. The coefficient should be less than 1 - 1.0e-9 for small samples.

Specified by:
setConfidenceCoeff in interface ConfidenceBand
Parameters:
coeff - the confidence coefficient; must be between 0 and 1.
Throws:
IllegalArgumentException - if confidenceCoeff not > 0 and < 1.

getCriticalValue

public double getCriticalValue()
Return the critical value of the Kolmogorov-Smirnov D-statistic used to calculate the confidence band.

Returns:
the critical value.

getLowerLimit

public double getLowerLimit(int i)
Description copied from interface: ConfidenceBand
Returns the value of the lower confidence limit function at the ith x-value.

Specified by:
getLowerLimit in interface ConfidenceBand
Parameters:
i - the index of x; from 0 to n-1.
Returns:
the lower confidence limit.

getUpperLimit

public double getUpperLimit(int i)
Description copied from interface: ConfidenceBand
Returns the value of the upper confidence limit function at the ith x-value.

Specified by:
getUpperLimit in interface ConfidenceBand
Parameters:
i - the index of x; from 0 to n-1.
Returns:
the upper confidence limit.

getN

public int getN()
Description copied from interface: ConfidenceBand
Returns n, the number of indexed values that define the band.

Specified by:
getN in interface ConfidenceBand
Returns:
n.

getSdf

public SampleDistributionFunction getSdf()
Returns the sample distribution function S(x) calculated for the confidence band.

Returns:
the sample distribution function.

getX

public double getX(int i)
Description copied from interface: ConfidenceBand
Returns the ith x-value.

Specified by:
getX in interface ConfidenceBand
Parameters:
i - the index of x; from 0 to n-1.
Returns:
the ith x-value.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005