Kolmogorov-Smirnov Test

Statistics
Introduced by
Andrey Nikolaevich Kolmogorov; Nikolai Vasilyevich Smirnov
Year
1933
Type
Nonparametric goodness-of-fit test

What does it do?

The Kolmogorov-Smirnov (KS) test is a nonparametric goodness-of-fit test that assesses whether a sample comes from a specified theoretical distribution, such as the normal or exponential. First formalised by Andrey Kolmogorov in 1933 and further developed by Nikolai Smirnov in 1948, it compares the empirical cumulative distribution function of the observed data against a target theoretical CDF and quantifies their maximum absolute deviation.

The intuition behind the method

Imagine plotting the staircase-shaped cumulative frequency curve of your data alongside the smooth theoretical CDF you are testing against. The KS statistic is simply the largest vertical gap between the two curves at any point along the x-axis. If that gap is small, the data are consistent with the theoretical distribution; if it is large, something in the distribution shape does not match. Because the test works directly on the CDF rather than on binned frequencies, it does not require any arbitrary grouping of the data.

History

Andrey Kolmogorov published the theoretical foundation of the test in 1933, in Giornale dell'Istituto Italiano degli Attuari, deriving the limiting distribution of the maximum deviation between an empirical and a theoretical CDF. Nikolai Smirnov published tables for the test in 1948 in the Annals of Mathematical Statistics. Frank Massey's 1951 paper in the Journal of the American Statistical Association further discussed the test for goodness of fit. A two-sample form, which compares two independent samples, and the Lilliefors adaptation for estimated parameters are later extensions of the same idea.

When to use it

Use the one-sample KS test when a continuous variable must be checked against a fully specified theoretical distribution, meaning its parameters are fixed in advance rather than estimated from the same sample. It suits cases where a method that assumes that distribution is to be applied. If the question is only whether data are normal, Shapiro-Wilk is generally the more powerful choice. When the distribution parameters are estimated from the same sample, do not use the standard critical values; apply the Lilliefors correction instead. With small samples (roughly below 20-30 observations) the test has low power to detect departures, so a non-significant result is weak evidence of fit. For discrete or ordinal data the standard null distribution is only an approximation (see Limitations).

Limitations and considerations

  • Generally less powerful than Shapiro-Wilk when the specific question is whether data are normal.
  • Designed for continuous distributions. For discrete or ordinal data the Kolmogorov null distribution is only an upper bound, so the test is conservative (p-values too large) and loses power, although some textbooks describe it as applicable to data of at least ordinal level.
  • When distribution parameters are estimated from the sample, the standard critical values are conservative, so the test rejects less often than its nominal significance level; the Lilliefors correction addresses this for the normal case.
  • Sensitivity is spread across the whole distribution, so departures concentrated in the tails can be missed; Anderson-Darling gives greater weight to the tails.
  • Ties or rounding in the data make p-values approximate and generally conservative.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • When the reference distribution is fully specified, the test makes no parametric assumption about the data beyond continuity.
  • Works directly on the continuous empirical CDF, so no arbitrary binning of the data is needed.
  • Responds to differences in location and overall shape, not only to a single moment such as the mean.
  • The statistic is easy to visualise as the largest vertical gap between two CDF curves.

Applications

  • Checking the normality assumption before applying parametric tests such as t-tests or ANOVA, when a formal check is needed.
  • Verifying that regression residuals follow the distribution assumed by the model.
  • Testing whether survival times, inter-arrival times or other continuous measurements follow a theoretical distribution such as the exponential or Weibull.
  • Quality control: confirming that the output of a production process matches a target distribution specification.

How it works

How it works

1

The null hypothesis states that the sample was drawn from the specified theoretical distribution F₀(x), for example a normal distribution with given mean and standard deviation. The two-sided alternative states that the underlying population distribution differs from F₀(x); the test is then sensitive to differences anywhere along the distribution, including the tails, centre, or overall shape. One-sided alternatives are also available in standard software; they ask whether one CDF lies uniformly to one side of the other.

