Comparing Distributions
Comparing distributions means quantifying how similar or different two probability distributions are, using graphical tools (Q–Q plots, ECDF overlays), summary-statistic comparisons (mean, variance, quantiles), formal hypothesis tests (two-sample t, Kolmogorov–Smirnov, Mann–Whitney), and distance/divergence measures (total variation, KL divergence, Wasserstein). Key result: different tools answer different questions — "are these the same distribution?" vs. "are their means equal?" vs. "how far apart are they?" — and choosing the wrong one is the central practical error. Applies across statistics, machine learning, econometrics, and the experimental sciences. Foundational figures: Kolmogorov, Smirnov, Mann, Whitney, and Wasserstein (1969 metric).Given two collections of data (or two theoretical models), comparing distributions asks whether they share the same underlying probability law, and if not, how and how much they differ. This matters because almost every inferential question — does a drug change outcomes, do two algorithms behave the same, is a sample drawn from a hypothesized model — reduces to comparing a sample distribution to another sample or to a reference. The discipline spans location (where the mass sits), scale (how spread out), shape (skew, tails), and whole-distribution comparisons. A surprising fact: two distributions can have identical means and variances yet be radically different (e.g., a normal vs. a bimodal mixture), so mean-based tests can completely miss a real effect — which is exactly why distribution-level tools exist.
The Core Insight
There is no single "distance" between distributions — there is a toolbox, and each tool privileges a different feature. Mean comparisons ask about the first moment; variance comparisons about the second; the Kolmogorov–Smirnov statistic about the largest vertical gap between cumulative distribution functions (CDFs); KL divergence about information loss; Wasserstein distance about the physical cost of moving probability mass. The art of comparing distributions is matching the question ("equal centers?" "same shape?" "indistinguishable laws?") to the right instrument, while respecting whether your data are paired or independent, continuous or discrete, and how heavy the tails are.
Formal Statement
Let and be random variables with cumulative distribution functions and . We have independent samples from and from .
Equality of Distributions
Two distributions are equal, written , if their CDFs agree everywhere:
Empirical Cumulative Distribution Function (ECDF)
The ECDF of a sample estimates the true CDF by the fraction of observations at or below each point:
where is the indicator function (1 if true, 0 if false).
Kolmogorov–Smirnov Statistic
The two-sample KS statistic is the supremum (largest) vertical distance between the two ECDFs:
Total Variation Distance
For distributions with densities and (or PMFs), the total variation distance is
where the supremum runs over all measurable events .
Kullback–Leibler Divergence
The KL divergence from to measures expected information lost when is used to approximate :
Wasserstein (Earth Mover's) Distance
The -Wasserstein distance is the minimal cost of transporting mass from to :
where is the set of joint distributions (couplings) with marginals and .
Glivenko–Cantelli
The ECDF converges uniformly to the true CDF almost surely:
Kolmogorov Limiting Distribution
Under (continuous), the scaled KS statistic has a distribution-free limit:
Why It Holds / Derivation
The KS Test Is Distribution-Free Under the Null
Claim: Under with continuous, the null distribution of does not depend on the underlying .- Probability integral transform. If with continuous, then is Uniform. Apply to every observation in both samples.
- ECDFs transform consistently. Since is monotone increasing, . Writing and , the indicator equals .
- The supremum is invariant. As ranges over , ranges over , so
- Conclusion. Under both transformed samples are i.i.d. Uniform, irrespective of the original . Hence the distribution of depends only on and — not on .
KL Divergence Is Nonnegative (Gibbs' Inequality)
- Write where .
- The function is convex on .
- By Jensen's inequality, .
- Compute the inner expectation: .
- Therefore , with equality iff a.e., i.e. .
Two ECDFs and the Kolmogorov–Smirnov gap
Andrey Kolmogorov | 1903–1987
Kolmogorov axiomatized probability theory in 1933 and, the same year, introduced the goodness-of-fit statistic that compares an ECDF to a hypothesized CDF via their maximal gap. His insight that this gap's limiting distribution is governed by the Brownian bridge — and is free of the underlying distribution — made distribution comparison rigorous and universal. Nikolai Smirnov extended the idea to the two-sample case in 1939, giving the tool used to this day for asking "do these two samples come from the same law?"
Building Intuition
Picture each distribution as a pile of sand on a number line. Comparing means asks only where the balance point of each pile sits — you could shovel sand around wildly without moving it. Comparing variances asks how spread out each pile is. The KS statistic stacks the sand into a running cumulative wall and asks: what is the biggest height difference between the two walls anywhere? Wasserstein distance asks the most physical question of all: if I literally had to shovel one pile into the shape of the other, what is the minimum total "dirt × distance" work? Notice these can disagree dramatically: two piles with the same balance point can have a huge KS gap (different shapes), and two piles a KS test calls "barely different" can be far apart in Wasserstein if the difference lives in the tails. The choice of tool is a choice of what "different" means.
Worked Examples
Two-Sample t-Test for Equal Means
Given: A new fertilizer (group A) and control (group B). Yields (kg/plot): A: , mean , sd . B: , mean , sd . Goal: Test at (two-sided), assuming equal variances. Step 1 — Pooled variance.Two-Sample KS Test for Whole-Distribution Difference
Given: Two small samples (sorted). A: (). B: (). Goal: Test using . Step 1 — Build ECDFs over the pooled sorted points . Each step is .| | | | | |----|------|------|------| | 1 | 0.25 | 0.00 | 0.25 | | 2 | 0.50 | 0.00 | 0.50 | | 3 | 0.50 | 0.25 | 0.25 | | 4 | 0.75 | 0.25 | 0.50 | | 5 | 0.75 | 0.50 | 0.25 | | 6 | 0.75 | 0.75 | 0.00 | | 7 | 1.00 | 0.75 | 0.25 | | 8 | 1.00 | 1.00 | 0.00 |
Step 2 — Maximum gap. (attained at and ). Step 3 — Critical value. For at , the exact critical value is . Step 4 — Decision. Since , we fail to reject .Common Misconceptions
Equal means do NOT imply equal distributions. A two-sample t-test that "finds no difference" tests only the first moment. Two groups can have identical means and still differ wildly in variance, skew, or modality. Always ask which feature your test is sensitive to before declaring distributions "the same." A non-significant test is not evidence of equality. Failing to reject means you lacked power to detect a difference, not that the distributions match. With small samples (as in the KS example above), the test can miss even large real differences. "Absence of evidence is not evidence of absence." KL divergence is not a distance. It is asymmetric, , fails the triangle inequality, and blows up to whenever assigns zero probability where does not. Do not use it as if it were a metric — use TV or Wasserstein for that. Identical mean and variance, totally different shape. Let and let be the two-point mixture placing mass at and at . Both have mean and variance . A t-test and an F-test (variance test) both report "no difference." Yet is discrete and bimodal while is unimodal continuous — a KS or Wasserstein comparison detects a large gap. Moment-matching can perfectly disguise a structural difference.Connections
Comparing distributions sits at the crossroads of several areas. The KS test rests on the Empirical Distribution Function and its convergence (Glivenko–Cantelli), while its limiting law is governed by the Brownian Bridge from stochastic processes. Mean comparisons descend from the Central Limit Theorem and Hypothesis Testing. Divergence measures like KL connect to Information Theory (entropy, cross-entropy) and to Maximum Likelihood Estimation, where minimizing KL to the empirical distribution is maximizing likelihood. Wasserstein distance links to Optimal Transport and underlies modern generative modeling. Rank-based comparisons (Mann–Whitney) belong to Nonparametric Statistics.
Real-World Applications
- Clinical trials (FDA): Two-sample t-tests and Mann–Whitney tests compare treatment vs. placebo outcome distributions to license drugs.
- A/B testing (tech industry): Companies like Netflix and Booking.com use distribution comparisons (KS, bootstrap) to decide whether a website variant changes user behavior, not just average clicks.
- Machine learning — data drift detection: Production ML systems (e.g., at Uber, Amazon) run KS or Population Stability Index tests to flag when incoming feature distributions drift from training data.
- Generative models (WGAN): Wasserstein distance is the training objective of Wasserstein GANs, comparing the generator's output distribution to the data distribution.
- Quality control (manufacturing): Six Sigma programs compare a process's output distribution against specification limits and historical baselines.
- Econometrics — inequality: Lorenz curves and stochastic-dominance tests compare income distributions across countries or policy regimes.
- Particle physics (CERN): Goodness-of-fit comparisons between simulated and measured event distributions validate detector models and signal claims.
Historical Development
- 1908 — William Gosset ("Student") publishes the t-distribution, enabling small-sample mean comparison.
- 1933 — Andrey Kolmogorov introduces the one-sample goodness-of-fit statistic based on the maximal ECDF–CDF gap.
- 1933 — Glivenko and Cantelli prove uniform convergence of the ECDF to the true CDF.
- 1939 — Nikolai Smirnov extends Kolmogorov's idea to the two-sample setting, creating the KS two-sample test.
- 1947 — Henry Mann and Donald Whitney publish the rank-based U test for stochastic ordering of two distributions.
- 1948 — Claude Shannon's information theory provides the conceptual home for cross-entropy and (soon after) KL divergence.
- 1951 — Solomon Kullback and Richard Leibler formalize the directed divergence between distributions.
- 1969 — Leonid Vaserstein (Wasserstein) introduces the metric, rooted in Monge–Kantorovich optimal transport, that now bears his name.
- 2017 — Arjovsky, Chintala, and Bottou introduce Wasserstein GANs, propelling optimal-transport distribution comparison into deep learning.
Subtleties & Limits
Several deep issues remain practically and theoretically active. (1) High-dimensional comparison: the KS test has no canonical multivariate generalization, and estimating Wasserstein or KL distances in high dimensions suffers a curse of dimensionality (sample requirements grow exponentially). Entropic regularization (Sinkhorn distances) and kernel methods (Maximum Mean Discrepancy) are partial answers, but optimal sample complexity is still studied. (2) Calibrated equivalence testing: standard tests are built to detect differences, not to certify similarity; rigorous "two one-sided test" (TOST) equivalence frameworks exist but choosing the equivalence margin remains a modeling judgment. (3) Distribution-free guarantees under dependence: most theory assumes i.i.d. data, yet real time-series and networked data violate this, and the limiting distributions of comparison statistics under general dependence are incompletely characterized.