Kolmogorov–Smirnov test

Intermediate

What you need first. Nothing else on this path comes first. This page is part of Data analysis.

In data analysis, the Kolmogorov–Smirnov test is a goodness-of-fit and two-sample test based on the largest vertical distance between an empirical distribution function and a specified or second empirical distribution function. It is a non-parametric test based on the largest vertical distance between an empirical distribution function and a distribution function it is compared with. In its one-sample form it tests whether a sample could have come from a fully specified continuous distribution; in its two-sample form it tests whether two samples could have come from a common continuous distribution. Massey’s exposition, still the clearest short account of the one-sample test, describes it as a test “based on the maximum difference between an empirical and a hypothetical cumulative distribution” .[1]

Let X1,…,XnX_1, \ldots, X_n be independent observations from an unknown continuous distribution function FF, where a distribution function is defined by F(x)=P(X≤x)F(x) = \mathbb{P}(X \le x) for a random variable XX. The one-sample null hypothesis is H0:F=F0H_0: F = F_0, where F0F_0 is a continuous distribution function specified completely before the data are examined: every parameter of F0F_0 is given a numerical value, not estimated from the sample. The statistic measures the worst disagreement, anywhere on the line, between the sample and F0F_0. Because that disagreement is a distance between two curves rather than a discrepancy in one chosen summary, the test is omnibus: it can in principle detect a difference in location, in spread, in shape, or in any combination of these, but it reports none of them separately. It is a test of significance only. It estimates no parameter and supplies no confidence interval for any feature of FF, although the same critical values can be inverted to give a confidence band for FF, as the section on statistical use explains.

The construction originates with Kolmogorov, who in 1933 studied the distribution of the largest deviation of an empirical distribution function from the true distribution function .[2] The test is distribution-free under H0H_0 in a precise sense explained below: when F0F_0 is continuous, the null distribution of the statistic does not depend on which continuous F0F_0 was specified. That property, and not any assumption of normality, is what makes a single table of critical values possible.

Kolmogorov–Smirnov test

Kolmogorov–Smirnov test
Fact Value
Topic Data analysis
Listed on Data analysis

The empirical distribution function and the one-sample statistic

The empirical distribution function (ECDF) of the sample is

Fn(x)=1n∑i=1nI(Xi≤x),F_n(x) = \frac{1}{n} \sum_{i=1}^{n} I(X_i \le x),

where I(Xi≤x)I(X_i \le x) is the indicator that takes the value 11 when Xi≤xX_i \le x and 00 otherwise. Thus Fn(x)F_n(x) is simply the proportion of observations less than or equal to xx. It is a step function: it is flat between consecutive ordered observations and jumps by 1/n1/n at each observation, or by k/nk/n at a value shared by kk observations. Massey, using the notation SN(x)S_N(x) for the same object, defines it as k/Nk/N, where kk is the number of observations less than or equal to xx .[1]

Write X(1)≤X(2)≤⋯≤X(n)X_{(1)} \le X_{(2)} \le \cdots \le X_{(n)} for the ordered observations. The one-sample Kolmogorov–Smirnov statistic is

Dn=sup⁡x∣Fn(x)−F0(x)∣,D_n = \sup_x |F_n(x) - F_0(x)|,

where sup⁡x\sup_x denotes the supremum, the least upper bound, of the absolute difference over all real xx. The supremum is not an abstraction that requires searching the whole line point by point. Because FnF_n changes only at the observations and F0F_0 is continuous, the largest absolute difference is attained either just after a jump of FnF_n at an observation or just before one. Evaluating both sides of every jump gives the computing form

Dn=max⁡1≤i≤nmax⁡{in−F0(X(i)),  F0(X(i))−i−1n}.D_n = \max_{1 \le i \le n} \max\left\{ \frac{i}{n} - F_0(X_{(i)}), \; F_0(X_{(i)}) - \frac{i-1}{n} \right\}.

The two quantities inside the maximum have separate names and separate uses. The upper one-sided statistic is

Dn+=max⁡1≤i≤n{in−F0(X(i))},D_n^+ = \max_{1 \le i \le n} \left\{ \frac{i}{n} - F_0(X_{(i)}) \right\},

the largest amount by which the ECDF rises above F0F_0, and the lower one-sided statistic is

Dn−=max⁡1≤i≤n{F0(X(i))−i−1n},D_n^- = \max_{1 \le i \le n} \left\{ F_0(X_{(i)}) - \frac{i-1}{n} \right\},

the largest amount by which F0F_0 rises above the ECDF, measured just before the jump at X(i)X_{(i)}. Then Dn=max⁡(Dn+,Dn−)D_n = \max(D_n^+, D_n^-). A large Dn+D_n^+ means the sample accumulates probability faster than F0F_0 somewhere, as happens when the observations are systematically smaller than F0F_0 predicts; a large Dn−D_n^- means the sample accumulates probability more slowly, as happens when the observations are systematically larger. The two-sided statistic discards that directional information, which is why the one-sided statistics are reported in their own right when a directional alternative was specified in advance.

