Class KolmogorovSmirnovTest

  • All Implemented Interfaces:
    GoodnessOfFitTest

    public class KolmogorovSmirnovTest
    extends java.lang.Object
    implements GoodnessOfFitTest
    Kolmogorov-Smirnov test.

    Class that tests two given real-valued data samples on whether they might have originated from the same underlying distribution using the Kolmogorov-Smirnov test statistic that compares the two empirical cumulative distribution functions. The KS statistic is defined as the maximum absolute difference of the empirical CDFs.

    Since:
    0.5.0
    Author:
    Erich Schubert
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  KolmogorovSmirnovTest.Par
      Parameterizer, to use the static instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static double calculateTestStatistic​(double[] sample1, double[] sample2)
      Calculates the maximum distance between the two empirical CDFs of two data samples.
      double deviation​(double[] fullSample, double[] conditionalSample)
      Measure the deviation of a full sample from a conditional sample.
      static double simpleTest​(double[] test)
      Simplest version of the test: test if a sorted array is approximately uniform distributed on [0:1].
      static double simpleTest​(double[] test, double min, double max)
      Simplest version of the test: test if a sorted array is approximately uniform distributed on the given interval.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KolmogorovSmirnovTest

        public KolmogorovSmirnovTest()
        Constructor.
    • Method Detail

      • deviation

        public double deviation​(double[] fullSample,
                                double[] conditionalSample)
        Description copied from interface: GoodnessOfFitTest
        Measure the deviation of a full sample from a conditional sample.

        Sample arrays may be modified, e.g., sorted, by the test.

        Specified by:
        deviation in interface GoodnessOfFitTest
        Parameters:
        fullSample - Full sample
        conditionalSample - Conditional sample
        Returns:
        Deviation
      • calculateTestStatistic

        public static double calculateTestStatistic​(double[] sample1,
                                                    double[] sample2)
        Calculates the maximum distance between the two empirical CDFs of two data samples. The sample positions and CDFs must be synchronized!
        Parameters:
        sample1 - first data sample positions
        sample2 - second data sample positions
        Returns:
        the largest difference between both functions
      • simpleTest

        public static double simpleTest​(double[] test)
        Simplest version of the test: test if a sorted array is approximately uniform distributed on [0:1].
        Parameters:
        test - Presorted (!) array
        Returns:
        Maximum deviation from uniform.
      • simpleTest

        public static double simpleTest​(double[] test,
                                        double min,
                                        double max)
        Simplest version of the test: test if a sorted array is approximately uniform distributed on the given interval.
        Parameters:
        test - Presorted (!) array
        min - Minimum of uniform distribution
        max - Maximum of uniform distribution
        Returns:
        Maximum deviation from uniform.