In statistics, the Kolmogorov–Smirnov test (K–S test or KS test) is a nonparametric test of the equality of continuous (or discontinuous, see Section 2.2), onedimensional probability distributions that can be used to compare a sample with a reference probability distribution (onesample K–S test), or to compare two samples (twosample K–S test). It is named after Andrey Kolmogorov and Nikolai Smirnov.
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 onesample case) or that the samples are drawn from the same distribution (in the twosample case). In the onesample case, the distribution considered under the null hypothesis may be continuous (see Section 2), purely discrete or mixed (see Section 2.2). In the twosample case (see Section 3), the distribution considered under the null hypothesis is a continuous distribution but is otherwise unrestricted.
The twosample 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, these other tests have their own disadvantages. For instance the Shapiro–Wilk test is known not to work well in samples with many identical values.
YouTube Encyclopedic

1/5Views:32 95080 80731 49522 8004 906

✪ Kolmogorov  Smirnov Test [KS Test]

✪ Conducting a KolmogorovSmirnov Normality Test (KS Test) in SPSS

✪ Simulation Modeling  Tutorial #2  KS Test (Solved Problem)

✪ KolmogorovSmirnov Test of Normality in Excel

✪ 12. Testing Goodness of Fit (cont.)
Transcription
Contents
Kolmogorov–Smirnov statistic
The empirical distribution function F_{n} for n iid ordered observations X_{i} is defined as
where is the indicator function, equal to 1 if and equal to 0 otherwise.
The Kolmogorov–Smirnov statistic for a given cumulative distribution function F(x) is
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 D_{n} converges to 0 almost surely in the limit when 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 (in comparison to other goodness of fit criteria such as the Anderson–Darling test statistic) to properly reject the null hypothesis.
Kolmogorov distribution
The Kolmogorov distribution is the distribution of the random variable
where B(t) is the Brownian bridge. The cumulative distribution function of K is given by^{[2]}
which can also be expressed by the Jacobi theta function . 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 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),
in distribution, where B(t) is the Brownian bridge.
If F is continuous then under the null hypothesis converges to the Kolmogorov distribution, which does not depend on F. This result may also be known as the Kolmogorov theorem. The accuracy of this limit as an approximation to the exact cdf of when is finite is not very impressive: even when , the corresponding maximum error is about ; this error increases to when and to a totally unacceptable when . However, a very simple expedient of replacing by
in the argument of the Jacobi theta function reduces these errors to , , and respectively; such accuracy would be usually considered more than adequate for all practical applications.^{[5]}
The goodnessoffit test or the Kolmogorov–Smirnov test can be constructed by using the critical values of the Kolmogorov distribution. This test is asymptotically valid when . It rejects the null hypothesis at level if
where K_{α} is found from
The asymptotic power of this test is 1.
Fast and accurate algorithms to compute the cdf or its complement for arbitrary and , are available from:
 ^{[6]} and ^{[7]} for continuous null distributions with code in C and Java to be found in ^{[6]}.
 ^{[8]} for purely discrete, mixed or continuous null distribution implemented in the KSgeneral package ^{[9]} of the R project for statistical computing, which for a given sample also computes the KS test statistic and its pvalue. Alternative C++ implementation is available from ^{[8]}.