The two-sample test

Let X1,…,XnX_1, \ldots, X_n be a sample from a continuous distribution function FF and Y1,…,YmY_1, \ldots, Y_m an independent sample from a continuous distribution function GG, and let FnF_n and GmG_m be their ECDFs. The two-sample null hypothesis is H0:F=GH_0: F = G, with neither distribution specified. The two-sample statistic is

Dn,m=sup⁡x∣Fn(x)−Gm(x)∣,D_{n,m} = \sup_x |F_n(x) - G_m(x)|,

and its one-sided counterparts are Dn,m+=sup⁡x(Fn(x)−Gm(x))D_{n,m}^+ = \sup_x (F_n(x) - G_m(x)) and Dn,m−=sup⁡x(Gm(x)−Fn(x))D_{n,m}^- = \sup_x (G_m(x) - F_n(x)), so that Dn,m=max⁡(Dn,m+,Dn,m−)D_{n,m} = \max(D_{n,m}^+, D_{n,m}^-). As in the one-sample case, the supremum is attained at an observation of one sample or the other, so the statistic is computed by evaluating both ECDFs at every pooled observation. A large Dn,m+D_{n,m}^+ means that at some point the first sample has accumulated a larger fraction of its observations than the second sample has, which is the pattern expected when the first population’s values tend to be smaller.

Under H0H_0, with F=GF = G continuous, the same probability integral transform argument applies to the pooled data, and ne Dn,m\sqrt{n_e}\, D_{n,m}, where ne=nm/(n+m)n_e = nm/(n+m) is the effective sample size, has approximately the Kolmogorov distribution KK above when both nn and mm are large. The asymptotic 5%5\% critical value is therefore 1.36(n+m)/(nm)1.36 \sqrt{(n+m)/(nm)}. Exact two-sample pp-values, obtained by enumerating or recursing over the possible orderings of the pooled sample, are a separate computation from this limiting approximation and are preferable when either sample is small. That enumeration is finite because the two-sample statistic depends only on the pooled ranks: unlike the one-sample statistic, Dn,mD_{n,m} takes only finitely many values, and its exact null law really is discrete. The two-sample test inherits the one-sample test’s character: it is sensitive to any difference between FF and GG — location, spread or shape — and identifies none of them. If the scientific question is specifically whether one population’s values tend to be larger than the other’s, a rank test aimed at that alternative will usually be more powerful; the Connections section returns to this point.

Why the null distribution does not depend on F0F_0

Suppose H0H_0 is true and F0F_0 is continuous. The probability integral transform states that Ui=F0(Xi)U_i = F_0(X_i) then has a uniform distribution on [0,1][0, 1], for each ii, and the UiU_i remain independent. Applying F0F_0 to both curves converts the comparison into a comparison between the ECDF of a uniform sample and the diagonal line, and the vertical distances are unchanged. Consequently the distribution of DnD_n under H0H_0 is the same for every continuous F0F_0: it depends on nn alone. Massey states the same conclusion in his original notation: the sampling distribution of the maximum deviation “is known, and is independent of F0(x)F_0(x) if F0(x)F_0(x) is continuous” .[1] The NIST/SEMATECH e-Handbook lists this independence as the test’s first attractive feature .[3]

Continuity is doing real work in that argument. If F0F_0 has jumps, the transformed values UiU_i are not uniform, the null distribution does depend on F0F_0, and the standard tables no longer apply exactly. That qualification governs everything said later about discrete distributions and ties.

The null distribution — exact, limiting, and computed

Three different objects are often conflated under the single phrase “the distribution of DnD_n”, and they must be kept apart.

The exact finite-sample distribution. For each fixed nn, P(Dn≤d)\mathbb{P}(D_n \le d) under H0H_0 is a definite number that can in principle be computed exactly, with no appeal to large samples. Smirnov published a table for estimating the goodness of fit of empirical distributions, giving values of the limiting distribution and related percentage points .[4] This exact law is a continuous distribution, not a discrete one, and the distinction matters. What is discrete about the ECDF is its step heights: FnF_n moves in steps of 1/n1/n. But the locations of those steps are the observations themselves, which are random and continuously distributed, so DnD_n — a maximum of continuous functions of the observations — has a continuous law. Already at n=1n = 1, D1=max⁡(U,1−U)D_1 = \max(U, 1-U) for a single uniform UU, which is continuously distributed on [1/2,1][1/2, 1]. The genuinely discrete case in this article is the two-sample statistic below: with the pooled sample held fixed, Dn,mD_{n,m} depends only on the ranks and takes only finitely many values. That discreteness belongs to the rank statistic; do not transfer it to the one-sample law.

