# Cramér-von-Mises criterion

In statistics the Cramér-von-Mises criterion for judging the goodness of fit of a probability distribution ${\displaystyle F^{*}}$ compared to a given distribution ${\displaystyle F}$ is given by

${\displaystyle W^{2}=\int _{-\infty }^{\infty }[F(x)-F^{*}(x)]^{2}dF(x)}$

In one-sample applications ${\displaystyle F}$ is the theoretical distribution and ${\displaystyle F^{*}}$ is the empirically observed distribution. Alternatively the two distributions can both be empirically estimated ones; this is called the two-sample case.

The criterion is named after Harald Cramér and Richard Edler von Mises who first proposed it in 1928-1930. The generalization to two samples is due to Anderson (1962).

The Cramér-von-Mises test is an alternative to the Kolmogorov-Smirnov test. It is thought that the CvM test is more powerful than the KS test, but this has not been shown theoretically.

## Cramér-von-Mises test (one sample)

Let ${\displaystyle x_{1},x_{2},\cdots ,x_{n}}$ be the observed values, in increasing order. Then it is possible to show that

${\displaystyle T=nW^{2}={\frac {1}{12n}}+\sum _{i=1}^{n}\left[{\frac {2i-1}{2n}}-F(x_{i})\right]^{2}.}$

If this value is larger than the tabulated value we can reject the hypothesis that the data come from the distribution ${\displaystyle F(.)}$.

## Cramér-von-Mises test (two samples)

Let ${\displaystyle x_{1},x_{2},\cdots ,x_{n}}$ and ${\displaystyle y_{1},y_{2},\cdots ,y_{m}}$ be the observed values in the first and second sample respectively, in increasing order. Let ${\displaystyle r_{1},r_{2},\cdots ,r_{n}}$ be the ranks of the x's in the combined sample, and let ${\displaystyle s_{1},s_{2},\cdots ,s_{m}}$ be the ranks of the y's in the combined sample. It can be shown that

${\displaystyle T=nW^{2}={\frac {U}{nm(n+m)}}-{\frac {4mn-1}{6(m+n)}}}$

where U is defined as

${\displaystyle U=n\sum _{i=1}^{n}(r_{i}-i)+m\sum _{j=1}^{m}(s_{j}-j)}$

If the value of T is larger than the tabulated value we can reject the hypothesis that the two samples come from the same distribution. (Some books give critical values for U, which is more convenient, as it avoids the need to compute T via the expression above. The conclusion will be the same).

## References

Anderson: 'On the Distribution of the Two-Sample Cramer-von Mises Criterion', Annals Math. Stat. 33, #3 (1962), p1148-1159. [1]

Xiao, Gordon, Yakovlev: 'A C++ program for the Cramér-von-Mises two sample test', Journal of Statistical Software, 17 #8, January 2007 [2]