WASSERSTEIN DISTANCE · EARTH MOVER'S DISTANCE · OPTIMAL TRANSPORT · SINKHORN · RUNS IN YOUR BROWSER · NOTHING UPLOADED

How far apart are these two distributions, and where did the mass move?

Paste a table with a column that says which group each row is in: before and after, this year and last, site A and site B, control and variant. For each numeric column you get the Wasserstein distance (the earth mover's distance) in the column's own units, exactly: how much of it is values moving up and how much moving down, how each quantile shifted, and whether the difference is more than chance.

Across several columns at once you get the optimal transport distance, from Sinkhorn's algorithm (Cuturi 2013), with a certified range that the exact value is guaranteed to lie in, and a map of where each point's mass went.

Nothing you enter leaves this browser tab. Statistical output from data you supply, not advice. Not legal, tax, or financial advice.

Your data

Rows missing a value in a chosen column are left out.

Numeric columns to compare
Paste data to choose columns.

Method and citation

One column. Sort both groups. The Wasserstein-p distance on the line has a closed form: W_p^p = ∫₀¹ |F⁻¹(t) − G⁻¹(t)|^p dt, the average gap between the two quantile functions, and W1 is also the area between the two cumulative distributions (Peyré & Cuturi 2019). Both are computed exactly by walking the two step functions together. Splitting the integral by the sign of the gap gives the mass moved up and moved down. W2² splits exactly into (μ_B − μ_A)² + (σ_A − σ_B)² + 2σ_Aσ_B(1 − ρ), where ρ is the correlation of the two quantile functions; the three terms are reported as location, spread and shape. The p-value shuffles the group labels and recomputes W1 each time.

Several columns. The cost of moving a row of A to a row of B is their Euclidean distance (W1) or its square (W2), after the scaling you choose. Exact optimal transport is a linear programme; Sinkhorn's algorithm (Cuturi 2013) instead solves it with an entropy penalty of weight ε, which turns it into alternately rescaling the rows and columns of the matrix exp(−C/ε). Here ε is the blur times the mean cost, the iterations run on log-domain potentials with the kernel rebuilt around them so a small ε cannot underflow, and ε is lowered in stages from the largest cost. The answer is then certified: Altschuler, Weed & Rigollet's (2017) rounding makes the plan exactly feasible, so its cost is an upper bound on the exact distance, and two c-transforms of Sinkhorn's dual potential give a feasible dual solution, whose value is a lower bound (Peyré & Cuturi 2019). The p-value for several columns is the energy distance permutation test (Székely & Rizzo 2013). The share of movement per column is each column's part of the plan's squared displacement.

Verified by tests in the source against POT 0.9.7 (Python Optimal Transport) and SciPy 1.17.1: W1 and W2 on the line match scipy.stats.wasserstein_distance and ot.wasserstein_1d to 1e-12, with and without weights; the Sinkhorn plan matches ot.sinkhorn entry by entry to 1e-10; and the certified range always contains the exact cost from ot.emd2's network simplex, including on this page's example (exact 0.8747 °C for W1 with no scaling; the default blur gives 0.843 to 0.891). The energy statistic matches SciPy's energy distance.

BibTeX

@inproceedings{cuturi2013sinkhorn,
  author    = {Cuturi, Marco},
  title     = {Sinkhorn Distances: Lightspeed Computation of Optimal Transport},
  booktitle = {Advances in Neural Information Processing Systems 26},
  pages     = {2292--2300}, year = {2013}
}
@inproceedings{altschuler2017near,
  author    = {Altschuler, Jason and Weed, Jonathan and Rigollet, Philippe},
  title     = {Near-linear time approximation algorithms for optimal transport via {S}inkhorn iteration},
  booktitle = {Advances in Neural Information Processing Systems 30},
  pages     = {1964--1974}, year = {2017}
}
@article{peyre2019computational,
  author  = {Peyr{\'e}, Gabriel and Cuturi, Marco},
  title   = {Computational Optimal Transport},
  journal = {Foundations and Trends in Machine Learning},
  volume  = {11}, number = {5-6}, pages = {355--607}, year = {2019},
  doi     = {10.1561/2200000073}
}
@article{szekely2013energy,
  author  = {Sz{\'e}kely, G{\'a}bor J. and Rizzo, Maria L.},
  title   = {Energy statistics: A class of statistics based on distances},
  journal = {Journal of Statistical Planning and Inference},
  volume  = {143}, number = {8}, pages = {1249--1272}, year = {2013},
  doi     = {10.1016/j.jspi.2013.03.018}
}

Limits

Questions

What is the Wasserstein distance?

It is the least work needed to turn one distribution into the other, where work is the amount of mass moved times how far it moves. Pile up the values of one group as earth and dig them into the shape of the other group's pile: the cheapest way to do it costs W1, which is why it is also called the earth mover's distance. It is measured in the data's own units.

How do I read W1 for one column?

As an average distance moved, in the column's units. W1 = 0.79 degrees means that, matching the coldest night of one period with the coldest of the other, the second coldest with the second coldest and so on, the nights are 0.79 degrees apart on average. It is never smaller than the difference in means, and it equals it only when every quantile moved the same way.

What do moved up and moved down mean?

They split W1 by direction. Moved up is the part of the work done raising values, moved down the part lowering them. Their sum is W1 and their difference is the change in the mean. A mean shift of zero with a large W1 means the distribution changed shape, for example spreading out, without moving on average.

Why is the distance across several columns a range?

Because the exact problem is solved approximately and then checked. Sinkhorn's algorithm solves a slightly blurred version of optimal transport quickly. The tool turns its answer into a real transport plan, whose cost is an upper bound, and into a dual certificate, whose value is a lower bound. The exact distance is guaranteed to lie between the two. A smaller blur narrows the range and takes longer.

Should I scale my columns before comparing several at once?

Yes when the columns are in different units, such as kilograms and dollars, or the column with the biggest numbers decides everything. The default divides each column by its pooled standard deviation. When every column is in the same unit, such as two temperatures, choose no scaling so the distance stays in that unit.

Does a large distance mean the groups really differ?

Not by itself. Two samples from the same population are never identical, so the tool also shuffles the group labels hundreds of times and counts how often chance alone gives a distance as large. That share is the permutation p-value. A small p says the difference is more than chance; the distance says how big it is.

Is my data uploaded anywhere?

No. The file is read and compared by JavaScript in this browser tab. There are no accounts, cookies or analytics vendors.

Example data: daily maximum and minimum temperature at New York Central Park for every July day of 1951-1980 and of 1991-2020, from NOAA's Global Historical Climatology Network - Daily (Menne et al. 2012, doi:10.7289/V5D21VHZ), station USW00094728, a US Government work in the public domain, retrieved 2026-11-14. The station records whole degrees Fahrenheit, so the Celsius values move in steps of about 0.6 °C. July days are correlated with their neighbours, so read the example's p-values as rough.