The Kolmogorov limiting distribution. As nn increases, n Dn\sqrt{n}\, D_n converges in distribution to a random variable whose distribution function, called the Kolmogorov distribution, is

K(x)=1−2∑k=1∞(−1)k−1e−2k2x2,x>0,K(x) = 1 - 2 \sum_{k=1}^{\infty} (-1)^{k-1} e^{-2 k^2 x^2}, \qquad x > 0,

with K(x)=0K(x) = 0 for x≤0x \le 0. The asymptotic two-sided pp-value for an observed value dd is therefore approximated by 1−K(n d)1 - K(\sqrt{n}\, d). The series converges quickly for moderate and large xx and slowly for small xx, where an equivalent series in the complementary form is preferred; either way, the number produced by the series is a limiting probability, not the exact finite-sample probability, and the two can differ appreciably when nn is small. The limiting percentage points are the source of the familiar constants: the upper 5%5\% point of KK is approximately 1.361.36 and the upper 1%1\% point approximately 1.631.63, so the asymptotic critical values for DnD_n are 1.36/n1.36/\sqrt{n} at the 5%5\% level and 1.63/n1.63/\sqrt{n} at the 1%1\% level. Massey’s Table 1 gives exactly these constants, in the row for samples of size over 3535, as 1.361.36 and 1.631.63 respectively .[1]

Computation of the exact distribution. For most of the test’s history the exact distribution was set aside in favour of one-sided statistics or the limiting form, because no practical algorithm for P(Dn<d)\mathbb{P}(D_n < d) was available. Marsaglia, Tsang and Wang supplied one in 2003: a procedure that, in their words, provides P(Dn<d)\mathbb{P}(D_n < d) “with 13–15 digit accuracy for nn ranging from 2 to at least 16000” .[5] They also assessed how slowly the exact distribution approaches its limiting form, and provided a rapid approximation for the extreme upper tail when nn is large .[5] Modern software that reports an “exact” Kolmogorov–Smirnov pp-value is reporting a computation of this kind; software that reports an asymptotic pp-value is reporting 1−K(n d)1 - K(\sqrt{n}\, d), possibly with a finite-sample adjustment to the argument of KK. The two labels are not interchangeable, and a reported pp-value should say which it is.

Critical values in practice. Massey’s Table 1 remains a serviceable check on software for the one-sample test, but its entries are historical approximations to the exact quantiles, not the exact values themselves. For n=5n = 5 Massey gives 0.4460.446 at the 20%20\% level, 0.5100.510 at the 10%10\% level, 0.5650.565 at the 5%5\% level and 0.6690.669 at the 1%1\% level, and for n=10n = 10 the 20%20\% point is 0.3220.322 .[1] Modern exact computation, by the Marsaglia–Tsang–Wang method described above, puts the n=5n = 5 points at 0.44700.4470, 0.50940.5094, 0.56330.5633 and 0.66850.6685 respectively — close to Massey’s, but not identical with them: his 5%5\% point, 0.5650.565, is slightly larger than the exact 0.56330.5633. Note the comparison at n=5n = 5: the exact 5%5\% value, 0.56330.5633, is smaller than the asymptotic value 1.36/5≈0.6081.36/\sqrt{5} \approx 0.608, so at n=5n = 5 the asymptotic test is slightly conservative at the 5%5\% level, rejecting only for DnD_n above 0.6080.608 where the exact test already rejects above 0.56330.5633. The direction and size of the discrepancy between exact and asymptotic critical values vary with nn and with the level; neither should be assumed to bound the other without checking.

Sensitivity — the centre against the tails

DnD_n is a supremum of an unweighted difference, ∣Fn(x)−F0(x)∣|F_n(x) - F_0(x)|. The sampling variability of Fn(x)F_n(x) is largest near the median of F0F_0, where F0(x)F_0(x) is near 1/21/2, and smallest in the tails, where F0(x)F_0(x) is near 00 or 11. An unweighted supremum is therefore dominated, in practice, by discrepancies in the centre of the distribution: a deviation of a given absolute size in a tail, where the null variability is small and the deviation may be relatively enormous, counts for no more than the same absolute deviation at the centre, where such deviations arise by chance far more readily. The NIST/SEMATECH e-Handbook states the limitation plainly: the test “tends to be more sensitive near the center of the distribution than at the tails” .[3]

The Anderson–Darling test, treated in a companion article, is the standard response to exactly this limitation. It replaces the unweighted difference by a weighted integrated squared difference, with a weight function that grows without bound as F0(x)F_0(x) approaches 00 or 11, so tail discrepancies are charged at something closer to their relative size. The e-Handbook groups the Anderson–Darling and Cramér–von Mises tests together as refinements of the Kolmogorov–Smirnov test that are generally considered more powerful .[3] Neither refinement is uniformly better for every alternative: a discrepancy concentrated in the centre is the Kolmogorov–Smirnov test’s home ground. The choice between them is a choice about where a departure would matter, and it should be made before the data are inspected.

