Cramér–von Mises CDF Gap
Compare integrated CDF error with a fully specified null instead of a single largest gap.
By Riano · Published · Updated · Report a correction
Cramér–von Mises CDF Gap
The Cramér–von Mises (CvM) statistic evaluates the goodness of fit of a cumulative distribution function (CDF) compared to an empirical CDF. Unlike the Kolmogorov-Smirnov statistic which looks at the single maximum difference, the CvM statistic integrates the squared difference over the entire distribution.
Worked Example
Consider an even sample distribution n = 4 with points at 1/8, 3/8, 5/8, 7/8 and a uniform null CDF F(x) = x.
- First, evaluate the null CDF at each sorted observation:F(1/8) = 1/8, F(3/8) = 3/8, F(5/8) = 5/8, F(7/8) = 7/8
- For each point i from 1 to 4, calculate the term (F(xi) - (2i - 1)/(2n))2.
- Notice that for our even points, (2i - 1)/8 exactly matches F(xi).(1/8 - 1/8)2 = 0(3/8 - 3/8)2 = 0This pattern continues for all points, so the sum of these squared differences is 0.
- Calculate the statistic T using the formula T = 1/(12n) + Σ:T = 1/(12 × 4) + 0 = 1/48 ≈ 0.020833333333333332
- The integrated squared gap is T / n:1/48 / 4 = 1/192 ≈ 0.005208333333333333
Interactive Experiment
You can interactively compare different distributions by exploring the Cramér–von Mises CDF Gap module.
- Select the Sample "Even" and the Null CDF "Uniform". Notice the statistic is exactly 0.020833333333333332 as derived above.
- Change the Sample to "Clustered". The ECDF visually diverges more significantly from the uniform diagonal, and the statistic increases to 0.5233333333333333, reflecting higher discrepancy.
- Change the Null CDF to "Quadratic" while keeping the "Even" sample. The points no longer align perfectly with the curve F(x) = x2, producing a statistic of 0.15462239583333334.
Assumptions and Limitations
The exact Cramér–von Mises statistic T formula requires a fully specified continuous null distribution without parameters estimated from the data itself.
When tied values or identical endpoints exist (e.g. the "Ties" or "Endpoints" samples), you can still calculate the numerical discrepancy T. However, typical tables of critical values and p-values assume independent, identically distributed continuous data. Violating these exact-null probability assumptions means these descriptive values cannot be directly translated into a standard hypothesis test conclusion without adjustment. If the sample is entirely empty, the statistic is undefined.
References
For more information on the implementation and usage of the Cramér-von Mises statistic in Python, see the official SciPy documentation linked below.
- SciPy Statistical Functions: cramervonmises - Documentation detailing the calculation of the Cramér-von Mises statistic for goodness of fit.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Cramér–von Mises CDF Gap module.
Try Cramér–von Mises CDF Gap on Riano →