InfyCalculator
📊

Kolmogorov-Smirnov Test Calculator

Two-sample Kolmogorov–Smirnov test — the D statistic (largest gap between the two empirical CDFs), where it occurs, the exact or asymptotic p-value and the critical D.

Sample 1
Sample 2
Significance level
Loading calculator…

How it works

D = maxₓ |F₁(x) − F₂(x)| over the two empirical CDFs; exact p = 1 − P(every lattice path stays within |i/m − j/n| < D); large samples: p ≈ 2Σ(−1)^(k−1) e^(−2k²λ²), λ = (√nₑ + 0.12 + 0.11/√nₑ)·D; critical D ≈ c(α)·√[(m + n)/(mn)], c(α) = √(−½ ln(α/2))

The two-sample Kolmogorov–Smirnov test compares whole distributions, not just means: it finds the largest vertical distance between the two cumulative distribution functions. It reacts to differences in location, spread or shape. This calculator computes the exact p-value by counting lattice paths (the method SciPy’s ks_2samp uses for small and medium samples) and switches to the Kolmogorov asymptotic formula for very large samples.

Worked example

Two samples of 15 with the same centre but very different spread: D = 0.4667 (largest gap at x = 1.64), exact p = 0.0755 — at α = 0.05 there is no significant difference between the two distributions, even though the second sample looks wider.

Sources: NIST/SEMATECH e-Handbook — Kolmogorov–Smirnov goodness-of-fit test · SciPy — scipy.stats.ks_2samp

Frequently asked questions

What does D mean?

It is the largest difference between the share of sample 1 and the share of sample 2 at or below some value x — a number between 0 (identical ECDFs) and 1 (no overlap at all).

KS test or Mann–Whitney?

Mann–Whitney is more powerful for a shift in location; the KS test also detects differences in spread or shape, at the cost of some power.

Can I use it to test normality?

The one-sample KS test against a normal with estimated mean and SD is badly miscalibrated (that is the Lilliefors problem). For normality use the Shapiro–Wilk test.

What about ties?

The test assumes continuous data. With many ties the p-value is conservative (too large).

Related calculators

Educational tool: check the test’s assumptions (sample size, independence, distribution) before relying on a result for a real decision.