Statistical use

When to use it. The one-sample test is appropriate when a single continuous distribution has been specified in advance, in full, and the question is whether the sample is compatible with it: checking a claimed measurement distribution, a simulation’s output distribution, or a probability integral transform’s uniformity. The two-sample test is appropriate when two independent samples are to be compared without specifying their common form and when any kind of distributional difference is of interest. In both forms the ECDF plot should accompany the test: the statistic reports the size of the largest gap but not its location, whereas the plot shows both, and shows whether a significant gap sits in the centre or in a tail.

A confidence band, from the same numbers. Inverting the one-sample test gives simultaneous confidence limits for the whole unknown FF: the band Fn(x)−dα(n)F_n(x) - d_\alpha(n) to Fn(x)+dα(n)F_n(x) + d_\alpha(n), where dα(n)d_\alpha(n) is the critical value at level α\alpha, contains the true F(x)F(x) for all xx simultaneously with probability 1−α1 - \alpha under the same continuity assumptions. Massey presents this use explicitly, with limits of the form SN(x)−dα(N)<F(x)<SN(x)+dα(N)S_N(x) - d_\alpha(N) < F(x) < S_N(x) + d_\alpha(N) .[1] The band is wide — for a sample of size 100100 its half-width at the 5%5\% level is 1.36/100=0.1361.36/\sqrt{100} = 0.136 [1] — which is an honest reflection of how little a sample of that size pins down an entire distribution function.

Five values against a specified uniform distribution

Five independent values, recorded as proportions, are to be tested against the fully specified hypothesis that they come from a uniform distribution on [0,1][0, 1], for which F0(x)=xF_0(x) = x for 0≤x≤10 \le x \le 1. The ordered sample is

0.05,0.12,0.18,0.25,0.90.0.05, \quad 0.12, \quad 0.18, \quad 0.25, \quad 0.90.

Four of the five values lie in the lowest quarter of the interval. The question is whether that crowding is larger than uniform sampling ordinarily produces. The calculation evaluates both sides of each jump of FnF_n:

Five values against a specified uniform distribution
ii X(i)X_{(i)} F0(X(i))F_0(X_{(i)}) i/ni/n (i−1)/n(i-1)/n i/n−F0(X(i))i/n - F_0(X_{(i)}) F0(X(i))−(i−1)/nF_0(X_{(i)}) - (i-1)/n
1 0.05 0.05 0.20 0.00 0.15 0.05
2 0.12 0.12 0.40 0.20 0.28 −0.08-0.08
3 0.18 0.18 0.60 0.40 0.42 −0.22-0.22
4 0.25 0.25 0.80 0.60 0.55 −0.35-0.35
5 0.90 0.90 1.00 0.80 0.10 0.10

Reading the maxima from the last two columns,

Dn+=0.55,Dn−=0.10,Dn=max⁡(0.55,0.10)=0.55.D_n^+ = 0.55, \qquad D_n^- = 0.10, \qquad D_n = \max(0.55, 0.10) = 0.55.

The maximum occurs at the fourth observation: by x=0.25x = 0.25 the ECDF has already reached 0.800.80, whereas F0F_0 has reached only 0.250.25. The negative entries in the final column are not errors; that column is a list of candidates for a maximum, and candidates below zero simply record points at which the ECDF, just before its jump, was already above F0F_0.

Now the decision, stated three ways so that the exact and the approximate are not confused. First, the exact finite-sample pp-value, computed by the Marsaglia–Tsang–Wang method, is P(D5≥0.55)=0.0597\mathbb{P}(D_5 \ge 0.55) = 0.0597: the exact test rejects at the 10%10\% level and does not reject at the 5%5\% level. Massey’s Table 1 points tell the same story — 0.550.55 exceeds his 10%10\% point 0.5100.510 but not his 5%5\% point 0.5650.565 [1] — but those points are historical approximations; the exact 5%5\% point is 0.56330.5633, not 0.5650.565. Second, the asymptotic pp-value from the Kolmogorov series is 1−K(5×0.55)=1−K(1.2298)≈0.09711 - K(\sqrt{5} \times 0.55) = 1 - K(1.2298) \approx 0.0971, which agrees with the exact value on the 5%5\% decision — both lie above 0.050.05 — but not numerically: 0.09710.0971 against 0.05970.0597 is a large relative difference at this sample size, and it is a limiting probability, not the exact one. Third, the asymptotic 5%5\% critical value is 1.36/5≈0.6081.36/\sqrt{5} \approx 0.608, which 0.550.55 does not exceed. All three readings agree on the 5%5\% decision for these data. The example sits close to the boundary, however: Dn=0.55D_n = 0.55 is above the exact 10%10\% point and below both 5%5\% points, and the exact and asymptotic 5%5\% points themselves differ by 0.0450.045, so a slightly larger statistic could have separated the exact and asymptotic decisions. With five observations the honest summary is that the crowding in the lowest quarter is suggestive but not decisive at the 5%5\% level, and that the one-sided statistic Dn+=0.55D_n^+ = 0.55 correctly locates the departure: the sample accumulates far faster than F0F_0, and Dn−=0.10D_n^- = 0.10 shows there is no corresponding lag anywhere.

