Kolmogorov–Smirnov test

From Infogalactic: the planetary knowledge core
(Redirected from Kolmogorov distribution)
Jump to: navigation, search
Illustration of the Kolmogorov–Smirnov statistic. Red line is CDF, blue line is an ECDF, and the black arrow is the K–S statistic.

In statistics, the KolmogorovSmirnov test (K–S test or KS test) is a nonparametric test of the equality of continuous, one-dimensional probability distributions that can be used to compare a sample with a reference probability distribution (one-sample K–S test), or to compare two samples (two-sample K–S test). 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 samples are drawn from the same distribution (in the two-sample case) or that the sample is drawn from the reference distribution (in the one-sample case). In each case, the distributions considered under the null hypothesis are continuous distributions but are otherwise unrestricted.

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 below. 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.[1] However, other tests have their own disadvantages. For instance the Shapiro–Wilk test is known not to work well with many ties (many identical values).

Kolmogorov–Smirnov statistic

The empirical distribution function Fn for n iid observations Xi is defined as

F_n(x)={1 \over n}\sum_{i=1}^n I_{[-\infty,x]}(X_i)

where I_{[-\infty,x]}(X_i) is the indicator function, equal to 1 if X_i \le x and equal to 0 otherwise.

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

D_n= \sup_x |F_n(x)-F(x)|

where sup x is the supremum of the set of distances. By the Glivenko–Cantelli theorem, if the sample comes from 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 below). Donsker's theorem provides yet a stronger result.

In practice, the statistic requires a relatively large number of data points to properly reject the null hypothesis.

Kolmogorov distribution

The Kolmogorov distribution is the distribution of the random variable

K=\sup_{t\in[0,1]}|B(t)|

where B(t) is the Brownian bridge. The cumulative distribution function of K is given by[2]

\operatorname{Pr}(K\leq x)=1-2\sum_{k=1}^\infty (-1)^{k-1} e^{-2k^2 x^2}=\frac{\sqrt{2\pi}}{x}\sum_{k=1}^\infty e^{-(2k-1)^2\pi^2/(8x^2)}.

Both the form of the Kolmogorov–Smirnov test statistic and its asymptotic distribution under the null hypothesis were published by Andrey Kolmogorov,[3] while a table of the distribution was published by Nikolai Vasilyevich Smirnov.[4] Recurrence relations for the distribution of the test statistic in finite samples are available.[3]

Under null hypothesis that the sample comes from the hypothesized distribution F(x),

\sqrt{n}D_n\xrightarrow{n\to\infty}\sup_t |B(F(t))|

in distribution, where B(t) is the Brownian bridge.

If F is continuous then under the null hypothesis \sqrt{n}D_n converges to the Kolmogorov distribution, which does not depend on F. This result may also be known as the Kolmogorov theorem; see Kolmogorov's theorem for disambiguation.

The goodness-of-fit test or the Kolmogorov–Smirnov test is constructed by using the critical values of the Kolmogorov distribution. The null hypothesis is rejected at level \alpha if

\sqrt{n}D_n>K_\alpha,\,

where Kα is found from

\operatorname{Pr}(K\leq K_\alpha)=1-\alpha.\,

The asymptotic power of this test is 1.

Test with estimated parameters

If either the form or the parameters of F(x) are determined from the data Xi the critical values determined in this way are invalid. In such cases, Monte Carlo or other methods may be required, but tables have been prepared for some cases. Details for the required modifications to the test statistic and for the critical values for the normal distribution and the exponential distribution have been published,[5] and later publications also include the Gumbel distribution.[6] The Lilliefors test represents a special case of this for the normal distribution. The logarithm transformation may help to overcome cases where the Kolmogorov test data does not seem to fit the assumption that it came from the normal distribution.

Discrete null distribution

The Kolmogorov–Smirnov test must be adapted for discrete variables.[7] The form of the test statistic remains the same as in the continuous case, but the calculation of its value is more subtle. We can see this if we consider computing the test statistic between a continuous distribution f(x) and a step function g(x) that has a discontinuity at x_i. In other words, the limit \lim_{x\rightarrow x_i} g(x), if it exists, is different from  g(x_i) . Thus, when computing the statistic

\sup_x |g(x)-f(x)| = \max_i \left[ \max\left( |g(x_i)-f(x_i)|,\lim_{x\rightarrow x_i} |g(x) - f(x_{i-1})| \right) \right],

