Your data
Rows missing a value in a chosen column are left out.
Result
One column at a time (exact)
| Column | W1 | Mean shift | Moved up | Moved down | W2 | W2² is mostly | p (W1) |
|---|
All distances in the column's units, B minus A. Moved up + moved down = W1; moved up − moved down = the mean shift. W2² splits exactly into location (mean shift²), spread ((SD_A − SD_B)²) and shape (the rest). p: share of label shuffles giving a W1 at least this large.
Where the difference is
A B. The two cumulative distributions; the shaded area between them is W1.
| Quantile | A | B | Shift |
|---|
All the columns at once
Each line runs from a row of A to the average place the optimal plan sends its mass in B (up to 400 lines drawn). Rows with identical values overlap.
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
- Distance is not significance, and significance is not cause. A distance says how big the difference is; the p-value says whether chance could produce it; neither says why the groups differ.
- Rows are treated as independent. The shuffles assume any row could have been in either group. Days in a row of weather, repeated visits by one customer or batches from one machine are correlated, so the p-values are too small for such data.
- Units decide the several-column answer. Without scaling, the column with the largest numbers dominates the cost. With scaling, the distance is in pooled standard deviations.
- Size. The several-column problem stores a cost matrix of A rows × B rows, so above 1,200 rows per group it uses a seeded random subsample; the one-column results always use every row.
- Range, not a point. The several-column value shown is the cost of a real transport plan, the upper end of the range; the exact optimum lies in the range, not necessarily at its middle.
- Not modelled: weights per row, unbalanced transport (groups of different total mass), the debiased Sinkhorn divergence, more than two groups at once, and a time order (for one series over time, use the changepoint detector).
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.