Your turn

Two independent samples of four observations each are

  • Sample X: 1.2,  1.5,  2.1,  2.81.2, \; 1.5, \; 2.1, \; 2.8.
  • Sample Y: 1.8,  2.4,  3.0,  3.61.8, \; 2.4, \; 3.0, \; 3.6.

Compute both ECDFs at each of the eight pooled values, and hence Dn,mD_{n,m}, Dn,m+D_{n,m}^+ and Dn,m−D_{n,m}^-. Compare Dn,mD_{n,m} with the asymptotic 5%5\% critical value 1.36(n+m)/(nm)1.36\sqrt{(n+m)/(nm)}, and compute the asymptotic pp-value from the Kolmogorov series using the effective sample size ne=nm/(n+m)n_e = nm/(n+m). Do you reject the null hypothesis of a common distribution at the 5%5\% level?

At the pooled values 1.2,1.5,1.8,2.1,2.4,2.8,3.0,3.61.2, 1.5, 1.8, 2.1, 2.4, 2.8, 3.0, 3.6, the differences Fn(x)−Gm(x)F_n(x) - G_m(x) are 0.25,0.50,0.25,0.50,0.25,0.50,0.25,0.000.25, 0.50, 0.25, 0.50, 0.25, 0.50, 0.25, 0.00. Hence Dn,m+=0.50D_{n,m}^+ = 0.50, Dn,m−=0D_{n,m}^- = 0, and Dn,m=0.50D_{n,m} = 0.50. The asymptotic 5%5\% critical value is 1.368/16≈0.96171.36\sqrt{8/16} \approx 0.9617, which 0.500.50 does not approach. With ne=2n_e = 2, the scaled statistic is 2×0.50≈0.7071\sqrt{2} \times 0.50 \approx 0.7071 and the asymptotic pp-value is 1−K(0.7071)≈0.69941 - K(0.7071) \approx 0.6994. We do not reject the null hypothesis at the 5%5\% level. With only four observations per sample this asymptotic pp-value is a rough guide only; an exact two-sample calculation would be the appropriate reference at this size, and the visible tendency of the X values to fall below the Y values is far from established by samples this small.

Common misconceptions

“The Kolmogorov–Smirnov test tests normality.” It does not, in its standard form. It tests a completely specified distribution, which may happen to be a normal distribution with a stated mean and variance. Testing “normality” with the mean and variance estimated from the sample is the Lilliefors problem, and using the standard table for it is invalid .[6]

“A large pp-value shows the sample came from F0F_0.” It does not. It shows that the largest ECDF deviation is within the range that samples from F0F_0 commonly produce. At small nn that range is very wide, so compatibility is a weak statement.

“The asymptotic pp-value is the exact pp-value.” It is not. One is a limiting probability from the series for KK; the other is a finite-sample probability that, since 2003, can be computed to many digits .[5] At small nn they can support different decisions at a stated level, as the worked example nearly does.

“Ties can be broken at random and the usual table applied.” Randomly breaking ties fabricates an ordering the data do not contain and destroys any calibration the tied data might have supported, in an uncontrolled direction: the resulting pp-value is neither the exact one nor a bound on it. Tied data call for a reference distribution computed for the tied, grouped or discrete structure actually observed.

“The two-sample test shows which distribution is larger.” The two-sided statistic does not. Direction is carried by Dn,m+D_{n,m}^+ and Dn,m−D_{n,m}^- separately, and even a large one-sided statistic establishes a gap between ECDFs at some point, not a uniform ordering of the two distributions at every point.

Assumptions and limits

Ties, discrete distributions, and grouping

The standard test assumes a continuous F0F_0 and, in the two-sample case, a continuous common distribution. Three common departures recur in practice, and they are often said to push in the same direction. The claim needs its reference class: judged against the distribution the recorded values actually follow, each of the three pushes the standard procedure towards conservatism; judged against a latent continuous distribution the values were coarsened from, coarsening can push it the other way, as the discussion of ties shows.

