Kolmogorov-Smirnov Test Calculator
Statistical tests
- Statistic: the largest gap between the empirical and fitted cumulative curves is D = 0.184 at n = 42.
- Stephens' adjustment scales D by (sqrt(n) + 0.12 + 0.11 / sqrt(n)) = 6.618, giving lambda = 1.2177.
- Series: the Kolmogorov survival series 2 x sum of (-1)^(k-1) e^(-2 k^2 lambda^2) converges to a p-value of 0.1031.
- Kolmogorov-Smirnov result: p = 0.1031; D does not reject the fitted distribution at 5%, where the critical D is 0.2095.
The Kolmogorov-Smirnov test reduces a whole distribution comparison to one number: D, the largest vertical gap between the empirical cumulative distribution of your sample and the cumulative curve of the distribution you are testing against. It is beautifully general — any continuous distribution can be tested — and its p-value comes from a distribution that Kolmogorov derived in 1933 and that still has no closed form.
What software actually computes is the alternating series 2 x sum of (-1)^(k-1) e^(-2 k^2 lambda^2), where lambda is D rescaled by a finite-sample adjustment due to Stephens: (sqrt(n) + 0.12 + 0.11/sqrt(n)) x D. The series converges within a handful of terms, which is why the test is cheap to run exactly rather than by table lookup.
Enter D and the sample size. The calculator returns the p-value, lambda, and the critical D values at 5 and 1 percent for direct comparison.
Worked examples
Kolmogorov-Smirnov test of a close fit
(0.184 · 42)
| p-value | 0.1031 |
| Kolmogorov lambda | 1.2177 |
| Critical D at 5% | 0.2095 |
| Critical D at 1% | 0.2512 |
Kolmogorov-Smirnov test of a shifted fit
(0.092 · 150)
| p-value | 0.1495 |
| Kolmogorov lambda | 1.1386 |
| Critical D at 5% | 0.1109 |
| Critical D at 1% | 0.1329 |
Kolmogorov-Smirnov test of a two-sample gap
(0.278 · 25)
| p-value | 0.0336 |
| Kolmogorov lambda | 1.4295 |
| Critical D at 5% | 0.2716 |
| Critical D at 1% | 0.3256 |
The D statistic as a maximum gap
D is a worst-case measure: it finds the single point where the sample's cumulative curve strays furthest from the fitted curve and ignores everything else. That makes the test sensitive to differences in the centre of the distribution, where cumulative curves separate most, and comparatively deaf to differences confined to the far tails — the opposite profile to the Anderson-Darling test, which weights the tails deliberately.
In the first worked example D is 0.184 at n = 42. Stephens' factor is 6.618, giving a lambda of 1.2177, and the series returns a p-value of 0.1030: a gap this large arises by chance about one time in ten under the fitted distribution, so the test does not reject. The critical D at 5 percent for this sample size, 0.2096, tells the same story from the other side.
| Quantity | Formula or source | Role |
|---|---|---|
| D | Maximum |empirical CDF - fitted CDF| | Test statistic from your data |
| Lambda | (sqrt(n) + 0.12 + 0.11/sqrt(n)) x D | Stephens-adjusted argument |
| p-value | 2 x sum (-1)^(k-1) e^(-2 k^2 lambda^2) | Kolmogorov distribution survival |
| Critical D, 5% | 1.358 / sqrt(n) | Large-sample approximation |
| Critical D, 1% | 1.628 / sqrt(n) | Large-sample approximation |
Stephens' finite-sample adjustment
Kolmogorov's distribution is the large-sample limit. At modest n the raw sqrt(n) x D scaling misplaces the p-value enough to matter near decision boundaries, and Stephens' correction — adding 0.12 and a small 0.11/sqrt(n) term inside the scaling — pulls the approximation into line across the sample sizes researchers actually have. Most modern software, and this calculator, build it in.
The large-sample example shows the machinery at its calmest: D of 0.092 at n = 150 adjusts to a lambda of 1.1386 and a p-value of 0.1495. The small-sample example is the dramatic one — D of 0.278 at n = 25 gives lambda 1.4295 and p of 0.0336, a rejection at 5 percent driven by a genuinely wide gap rather than by sample size.
- D must come from a fully specified distribution, or the Lilliefors correction applies instead.
- The test needs continuous data; heavy ties from rounding distort D and the p-value.
- Critical values 1.358/sqrt(n) and 1.628/sqrt(n) are approximations that Stephens' p-value refines.
- For tail-sensitive questions, prefer Anderson-Darling; KS is a centre-weighted test.
- A two-sample KS test uses a different scaling based on both sample sizes.
Worked examples
Example 1: KS statistic D 0.184; Sample size n 42. p-value = 0.1031. Supporting values: Kolmogorov lambda 1.2177; Critical D at 5% 0.2095; Critical D at 1% 0.2512. Statistic: the largest gap between the empirical and fitted cumulative curves is D = 0.184 at n = 42. Stephens' adjustment scales D by (sqrt(n) + 0.12 + 0.11 / sqrt(n)) = 6.618, giving lambda = 1.2177. Series: the Kolmogorov survival series 2 x sum of (-1)^(k-1) e^(-2 k^2 lambda^2) converges to a p-value of 0.1031. Kolmogorov-Smirnov result: p = 0.1031; D does not reject the fitted distribution at 5%, where the critical D is 0.2095.
Example 2: KS statistic D 0.092; Sample size n 150. p-value = 0.1495. Supporting values: Kolmogorov lambda 1.1386; Critical D at 5% 0.1109; Critical D at 1% 0.1329. Statistic: the largest gap between the empirical and fitted cumulative curves is D = 0.092 at n = 150. Stephens' adjustment scales D by (sqrt(n) + 0.12 + 0.11 / sqrt(n)) = 12.376, giving lambda = 1.1386. Series: the Kolmogorov survival series 2 x sum of (-1)^(k-1) e^(-2 k^2 lambda^2) converges to a p-value of 0.1495. Kolmogorov-Smirnov result: p = 0.1495; D does not reject the fitted distribution at 5%, where the critical D is 0.1109.
Example 3: KS statistic D 0.278; Sample size n 25. p-value = 0.0336. Supporting values: Kolmogorov lambda 1.4295; Critical D at 5% 0.2716; Critical D at 1% 0.3256. Statistic: the largest gap between the empirical and fitted cumulative curves is D = 0.278 at n = 25. Stephens' adjustment scales D by (sqrt(n) + 0.12 + 0.11 / sqrt(n)) = 5.142, giving lambda = 1.4295. Series: the Kolmogorov survival series 2 x sum of (-1)^(k-1) e^(-2 k^2 lambda^2) converges to a p-value of 0.0336. Kolmogorov-Smirnov result: p = 0.0336; D rejects the fitted distribution at 5%, where the critical D is 0.2716.
KS vs Lilliefors and Anderson-Darling
The most common misuse of this test is feeding it a normal distribution whose mean and variance were estimated from the same sample. Fitting first shrinks D, so the standard p-value becomes far too forgiving — the test stops rejecting data it should. Lilliefors tabulated the corrected critical values for exactly that case in 1967, and any normality check done by estimating parameters belongs to his version, not Kolmogorov's.
Anderson-Darling answers a neighbouring question with a weighted integral of squared gaps instead of the single maximum, gaining power in the tails at the cost of a less intuitive statistic. Choosing between them is choosing which departures you fear: central shifts and shape changes argue for KS, tail behaviour argues for Anderson-Darling.
Kolmogorov-Smirnov in practice
The test's generality keeps it employed far from its statistical birthplace: validating Monte Carlo generators against their target distributions, checking whether sensor readings still match a calibration distribution, and comparing simulated and observed rainfall in climate work. Anywhere a cumulative curve can be drawn, D can be measured.
Its honest limitations travel with it. Report D and n with the p-value — 'D = 0.278, n = 25, p = 0.0336' is a finding a reader can weigh, while a bare 'p < 0.05' hides whether the gap was wide or the sample merely large.
Power, ties and the shape of departures
KS power has a geography: the test is most sensitive where the cumulative curves can separate most, near the median of the distribution, and weakest in the tails, where cumulative values are pinned near 0 and 1 and even large density differences move the curves little. A contaminating process that fattens only the extreme tails can pass a KS test at sample sizes where an Anderson-Darling test convicts it easily. Choosing KS is therefore a bet about where departures will live, and it should be made consciously.
Ties are the practical enemy. The test's distribution theory assumes continuous data, but real measurements are rounded, and rounding manufactures ties that shrink D and distort the p-value in the conservative direction. With heavily rounded data the honest options are jittering with a stated method, a permutation version of the test, or a test designed for discrete data. Pretending the rounded values are continuous is the one option the theory does not cover.
Finally, remember what a rejection does not say. D locates the largest gap but the test returns no estimate of how the distributions differ — shift, spread, shape or all three. The statistic opens the investigation; the cumulative plot, which costs nothing to draw, is what closes it.
Kolmogorov derived his distribution in 1933 for a problem in probability theory, and Smirnov built the practical test on it within the decade; the pairing of a pure mathematician's limit theorem with an applied statistician's tables is why the test carries both names. It is a pleasing thought that the series this page sums — a handful of exponentials — is the same object that appeared in that 1933 paper, unchanged in ninety years while the computers evaluating it changed beyond recognition. Some statistics are approximations of their era; this one is a theorem that merely waited for arithmetic to get cheap.
FAQs
What p-value does the first example give?
0.1030, from D = 0.184 at n = 42 — not a rejection at the 5 percent level.
What lambda results from the adjustment?
1.2177, from Stephens' factor of 6.618 times D.
What critical D at 5% pairs with the first example?
0.2096; the observed D of 0.184 falls short of it, matching the p-value's verdict.
What p-value does the large-sample example give?
0.1495 from a small D of 0.092 at n = 150 — a narrow gap that even a large sample cannot convict.
What p-value does the small-sample example give?
0.0336, a rejection driven by a wide D of 0.278 at n = 25.
When must Lilliefors replace this test?
When the tested distribution's parameters were estimated from the same data, which shrinks D and makes standard KS p-values far too lenient.