Test with estimated parameters
If either the form or the parameters of F(x) are determined from the data X_{i} 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,^{[10]} and later publications also include the Gumbel distribution.^{[11]} 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.
Using estimated parameters, the questions arises which estimation method should be used. Usually this would be the maximum likelihood method, but e.g. for the normal distribution MLE has a large bias error on sigma! Using a moment fit or KS minimization instead has a large impact on the critical values, and also some impact on test power. If we need to decide for StudentT data with df = 2 via KS test whether the data could be normal or not, then a ML estimate based on H_{0} (data is normal, so using the standard deviation for scale) would give much larger KS distance, than a fit with minimum KS. In this case we should reject H_{0}, which is often the case with MLE, because the sample standard deviation might be very large for T2 data, but with KS minimization we may get still a too low KS to reject H_{0}. In the StudentT case, a modified KS test with KS estimate instead of MLE, makes the KS test indeed slightly worse. However, in other cases, such a modified KS test leads to slightly better test power.
Discrete and mixed null distribution
Under the assumption that is nondecreasing and rightcontinuous, with countable (possibly infinite) number of jumps, the KS test statistic can be expressed as:
From the rightcontinuity of , it follows that and and hence, the distribution of depends on the null distribution , i.e., is no longer distributionfree as in the continuous case. Therefore, a fast and accurate method has been developed to compute the exact and asymptotic distribution of when is purely discrete or mixed ^{[8]}, implemented in C++ and in the KSgeneral package ^{[9]} of the R project for statistical computing. The functions disc_ks_test()
, mixed_ks_test()
and cont_ks_test()
compute also the KS test statistic and pvalues for purely discrete, mixed or continuous null distributions and arbitrary sample sizes. The KS test and its pvalues for discrete null distributions and small sample sizes are also computed in ^{[12]} as part of the dgof package of the R project for statistical computing. Major statistical packages among which SAS PROC NPAR1WAY
^{[13]}, Stata ksmirnov
^{[14]} implement the KS test under the assumption that is continuous, which is more conservative if the null distribution is actually not continuous (see ^{[15]}
^{[16]}
^{[17]}).
Twosample Kolmogorov–Smirnov test
The Kolmogorov–Smirnov test may also be used to test whether two underlying onedimensional probability distributions differ. In this case, the Kolmogorov–Smirnov statistic is
where and are the empirical distribution functions of the first and the second sample respectively, and is the supremum function.
For large samples, the null hypothesis is rejected at level if
Where and are the sizes of first and second sample respectively. The value of is given in the table below for the most common levels of
0.10  0.05  0.025  0.01  0.005  0.001  
1.073  1.224  1.358  1.517  1.628  1.858 
and in general^{[18]} by
Note that the twosample 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. A shortcoming of the Kolmogorov–Smirnov test is that it is not very powerful because it is devised to be sensitive against all possible types of differences between two distribution functions. ^{[19]} and ^{[20]} showed evidence that the Cucconi test, originally proposed for simultaneously comparing location and scale, is much more powerful than the Kolmogorov–Smirnov test when comparing two distribution functions.
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 F_{n}(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(D_{n} > D_{α}) = α, then a band of width ±D_{α} around F_{n}(x) will entirely contain F(x) with probability 1 − α.
The Kolmogorov–Smirnov statistic in more than one dimension
A distributionfree multivariate Kolmogorov–Smirnov goodness of fit test has been proposed by Justel, Peña and Zamar (1997).^{[21]} 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 or 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 2^{d}−1 such orderings. One such variation is due to Peacock^{[22]} and another to Fasano and Franceschini^{[23]} (see Lopes et al. for a comparison and computational details).^{[24]} Critical values for the test statistic can be obtained by simulations, but depend on the dependence structure in the joint distribution.
In one dimension, the Kolmogorov–Smirnov statistic is identical to the socalled star discrepancy D, so another native KS extension to higher dimensions would be simply to use D also for higher dimensions. Unfortunately, the star discrepancy is hard to calculate in high dimensions.
See also
References
 ^ Stephens, M. A. (1974). "EDF Statistics for Goodness of Fit and Some Comparisons". Journal of the American Statistical Association. 69 (347): 730–737. doi:10.2307/2286009. JSTOR 2286009.
 ^ Marsaglia G, Tsang WW, Wang J (2003). "Evaluating Kolmogorov's Distribution". Journal of Statistical Software. 8 (18): 1–4. doi:10.18637/jss.v008.i18.
 ^ ^{a} ^{b} Kolmogorov A (1933). "Sulla determinazione empirica di una legge di distribuzione". G. Ist. Ital. Attuari. 4: 83–91.
 ^ Smirnov N (1948). "Table for estimating the goodness of fit of empirical distributions". Annals of Mathematical Statistics. 19 (2): 279–281. doi:10.1214/aoms/1177730256.
 ^ Vrbik, Jan (2018). "SmallSample Corrections to Kolmogorov–Smirnov Test Statistic". Pioneer Journal of Theoretical and Applied Statistics. 15 (1–2): 15–23.
 ^ ^{a} ^{b} Simard R, L'Ecuyer P (2011). "Computing the TwoSided Kolmogorov–Smirnov Distribution". Journal of Statistical Software. 39 (11): 1–18. doi:10.18637/jss.v039.i11.
 ^ Moscovich A, Nadler B (2017). "Fast calculation of boundary crossing probabilities for Poisson processes". Statistics and Probability Letters. 123: 177–182.
 ^ ^{a} ^{b} ^{c} Dimitrova DS, Kaishev VK, Tan S (2019). "Computing the Kolmogorov–Smirnov Distribution when the Underlying cdf is Purely Discrete, Mixed or Continuous". Journal of Statistical Software. forthcoming.
 ^ ^{a} ^{b} Dimitrova, Dimitrina; Kaishev, Vladimir; Tan, Senren. "KSgeneral: Computing PValues of the KS Test for (Dis)Continuous Null Distribution". cran.rproject.org/web/packages/KSgeneral/index.html.
 ^ Pearson, E. S. and Hartley, H. O., eds. (1972). Biometrika Tables for Statisticians. 2. Cambridge University Press. pp. 117–123, Tables 54, 55. ISBN 9780521069373.CS1 maint: Uses editors parameter (link)
 ^ Shorack, Galen R.; Wellner, Jon A. (1986). Empirical Processes with Applications to Statistics. Wiley. p. 239. ISBN 9780471867258.
 ^ Arnold, Taylor B.; Emerson, John W. (2011). "Nonparametric GoodnessofFit Tests for Discrete Null Distributions" (PDF). The R Journal. 3 (2): 34\[Dash]39.
 ^ "SAS/STAT(R) 14.1 User's Guide". support.sas.com. Retrieved 14 April 2018.
 ^ "ksmirnov — Kolmogorov–Smirnov equalityofdistributions test" (PDF). stata.com. Retrieved 14 April 2018.
 ^ Noether GE (1963). "Note on the Kolmogorov Statistic in the Discrete Case". Metrika. 7 (1): 115–116.
 ^ Slakter MJ (1965). "A Comparison of the Pearson ChiSquare and Kolmogorov GoodnessofFit Tests with Respect to Validity". Journal of the American Statistical Association. 60 (311): 854–858.
 ^ Walsh JE (1963). "Bounded Probability Properties of Kolmogorov–Smirnov and Similar Statistics for Discrete Data". Annals of the Institute of Statistical Mathematics. 15 (1): 153–158.
 ^ Eq. (15) in Section 3.3.1 of Knuth, D.E., The Art of Computer Programming, Volume 2 (Seminumerical Algorithms), 3rd Edition, Addison Wesley, Reading Mass, 1998.
 ^ Marozzi, Marco (2009). "Some Notes on the LocationScale Cucconi Test". Journal of Nonparametric Statistics. 21 (5): 629–647. doi:10.1080/10485250902952435.
 ^ Marozzi, Marco (2013). "Nonparametric Simultaneous Tests for Location and Scale Testing: a Comparison of Several Methods". Communications in Statistics – Simulation and Computation. 42 (6): 1298–1317. doi:10.1080/03610918.2012.665546.
 ^ Justel, A.; Peña, D.; Zamar, R. (1997). "A multivariate Kolmogorov–Smirnov test of goodness of fit". Statistics & Probability Letters. 35 (3): 251–259. CiteSeerX 10.1.1.498.7631. doi:10.1016/S01677152(97)000205.
 ^ Peacock J.A. (1983). "Twodimensional goodnessoffit testing in astronomy". Monthly Notices of the Royal Astronomical Society. 202 (3): 615–627. Bibcode:1983MNRAS.202..615P. doi:10.1093/mnras/202.3.615.
 ^ Fasano, G., Franceschini, A. (1987). "A multidimensional version of the Kolmogorov–Smirnov test". Monthly Notices of the Royal Astronomical Society. 225: 155–170. Bibcode:1987MNRAS.225..155F. doi:10.1093/mnras/225.1.155. ISSN 00358711.CS1 maint: Uses authors parameter (link)
 ^ Lopes, R.H.C., Reid, I., Hobson, P.R. (April 23–27, 2007). The twodimensional Kolmogorov–Smirnov test (PDF). XI International Workshop on Advanced Computing and Analysis Techniques in Physics Research. Amsterdam, the Netherlands.CS1 maint: Uses authors parameter (link)
Further reading
 Daniel, Wayne W. (1990). "Kolmogorov–Smirnov onesample test". Applied Nonparametric Statistics (2nd ed.). Boston: PWSKent. pp. 319–330. ISBN 9780534919764.
 Eadie, W.T.; D. Drijard; F.E. James; M. Roos; B. Sadoulet (1971). Statistical Methods in Experimental Physics. Amsterdam: NorthHolland. pp. 269–271. ISBN 9780444101174.
 Stuart, Alan; Ord, Keith; Arnold, Steven [F.] (1999). Classical Inference and the Linear Model. Kendall's Advanced Theory of Statistics. 2A (Sixth ed.). London: Arnold. pp. 25.37–25.43. ISBN 9780340662304. MR 1687411.
 Corder, G. W.; Foreman, D. I. (2014). Nonparametric Statistics: A StepbyStep Approach. Wiley. ISBN 9781118840313.
 Stephens, M. A. (1979). "Test of fit for the logistic distribution based on the empirical distribution function". Biometrika. 66 (3): 591–595. doi:10.1093/biomet/66.3.591.
External links
 Hazewinkel, Michiel, ed. (2001) [1994], "Kolmogorov–Smirnov test", Encyclopedia of Mathematics, Springer Science+Business Media B.V. / Kluwer Academic Publishers, ISBN 9781556080104
 Short introduction
 KS test explanation
 JavaScript implementation of one and twosided tests
 Online calculator with the KS test
 Opensource C++ code to compute the Kolmogorov distribution and perform the KS test
 Paper on Evaluating Kolmogorov’s Distribution; contains C implementation. This is the method used in Matlab.
 Paper on Computing the TwoSided Kolmogorov–Smirnov Distribution; computing the cdf of the KS statistic in C or Java.
 Paper powerlaw: A Python Package for Analysis of HeavyTailed Distributions; Jeff Alstott, Ed Bullmore, Dietmar Plenz. Among others, it also performs the Kolmogorov–Smirnov test. Source code and installers of powerlaw package are available at PyPi.