Ties. With genuinely continuous data, ties occur with probability zero. Observed ties therefore signal rounding, grouping, or a discrete underlying variable. A tie makes the ECDF jump by more than 1/n1/n at one point, the set of values DnD_n can take becomes coarser, and the exact null distribution computed for the continuous case no longer holds. What replaces it depends on which null the coarsened values are tested against. Tested against the distribution of the coarsened variable itself — the discrete null the rounding induces — the standard critical values give a conservative test, one whose true rejection probability under that null is below the nominal level, so pp-values are too large and real departures are missed more often than they should be. Tested against the latent continuous distribution the values were rounded from, the same procedure can be severely anti-conservative: round five uniform values to 00 or 11 and the statistic is D=max⁡(K/5,1−K/5)≥0.6D = \max(K/5, 1 - K/5) \ge 0.6 for every count KK of ones, above the exact 5%5\% point 0.56330.5633, so data rounded this coarsely and referred to the original continuous table are rejected essentially always. Coarsening is therefore not a blanket licence to call the standard test conservative; the reference distribution has to be the one the recorded values actually follow.

Discrete F0F_0. If the hypothesised distribution is itself discrete, the probability integral transform fails outright, for the reason given in the section on the null distribution. Massey’s account is explicit that only the continuous case is discussed, “which, of course, excludes discrete populations” ,[1] and his comparison with the chi-squared test repeats that the dd test “cannot be applied to discrete populations, whereas the χ2\chi^2 can be” .[1] Purpose-built variants for discrete distributions exist, in which the null distribution is computed for the specified discrete F0F_0 itself, by recursion or simulation; they are different procedures from the standard test with its universal table, and a standard-table pp-value for a discrete hypothesis should be reported, if at all, as conservative — a statement about testing against the discrete distribution itself, not against a latent continuous distribution the data were coarsened from, the contrast drawn under Ties above.

Grouping. Recording continuous data in intervals can only shrink the statistic, because the largest deviation within an interval is never examined. Massey makes the point directly: “Grouping observations into intervals tends to lower the value of dd” and the appropriate significance levels for grouped data are smaller than those tabled .[1] The NIST/SEMATECH e-Handbook likewise notes that although the test is typically developed for continuous, uncensored and ungrouped data, extensions to discrete distributions and to censored and grouped data exist and are not the standard procedure .[3]

Parameters estimated from the data — the Lilliefors problem

The most consequential misuse of the test is also the most natural one: fitting a family such as the normal distribution by estimating its mean and variance from the very sample being tested, and then referring the resulting DnD_n to the standard Kolmogorov–Smirnov table. That table was built for a completely specified F0F_0. Estimation changes the null distribution, because the fitted F0F_0 has been pulled towards the sample: the ECDF and the fitted curve are no longer independent objects being compared, and DnD_n is systematically smaller than it would be against a prespecified curve of the same family. Referring that shrunken statistic to the standard table is therefore conservative, often severely — a conclusion established for the case Lilliefors tabulated, the normal family with both parameters estimated from the sample, and for other fitted families only where their own reference distributions have been computed; it should not be extended by analogy to arbitrary fitting procedures. In that case the test fails to reject distributions it should reject.

Massey already warned that the test “is correctly used only if the distribution is completely specified” and that “the distribution of the maximum deviation is not known when certain parameters of the population have been estimated from the sample” .[1] Lilliefors supplied the remedy for the normal case in 1967. His opening statement is the definitive one: “The standard tables used for the Kolmogorov-Smirnov test are valid when testing whether a set of observations are from a completely specified continuous distribution. If one or more parameters must be estimated from the sample then the tables are no longer valid” .[6] Lilliefors tabulated critical values, obtained by Monte Carlo calculation, for the statistic computed against a normal distribution whose mean and variance are the sample mean and sample variance .[6] The test using those values — same statistic, different reference distribution — is the Lilliefors test. Its critical values are much smaller than the standard ones at the same nn, which quantifies how much estimation shrinks DnD_n. Two qualifications matter. First, Lilliefors’s table is specific to the normal family with both parameters estimated; other families, and other estimators, need their own reference distributions, nowadays usually obtained by parametric simulation: simulate many samples from the fitted distribution, refit and recompute DnD_n for each, and refer the observed statistic to that simulated distribution. Second, a test that does not reject under the Lilliefors reference distribution has still not shown the data to be normal; it has shown only that the largest ECDF deviation is within the range that fitted normal samples commonly produce.

Assumptions. Independence within each sample, and between samples in the two-sample form; a continuous distribution, fully specified in the one-sample form; and ungrouped observations, are the assumptions on which the exact tables and the limiting distribution rest. The failures do not all push the same way. Estimated parameters, in the tabulated Lilliefors case, and testing coarsened data against their own coarsened null move the procedure in the conservative direction; testing coarsened data against the latent continuous distribution can be severely anti-conservative, as the rounding example under Ties shows; and in every case the standard reference distribution is, strictly, invalidated. Conservatism is not a harmless failure mode: it is lost power, silently, and it can make a fitted family appear compatible with data that a correctly referenced test would reject — while anti-conservatism manufactures rejections the data do not support.