it is unclear how to replace the limit, unless we know the limiting value of the underlying distribution.

In SAS, the Kolmogorov–Smirnov test is implemented in PROC NPAR1WAY.[8] The discretized KS test is implemented in the ks.test() function in the dgof package of the R project for statistical computing.[7] In Stata, the command ksmirnov performs a Kolmogorov–Smirnov test.[9]

Two-sample Kolmogorov–Smirnov test

Illustration of the two-sample Kolmogorov–Smirnov statistic. Red and blue lines each correspond to an empirical distribution function, and the black arrow is the two-sample KS statistic.

The Kolmogorov–Smirnov test may also be used to test whether two underlying one-dimensional probability distributions differ. In this case, the Kolmogorov–Smirnov statistic is

D_{n,n'}=\sup_x |F_{1,n}(x)-F_{2,n'}(x)|,

where F_{1,n} and F_{2,n'} are the empirical distribution functions of the first and the second sample respectively, and sup is the supremum function.

The null hypothesis is rejected at level \alpha if

D_{n,n'}>c(\alpha)\sqrt{\frac{n + n'}{n n'}}.[10] (dead link)

The value of c({\alpha}) is given in the table below for each level of \alpha[10]

\alpha 0.10 0.05 0.025 0.01 0.005 0.001
c({\alpha}) 1.22 1.36 1.48 1.63 1.73 1.95

Note that the two-sample test checks whether the two data samples come from the same distribution. This does not specify what that common distribution is (e.g. whether it's normal or not normal). Again, tables of critical values have been published.[5][10] These critical values have one thing in common with the Anderson–Darling and Chi-squares, namely the fact that higher values tend to be more rare.[11]

Setting confidence limits for the shape of a distribution function

While the Kolmogorov–Smirnov test is usually used to test whether a given F(x) is the underlying probability distribution of Fn(x), the procedure may be inverted to give confidence limits on F(x) itself. If one chooses a critical value of the test statistic Dα such that P(Dn > Dα) = α, then a band of width ±Dα around Fn(x) will entirely contain F(x) with probability 1 − α.

The Kolmogorov–Smirnov statistic in more than one dimension

A distribution-free multivariate Kolmogorov–Smirnov goodness of fit test has been proposed by Justel, Peña and Zamar (1997).[12] The test uses a statistic which is built using Rosenblatt's transformation, and an algorithm is developed to compute it in the bivariate case. An approximate test that can be easily computed in any dimension is also presented.

The Kolmogorov–Smirnov test statistic needs to be modified if a similar test is to be applied to multivariate data. This is not straightforward because the maximum difference between two joint cumulative distribution functions is not generally the same as the maximum difference of any of the complementary distribution functions. Thus the maximum difference will differ depending on which of \Pr(x < X \and y < Y) or \Pr(X < x \and Y > y) or any of the other two possible arrangements is used. One might require that the result of the test used should not depend on which choice is made.

One approach to generalizing the Kolmogorov–Smirnov statistic to higher dimensions which meets the above concern is to compare the cdfs of the two samples with all possible orderings, and take the largest of the set of resulting K–S statistics. In d dimensions, there are 2d−1 such orderings. One such variation is due to Peacock[13] and another to Fasano and Franceschini[14] (see Lopes et al. for a comparison and computational details).[15] Critical values for the test statistic can be obtained by simulations, but depend on the dependence structure in the joint distribution.

See also

Footnotes

  1. Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. 3.0 3.1 Lua error in package.lua at line 80: module 'strict' not found.
  4. Lua error in package.lua at line 80: module 'strict' not found.
  5. 5.0 5.1 Lua error in package.lua at line 80: module 'strict' not found.
  6. Lua error in package.lua at line 80: module 'strict' not found.
  7. 7.0 7.1 Lua error in package.lua at line 80: module 'strict' not found.
  8. http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_npar1way_toc.htm
  9. ksmirnov — Kolmogorov–Smirnov equality-of-distributions test
  10. 10.0 10.1 10.2 Table of critical values for the two-sample test
  11. Mehta, S. (2014) Statistics Topics ISBN 978-1499273533
  12. Lua error in package.lua at line 80: module 'strict' not found.
  13. Lua error in package.lua at line 80: module 'strict' not found.
  14. Lua error in package.lua at line 80: module 'strict' not found.
  15. Lua error in package.lua at line 80: module 'strict' not found.

References

  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.

External links