Lably
Skip to content

Kolmogorov–Smirnov test

Statistical test comparing two probability distributions

  • 10 min read
  • 6 chapters

Related on Lably

Through Statistics, Probability distribution and Sampling (statistics)

The Kolmogorov–Smirnov statistic quantifies a distance between the empirical distribution function of the sample and the cumulative distribution function of the reference distribution, or between the empirical distribution functions of two samples. The null distribution of this statistic is calculated under the null hypothesis that the sample is drawn from the reference distribution (in the one-sample case) or that the samples are drawn from the same distribution (in the two-sample case). In the one-sample case, the distribution considered under the null hypothesis may be continuous (see Section 2), purely discrete or mixed (see Section 2.2). In the two-sample case (see Section 3), the common distribution considered under the null hypothesis is otherwise unrestricted; it is classically assumed continuous, but the test can also be applied when this distribution is purely discrete or mixed, in which case tied observations may be present.

The two-sample K–S test is one of the most useful and general nonparametric methods for comparing two samples, as it is sensitive to differences in both location and shape of the empirical cumulative distribution functions of the two samples.

The Kolmogorov–Smirnov test can be modified to serve as a goodness of fit test. In the special case of testing for normality of the distribution, samples are standardized and compared with a standard normal distribution. This is equivalent to setting the mean and variance of the reference distribution equal to the sample estimates, and it is known that using these to define the specific reference distribution changes the null distribution of the test statistic (see Test with estimated parameters). Various studies have found that, even in this corrected form, the test is less powerful for testing normality than the Shapiro–Wilk test or Anderson–Darling test.

One-sample Kolmogorov–Smirnov statistic

The empirical distribution function Fn for n independent and identically distributed (i.i.d.) ordered observations Xi is defined as

Fn(x)=number of (elements in the sample≤x)n=1n∑i=1n1(−∞,x](Xi), where 1(−∞,x](Xi) is the indicator function, equal to 1 if Xi≤x and equal to 0 otherwise.

The Kolmogorov–Smirnov statistic for a given cumulative distribution function F(x) is

Dn=supx|Fn(x)−F(x)|

where supx is the supremum of the set of distances. Intuitively, the statistic takes the largest absolute difference between the two distribution functions across all x values.

By the Glivenko–Cantelli theorem, if the sample comes from the distribution F(x), then Dn converges to 0 almost surely in the limit when n goes to infinity. Kolmogorov strengthened this result, by effectively providing the rate of this convergence (see Kolmogorov distribution). Donsker's theorem provides a yet stronger result.

In practice, the statistic requires a relatively large number of data points (in comparison to other goodness of fit criteria such as the Anderson–Darling test statistic) to properly reject the null hypothesis.

Sign in to keep reading

5 more chapters are free with a Lably account.

More in Statistics