What it cannot do. The test does not estimate an effect, does not locate a difference except through the sign of Dn+D_n^+ against Dn−D_n^-, and does not adjust for covariates. A non-significant result does not establish that F=F0F = F_0; with small nn the critical values are so large — 0.5650.565 at the 5%5\% level when n=5n = 5 — that substantial departures pass undetected. Conversely, with very large nn the critical value 1.36/n1.36/\sqrt{n} becomes tiny, and departures too small to matter for any practical purpose are correctly and uselessly detected. The statistic measures compatibility with a specified curve, not the importance of the incompatibility.

Connections

  • Cumulative distribution function: the test is a comparison between distribution functions, and F0F_0 and FF in every hypothesis above are objects of this kind.
  • P-value: the Kolmogorov–Smirnov pp-value is the null probability of a statistic at least as large as the one observed, and this article’s insistence on separating exact from asymptotic values is a separation between two different computations of that probability.
  • Shapiro–Wilk test: a test of the composite normal hypothesis, in which location and scale are unspecified. Where a Kolmogorov–Smirnov test of normality with estimated parameters requires Lilliefors’s reference distribution, the Shapiro–Wilk statistic is built for the composite hypothesis from the start.
  • Anderson–Darling test: the weighted refinement discussed above. It charges tail discrepancies more heavily than the unweighted supremum DnD_n does, and is generally preferred when tail fit is the question.
  • Wilcoxon rank-sum test: a two-sample test aimed specifically at a tendency for one population’s values to exceed the other’s. Against pure location-shift alternatives it is typically more powerful than the omnibus two-sample Kolmogorov–Smirnov test, which spends its sensitivity on every kind of difference at once.
  • Chi-squared test of independence: the chi-squared goodness-of-fit test is the older grouped-data alternative. Massey’s comparison found the dd test able to detect smaller cumulative deviations at the 50%50\% power level, in part because it treats individual observations separately and loses no information by grouping .[1]
  • Normal distribution: the family most often, and most often incorrectly, placed in the role of F0F_0 with its parameters estimated from the sample under test; the Lilliefors section above gives the correctly referenced version of that use.

Check yourself

  1. A researcher standardises a sample using its own sample mean and sample standard deviation, computes DnD_n against the standard normal distribution function, and refers the result to the standard Kolmogorov–Smirnov table, obtaining a pp-value of 0.400.40. A colleague says the data are therefore comfortably compatible with normality. Identify the two distinct errors in the colleague’s statement.

First, the reference distribution is wrong: the mean and variance were estimated from the sample under test, so the standard table does not apply, and the pp-value of 0.400.40 is not the probability it purports to be. The correctly referenced test is the Lilliefors test, whose critical values are much smaller; the standard-table calculation is conservative, so a correct pp-value would be smaller, possibly much smaller. Second, even a valid large pp-value would not show compatibility in any strong sense: it would show only that the largest ECDF deviation lies within the range fitted normal samples commonly produce, which at small sample sizes is a wide range. The statement errs once about which probability was computed, and once about what a large probability of that kind can establish.

  1. Why is DnD_n computed from both i/n−F0(X(i))i/n - F_0(X_{(i)}) and F0(X(i))−(i−1)/nF_0(X_{(i)}) - (i-1)/n, rather than from i/n−F0(X(i))i/n - F_0(X_{(i)}) alone?

The ECDF jumps at each observation, from (i−1)/n(i-1)/n just before X(i)X_{(i)} to i/ni/n just after it, while the continuous F0F_0 takes the single value F0(X(i))F_0(X_{(i)}) at that point. The vertical gap between the curves therefore has two candidate values at each observation, one on each side of the jump, and the supremum of the absolute gap may be attained on either side. Using only i/n−F0(X(i))i/n - F_0(X_{(i)}) examines only the gaps just after the jumps, takes no account of sign, and can miss the largest gap entirely: in the worked pattern of a sample lagging behind F0F_0, the dominant gap sits just before a jump and is captured only by the second expression. The maximum of both expressions, over all ii, is DnD_n; the separate maxima are Dn+D_n^+ and Dn−D_n^-.

  1. For a one-sample test with n=8n = 8, an observed statistic is Dn=0.50D_n = 0.50. Massey’s Table 1 critical values at n=8n = 8 are 0.4570.457 at the 5%5\% level and 0.5430.543 at the 1%1\% level (historical approximations; modern exact computation gives 0.45430.4543 and 0.54180.5418). State the decision at each level, and whether the asymptotic 5%5\% critical value 1.36/81.36/\sqrt{8} gives the same 5%5\% decision.

Against the exact points, 0.50>0.45430.50 > 0.4543, so the exact test rejects the null hypothesis at the 5%5\% level; and 0.50<0.54180.50 < 0.5418, so it does not reject at the 1%1\% level. Massey’s approximations, 0.4570.457 and 0.5430.543, give the same two decisions. The asymptotic 5%5\% critical value is 1.36/8≈0.4811.36/\sqrt{8} \approx 0.481, and 0.500.50 exceeds it, so the asymptotic comparison gives the same 5%5\% decision here, rejection, although the asymptotic critical value is larger than the exact one and the agreement is a feature of these particular numbers rather than a general equivalence.

