*! version 1.0.0 23dec2025

Title

cvmtest -- Two-sample Cramer-von Mises equality-of-distributions test

Syntax

cvmtest
varname [if] [in] , "by(varlist:groupvar)"
[,
reps(#)
seed(#)
power(#)]

groupvar must take on
two distinct values. The distribution of varname for the first value of
groupvar is compared with that of the second value.

* "by(varlist:groupvar)" specify a binary variable that identifies the two groups

reps(#) perform # Monte Carlo permutations; default is reps(1000)

seed(#) set random-number seed to #

power(#) specify the exponent for the CVM statistic; default is power(2)

* Required

Description

cvmtest performs a two-sample Cramer-von Mises (CVM) permutation test
to assess whether two samples come from the same distribution. The CVM statistic
measures the integrated squared difference between the empirical cumulative
distribution functions (ECDFs) of the two samples. The permutation test provides
an exact p-value by comparing the observed statistic to its distribution under
random reassignment of group labels.

Options

"by(varlist:groupvar)" is required. It specifies a binary variable
that identifies the two groups.

reps(#) specifies the number of random permutations for the test;
the default is reps(1000).

seed(#) sets the random-number seed for reproducible results.

power(#) specifies the exponent for the CVM statistic calculation;
the default is power(2), which gives the standard Cramer-von
Mises statistic with quadratic weighting. Other values modify sensitivity:
power(1) linear weighting (less sensitive to large differences),
power(3+) which is more sensitive to large distributional differences.

Examples

Set-up

. clear

. set obs 20

. gen group = cond(_n < 11,1,2)

. gen x = runiform() in 1/10

. replace x = runiform() * 1.30 if group==2

cvmtest using defaults

. cvmtest x, by(group)

cvmtest with specific seed and more permutations

. cvmtest x, by(group) reps(2000) seed(12345)

change power to linear weighting

. cvmtest x, by(group) reps(2000) seed(12345) power(1)

Stored results

cvmtest stores the following in r():

Scalars

r(stat) observed CVM statistic

r(p) permutation p-value

r(reps) number of permutations performed

r(power) power parameter specified

Macros

r(group1) name of group 1

r(group2) name of group 2

References

Cramer, H. 1928.
On the composition of elementary errors.
Scandinavian Actuarial Journal
11: 13-74.

von Mises, R. 1931.
Wahrscheinlichkeitsrechnung und ihre Anwendung in der Statistik und theoretischen Physik.
Leipzig: Deuticke.

Dwass, M. 1957.
Modified randomization tests for nonparametric hypotheses.
Annals of Mathematical Statistics
28: 181-187.

Citation of cvmtest

cvmtest is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden A. (2025). CVMTEST: Stata module to perform a two-sample Cramer-von Mises equality-of-distributions test

Author

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org

Also see

ksmirnov, ranksum, permute, adtest (if installed), escftest (if installed), distcomp (if installed)