Formula
H_0:\ F(x) = F_0(x) \quad H_1:\ F(x) \neq F_0(x)
2

The empirical CDF Fₙ(x) is constructed by sorting the n observations and assigning cumulative proportions. The test statistic D is the supremum (largest absolute value) of the difference between Fₙ(x) and the theoretical CDF F₀(x); because Fₙ is a step function, it is evaluated at and just before each observed data point. A larger D means a wider gap between the sample and the target distribution. Under the null hypothesis, D follows the Kolmogorov distribution, whose critical values are tabulated.

Formula
D_n = \sup_{x}\, |F_n(x) - F_0(x)|
3

The observed D is compared against a critical value D_{n,α} that depends on sample size n and significance level α. If D exceeds the critical value, equivalently if the p-value falls below α (commonly 0.05), the null hypothesis is rejected, indicating that the sample distribution differs significantly from the theoretical one. Software may report exact or asymptotic p-values; for small samples the exact version is preferable. Failure to reject means the data are compatible with the assumed distribution, though this does not prove the distribution is exactly correct.

Formula
\text{reject } H_0 \text{ if } D_n > D_{n,\alpha} \text{ (critical value), equivalently if } p < \alpha \text{ (commonly } \alpha = 0.05)

Common pitfalls

  • Using standard KS critical values when the mean and standard deviation were estimated from the same data; apply the Lilliefors test instead.
  • Reading a non-significant result as proof that the data follow the distribution; it shows only that the data are not inconsistent with it.
  • Applying the one-sample KS test to compare two empirical samples; the two-sample KS variant is designed for that question.
  • Interpreting a non-significant result from a small sample as good evidence of fit, when power is low.
  • Choosing F₀ after looking at the data, which invalidates the null distribution.

Frequently asked questions

How does the KS test differ from the Shapiro-Wilk test for normality?

Both test whether data are normally distributed, but they differ in approach and power. Shapiro-Wilk is designed specifically for normality and is generally more powerful than the KS test for that question. The KS test is more general: it can test against any fully specified continuous distribution, not just the normal. This generality comes at the cost of lower power when the question is only about normality.

Can I use the KS test when I estimated the mean and standard deviation from my data?

Not with the standard version. When the distribution parameters are estimated from the same sample being tested, the standard critical values are conservative, meaning the test rejects less often than it should at the nominal level. In this common situation, use the Lilliefors test, which adjusts the critical values for estimated normal-distribution parameters.

What is the difference between the one-sample and two-sample KS test?

The one-sample KS test compares a single empirical CDF against a theoretical CDF that is fully specified in advance. The two-sample KS test compares the empirical CDFs of two independent samples against each other to decide whether they were drawn from the same population distribution, without specifying what that distribution is.

Does the KS test work for ordinal or count data?

It is not well suited to them. The Kolmogorov null distribution assumes continuous data; for discrete data it is only an upper bound, so the test becomes conservative and loses power. Some textbooks describe the test as applicable to data of at least ordinal level, but chi-square goodness-of-fit or other tests designed for discrete data are generally more appropriate.

Related methods

Sources

  1. Kolmogorov, A. N. (1933). Sulla determinazione empirica di una legge di distribuzione. Giornale dell'Istituto Italiano degli Attuari, 4, 83–91.

    Open publication reference
  2. Smirnov, N. V. (1948). Table for estimating the goodness of fit of empirical distributions. Annals of Mathematical Statistics, 19(2), 279–281.

    Open DOI reference
  3. Massey, F. J. (1951). The Kolmogorov-Smirnov test for goodness of fit. Journal of the American Statistical Association, 46(253), 68–78.

    Open DOI reference
  4. Conover, W. J. (1999). Practical Nonparametric Statistics (3rd ed.). Wiley.

    ISBN: 978-0471160687