- Introduced by
- N. V. Smirnov
- Year
- 1948
- Type
- Nonparametric two-sample distribution test
What does it do?
The two-sample Kolmogorov-Smirnov test is a nonparametric procedure that asks whether two independent groups come from the same continuous distribution.
It compares the empirical cumulative distribution functions (CDFs) of the two samples and uses the largest absolute vertical distance between them as the test statistic. Because it compares whole distributions rather than averages, it can register differences in shape, location, or spread.
The intuition behind the method
Picture stacking each group's values into a step curve that climbs from 0 to 1 as you sweep from the smallest value to the largest — its empirical CDF. Lay the two curves on top of each other and look for the single point where they are furthest apart vertically. If the two groups really came from the same distribution the curves should hug each other closely everywhere; a large gap anywhere is evidence that the distributions differ.
History
The test is named after N. V. Smirnov, whose 1948 paper, 'Table for Estimating the Goodness of Fit of Empirical Distributions', published in the Annals of Mathematical Statistics, provides tables for judging the maximum distance between empirical distribution functions, the quantity on which the statistic D is based.
When to use it
Choose this test when you have two independent groups, a continuous measurement, and a question about whether the distributions differ in any way, not only in their means. It does not require normality. Its reference distribution assumes continuous data, so it is a poor fit for heavily tied or discrete data, such as counts or rounded scores with many repeated values. Small samples limit the power of the test: with few observations per group the empirical CDFs are too coarse to separate real differences from chance variation, and a permutation test is worth considering. Do not use the standard form when the groups are paired or repeated measures on the same units, because it assumes two independent samples. The standard statistic is two-sided and signals a difference anywhere between the two distributions. A one-sided alternative, in which one CDF lies uniformly and appreciably to one side of the other, can also be specified, but it is a separate hypothesis and must be chosen before the data are examined.
Limitations and considerations
- Power is limited in small samples: with only a few observations per group, the empirical CDFs are too coarse to separate real differences from chance variation.
- Because D is the single largest gap between the two CDFs, a real difference that is spread thinly across the distribution may produce a small D and go undetected.
- Because D is a single maximum, it indicates that the distributions differ somewhere, not where or how; the two CDFs themselves are needed to interpret the result.
- Tied values violate the continuity assumption behind the reference distribution, which can make the p-value unreliable.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Distribution-free under a continuous null: it makes no normality assumption, so it applies to skewed or otherwise non-normal measurements.
- Responds to differences in shape, location, and spread at once, because the statistic is the maximum gap over the whole CDF rather than a difference in a single summary.
- The statistic has a direct reading, the largest vertical distance between the two empirical CDFs, which can be plotted and inspected alongside the test result.
Applications
- Checking whether two independent groups, such as treatment and control, differ in their full outcome distribution rather than only in their average.
- Comparing the distribution of a continuous measurement across two independent populations or conditions.
- Screening whether two samples could plausibly come from the same data-generating process before adopting a model that assumes they do.
How it works
How it works
Under the null hypothesis the two groups share the same underlying continuous distribution, so their cumulative distribution functions are identical: F₁(x) = F₂(x) at every value of x.
Formula
F_1(x) = F_2(x) \quad \text{for all } xEach sample is turned into its empirical CDF, the running fraction of observations at or below each value. The statistic Dₙ,ₘ is the largest vertical gap between the two empirical CDFs across all x. A large D, judged against Smirnov's reference distribution, leads to rejecting the null of equal distributions; because D reads off the maximum gap, it is sensitive to differences in shape, location, and scale at once.
Formula
D_{n,m} = \sup_{x}\,\bigl|\hat{F}_1(x) - \hat{F}_2(x)\bigr|Common pitfalls
- Running the test on heavily tied or discrete data, where the continuity assumption fails.
- Reading a significant result as a difference in averages; it signals that the distributions differ somewhere, not that one group is shifted.
- Relying on the standard p-value with small samples, where a permutation test is the safer alternative.
- Applying the standard form to paired or dependent groups, since it assumes two independent samples.
Frequently asked questions
How is the two-sample KS test different from a t-test or Mann-Whitney test?
A t-test compares means and a Mann-Whitney test compares ranks (a stochastic shift). The KS test compares the entire distributions, so it can flag differences in spread or shape even when the central tendencies match.
What does the D statistic actually measure?
D is the largest vertical distance between the two empirical cumulative distribution functions. The bigger this maximum gap, the stronger the evidence that the two samples come from different distributions.
Do tied values cause problems?
Yes. The test assumes continuous data, so repeated (tied) values can affect the statistic and the p-value. If your data are heavily tied or discrete, treat the result cautiously.
What should I do with very small samples?
With small samples the test has limited power, and a handful of observations gives too little information to compare the CDFs meaningfully. A permutation test is worth considering as an alternative.
How do I read the p-value and the decision?
The null hypothesis is that the two samples share one distribution, F1(x) = F2(x) for all x. The p-value is the probability, if the null is true, of observing a D at least as large as the one computed from your data. Compare it with the significance level chosen in advance: a p-value below that level leads to rejecting the null. Software may report an exact or an asymptotic p-value; the two agree closely mainly in larger samples. A non-significant result does not show that the distributions are equal. With small samples the test may simply lack the power to detect a difference.
Can the test tell me which group tends to have larger values?
The standard statistic is two-sided and detects a difference in either direction without saying which way it runs. A one-sided alternative, in which one empirical CDF lies uniformly and appreciably to one side of the other, is available but is a separate hypothesis that must be specified before testing. Read the direction from the two CDFs themselves, not from D alone.
Related methods
Sources
Smirnov, N. V. (1948). Table for Estimating the Goodness of Fit of Empirical Distributions. Annals of Mathematical Statistics, 19(2), 279-281.
Open DOI referenceConover, W. J. (1999). Practical Nonparametric Statistics (3rd ed.). Wiley.
ISBN: 978-04711606872015_Book_StatisticalAnalysisAndDataDisp, section 5.9 (page not recorded in library)