Probability & Statistics

Kolmogorov-Smirnov Statistic

Measure the largest vertical gap between a four-point empirical CDF and the uniform reference CDF.

By Riano · Published · Updated · Report a correction

Kolmogorov-Smirnov Statistic

Concept Overview

The Kolmogorov-Smirnov (KS) statistic measures the maximum distance between two cumulative distribution functions (CDFs). In this module, we compare a four-point empirical right-continuous CDF with the reference uniform CDF F(x) = x. We compute the one-sided statistics D+ and D- by checking both sides of every jump, including tied observations.

Worked Example

Let's calculate the KS statistic for the "Spread" sample preset: [0.1, 0.3, 0.6, 0.9]. The sample size is n = 4.

We compute the supremum of the differences between the empirical CDF Fn(x) and F(x) = x.

  1. i = 1 (x = 0.1):
    D+ candidate: 1/4 - 0.1 = 0.25 - 0.1 = 0.15
    D- candidate: 0.1 - 0/4 = 0.1
  2. i = 2 (x = 0.3):
    D+ candidate: 2/4 - 0.3 = 0.5 - 0.3 = 0.2
    D- candidate: 0.3 - 1/4 = 0.3 - 0.25 = 0.05
  3. i = 3 (x = 0.6):
    D+ candidate: 3/4 - 0.6 = 0.75 - 0.6 = 0.15
    D- candidate: 0.6 - 2/4 = 0.6 - 0.5 = 0.1
  4. i = 4 (x = 0.9):
    D+ candidate: 4/4 - 0.9 = 1 - 0.9 = 0.1
    D- candidate: 0.9 - 3/4 = 0.9 - 0.75 = 0.15

Taking the maximums:
D+ = max(0.15, 0.2, 0.15, 0.1) = 0.2 (1/5)
D- = max(0.1, 0.05, 0.1, 0.15) = 0.15 (3/20)
The total KS statistic is D = max(D+, D-) = 0.2 (1/5).

Experiment

Use the Kolmogorov-Smirnov Statistic interactive module to visualize these calculations.

  1. Select the Central gap preset.
  2. Observe the plotted empirical CDF as a blue step function and the reference uniform CDF as a diagonal grey line.
  3. The module calculates the largest vertical distance between these two lines. A dashed red line indicates where this maximum gap occurs.
  4. Select All zero to see what happens in an extreme boundary case when all observations are clumped together at the lower bound. D+ and D will become 1.

Limitations

This is a descriptive discrepancy module: it calculates the actual distance but does not report a p-value or a rejection rule. Furthermore, ordinary distribution-free KS calibration assumes a continuous specified null distribution and stochastic observations. Our visualizer calculates the exact statistic for a fixed sequence of four sample points.

References

The following reference describes the properties and implementation of the Kolmogorov-Smirnov test statistic, which forms the basis for this module.

  • SciPy: kstest
    Describes the SciPy implementation of the Kolmogorov-Smirnov test, the D+ and D- statistics, and its continuous-null limitation.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Kolmogorov-Smirnov Statistic module.

Try Kolmogorov-Smirnov Statistic on Riano →

More in Probability & Statistics