Comparing means alone can miss how two samples spread. One sample may cluster near zero while another sits nearer the extremes, yet both can share the same mean and median. The two-sample Cramér–von Mises test (CvM below) asks a different question: do two independent samples come from the same distribution? It accumulates differences between the two empirical cumulative distribution functions at many locations, rather than comparing a single center.[1]
The null hypothesis is that the two independent samples come from the same unspecified continuous distribution, F=G. No normal mean or variance need be stated in advance, and the target is not “equal means” or “equal medians.” Rejecting the null means there is evidence that the population distributions differ; the statistic itself does not say whether the difference is in location, scale, or shape, and it alone cannot support a causal reading.[1]
Starting from two empirical distribution curves
At any value t, the empirical CDF Fₙ(t) is the share of observations in sample X that are at most t; Gₘ(t) is defined the same way for sample Y. Plotting the two step curves together, the vertical distance Fₙ(t)−Gₘ(t) at each location describes the difference in cumulative proportions up to that point. CvM squares these differences and accumulates them: positive and negative departures do not cancel, and sustained differences at many places all enter the statistic.
Let the sample sizes be n and m, N=n+m, and the pooled empirical distribution H_N=(nFₙ+mGₘ)/N. When the pooled observations have no ties, the statistic can be written
where zₖ are the pooled observations ordered from smallest to largest.
The accumulation is weighted by the pooled empirical distribution: without ties, each pooled observation receives equal weight. It is not an integral along the raw numeric axis by distance, so a long empty gap between two observations does not get extra weight from the gap length; the sample-size scaling above is also part of the statistic. By contrast, the two-sample Kolmogorov–Smirnov test focuses on the largest vertical distance between the two empirical curves. The two statistics measure discrepancy differently, so their numeric values cannot be compared directly to decide which result is “more significant.”
Same means, different empirical distributions
Consider a constructed calculation: X=[−1.5, −0.5, 0.5, 1.5], Y=[−4, −2, 2, 4]. Each group has four numbers; both means and both medians are 0, and the pool has no ties. But Y is more dispersed: at −2, for example, Y's cumulative share is 2/4 while X's is still 0; at 1.5, X's cumulative share is 1 while Y's is 1/2. Departures of the two empirical distributions at different locations therefore enter the same statistic.

Figure: both constructed arrays have mean and median 0. The display follows the pooled-rank formula and the no-tie empirical squared-difference calculation, checks the exact p-value over 70 label assignments, and contrasts a tied case under conditional permutation versus continuous-null calibration. Algorithmic illustration.
Merging and sorting the eight numbers and evaluating the empirical-distribution difference at each observation yields −1/4, −1/2, −1/4, 0, 1/4, 1/2, 1/4, 0. Squaring and summing gives 3/4; with n=m=4 the scale factor nm/N²=1/4, so T=3/16=0.1875. That number summarizes discrepancy across those locations but does not keep the sign of each local difference; to see where the samples differ, return to the curves.
The same statistic can be computed from ranks: sort within X and within Y, let Rᵢ and Sⱼ be the pooled ranks of those observations, and let i and j be their within-group indices. Set U=n∑(Rᵢ−i)²+m∑(Sⱼ−j)²; then T=U/[nm(n+m)]−(4nm−1)/[6(n+m)]. For this example the rank formula also yields 0.1875. The finite-sample correction is part of the formula and must not be dropped.[1]
Is 0.1875 large enough to oppose the equal-distribution null? Under a continuous equal-distribution null, keep the eight ordered positions fixed and assign four of them to X; there are C(8,4)=70 equally weighted labelings. Enumerating them here, 30 yield a T at least as large as the observed value, so the exact upper-tail p-value is 30/70=3/7, about 0.429, matching SciPy's exact result.
If the significance level was set to 0.05 in advance, 0.429 exceeds 0.05, so the equal-distribution null is not rejected. The figure's constructed arrays do have different empirical distributions, but this test result is not enough to assert that the two population distributions differ; failure to reject is also not proof that the populations are equal or equivalent. With only four observations per group, the conclusion should be read together with the sample sizes and the curves.
When there are ties, check how the p-value is calibrated
When identical values appear, SciPy computes the statistic with average ranks. Its exact method uses the exact rank distribution under a continuous equal-distribution null; that is not the same as a conditional permutation p-value that respects the observed tie pattern. SciPy's documentation notes that when the underlying distribution is discontinuous the p-value tends to be conservative, but that is not a guarantee about every concrete data pattern.[1]
For example, take X=[0, 0, 0, 1], Y=[0, 1, 1, 1]. The average-rank statistic is T=0.25. SciPy's continuous-null exact p-value is about 0.257; keeping each of the eight observations' indices and enumerating all 70 four-vs-four labelings under an equal-distribution null yields a conditional permutation p-value of about 0.486 for this tie pattern. The two numbers differ, and in this example the former is smaller; a single case cannot settle how either calibration behaves across all discrete data.
In practice, draw the two empirical curves first, then report the independent sampling units, group sizes, tie pattern, T, the p-value and its calibration method, and any scientifically meaningful quantile, location, or scale differences. T and the p-value answer the equal-distribution test; they are not directly interpretable effect sizes and do not guarantee extrapolation to other populations.
References
- [1] SciPy Community. “scipy.stats.cramervonmises_2samp.” SciPy Manual.