History

Kolmogorov introduced the statistic and its limiting distribution in 1933, in a paper on the empirical determination of a distribution law, published in the Giornale dell’Istituto Italiano degli Attuari .[2] Smirnov then developed the theory in the late 1930s and, in 1948, published in The Annals of Mathematical Statistics the table for estimating the goodness of fit of empirical distributions on which practical use long depended .[4] Massey’s 1951 exposition in the Journal of the American Statistical Association records this lineage directly — the test “has been suggested by Kolmogorov, Smirnov, Scheffé, and Wolfowitz”, with the limiting distribution derived by Kolmogorov and by Smirnov — and added tabulated critical values for small samples — close approximations to the exact quantiles, as the comparison in the null-distribution section shows — together with the confidence-band construction .[1] It is from the pairing of Kolmogorov’s one-sample statistic with Smirnov’s work on empirical distributions, including the two-sample problem, that the joint name derives.

For half a century the test was used through tables: exact values for small nn, Smirnov’s limiting values for large nn, and an uncomfortable gap in between. Lilliefors’s 1967 Monte Carlo table for the estimated-parameter normal case was an early admission that simulation, not analysis, would settle the reference distributions the tables could not reach .[6] The computational chapter closed in 2003, when Marsaglia, Tsang and Wang published an algorithm for the exact distribution of DnD_n accurate to 13–15 digits over a wide range of nn, remarking that no easy way to compute that distribution had been provided in the more than 70 years since Kolmogorov’s paper .[5] The test in current software is thus Kolmogorov’s statistic with a twenty-first-century reference distribution, and the distinction between its exact and asymptotic pp-values is a distinction between two eras of its use.

See also

Line chart · Apriori algorithm · Asymptotic analysis · Average treatment effect · Base rate · Bayesian inference · Bayesian model · Bayesian probability

Glossary and index

References

  1. ^ a b c d e f g h i j k l m n a. (p. 68) b. (p. 69) c. (p. 69) d. (Table 1, p. 70) e. (Table 1, p. 70) f. (pp. 76–77) g. (p. 77) h. (Table 1, p. 70) i. (p. 68) j. (p. 76) k. (p. 72) l. (p. 73) m. (pp. 75–76) n. (pp. 68–69) Massey, F. J. (1951). The Kolmogorov-Smirnov Test for Goodness of Fit. Journal of the American Statistical Association, 46(253), 68–78. https://doi.org/10.1080/01621459.1951.10500769
  2. ^ a b a. (pp. 83–91) b. (pp. 83–91) Kolmogorov, A. N. (1933). Sulla determinazione empirica di una legge di distribuzione. Giornale dell'Istituto Italiano degli Attuari, 4, 83–91. https://openlibrary.org/authors/OL62490A
  3. ^ a b c d a. (§1.3.5.16) b. (§1.3.5.16) c. (§1.3.5.16) d. (§1.3.5.16) NIST/SEMATECH (2002). NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.16: Kolmogorov-Smirnov Goodness-of-Fit Test. National Institute of Standards and Technology. https://www.itl.nist.gov/div898/handbook/eda/section3/eda35g.htm
  4. ^ a b a. (pp. 279–281) b. (pp. 279–281) Smirnov, N. (1948). Table for Estimating the Goodness of Fit of Empirical Distributions. The Annals of Mathematical Statistics, 19(2), 279–281. https://doi.org/10.1214/aoms/1177730256
  5. ^ a b c d a. (p. 1) b. (p. 1) c. (p. 1) d. (p. 1) Marsaglia, G., Tsang, W. W. & Wang, J. (2003). Evaluating Kolmogorov's Distribution. Journal of Statistical Software, 8(18), 1–4. https://doi.org/10.18637/jss.v008.i18
  6. ^ a b c d a. (p. 399) b. (p. 399) c. (Table 1, p. 400) d. (Table 1, p. 400) Lilliefors, H. W. (1967). On the Kolmogorov-Smirnov Test for Normality with Mean and Variance Unknown. Journal of the American Statistical Association, 62(318), 399–402. https://doi.org/10.1080/01621459.1967.10482916
Cite this page
Plain text
StatWiki (2026). "Kolmogorov–Smirnov test." StatWiki. Last updated 2 December 2026. https://www.statwiki.io/articles/kolmogorov-smirnov-test.html
BibTeX
@misc{statwiki_kolmogorov_smirnov_test,
  author = {{StatWiki}},
  title = {{Kolmogorov–Smirnov test}},
  year = {2026},
  url = {https://www.statwiki.io/articles/kolmogorov-smirnov-test.html},
  urldate = {2026-12-02},
  note = {StatWiki, last updated 2 December 2026}
}