Skip to content

ADescribe · Guide test 120

Cramér–von Mises one sample test

Tests a specified continuous distribution using integrated squared cumulative discrepancy.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Fit a distribution (goodness of fit), choose Parameters = Specified in advance.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Cramér–von Mises one sample test

40
0.30
1.00
0.050

Your data

Drag a point or use ↑/↓ to change it
D = 0.227F₀ = N(0, 1)

If H₀ were true

W² = 0.58
  1. The reference: how W² varies across samples when H₀ is true, W² for n = 40 (Csörgő & Faraway).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .025).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

W2=112n+∑i(F0(x(i))−2i−12n)2W^2=\dfrac{1}{12n}+\sum_i\left(F_0(x_{(i)})-\dfrac{2i-1}{2n}\right)^2

With your numbers

W2=0.58,n=40W^2 = 0.58,\qquad n = 40
F0F_0
the hypothesized CDF, fully specified
(2i−1)/(2n)(2i-1)/(2n)
mid-points of the ECDF steps

The verdict

W² = 0.58, p = .025

p ≤ α = .050: reject H₀

The squared distance between the ECDF and F0, integrated with uniform weight. The p uses the exact finite-n correction of Csörgő and Faraway.

Statistic
0.578
p-value
0.0249
Cramér–von Mises one sample test on Sample: n = 40: W² = 0.58, p = .025. The p-value is below α = .050, so the data are hard to reconcile with H0.

Cramér–von Mises one sample test on Sample: n = 40: W² = 0.58, p = .025. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: the fully specified continuous CDF F0 is correct.

Assumptions

Independent observations; fitted parameters require different null calibration.

Formula

W2=n∫(Fn−F0)2dF0=112n+∑i[F0(x(i))−2i−12n]2W^2=n\int(F_n-F_0)^2dF_0=\frac1{12n}+\sum_i\left[F_0(x_{(i)})-\frac{2i-1}{2n}\right]^2

Parameters and notation

n sample size; F0 fixed null CDF.

Structure of the method

Apply the fully specified CDF to ordered observations and compare transformed probabilities with evenly spaced midpoint positions. The sum-of-squares form is an efficient evaluation of integrated empirical-CDF deviation under the simple continuous null.

Estimated and nuisance parameters

The empirical CDF is estimated, but every parameter of the tested theoretical CDF must be fixed for the standard reference. Estimated location or scale turns the problem into a composite-null version.

Settings and design choices

Specify the null family and parameter values, treatment of missingness, significance level and numerical evaluation. There is no fitted bandwidth or architecture. If simulation is used, its count controls Monte Carlo precision only.

Fitting and adaptation

Use the simple-null reference when parameters are externally known. When parameters come from the same sample, simulate under the fitted null and repeat the fit in every replicate, or use a documented family-specific correction. The preserved normal example deliberately fixes mean zero and variance one; it is distinct from testing some unspecified normal distribution.

Sensitivity and robustness

Tied or discrete observations change calibration and need a corresponding reference. CvM spreads weight across the probability range, so power differs from a maximum-deviation test. Residuals, truncated data and dependent sequences require their own sampling model; a large p-value is not a certificate of practical fit.

How to use and calibrate

Use the known-distribution Cramér–von Mises reference or refitted simulation for a composite null.

Example application

Evaluate overall continuous distribution fit.

Interpretation and pitfalls

Watch out

The normality-specific variant in entry 110 shares the statistic but not its null distribution.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Fully specified N(0,1) null. Estimating parameters requires a different reference distribution.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x=rng.normal(size=60)
print(stats.cramervonmises(x,"norm",args=(0,1)))
Output
CramerVonMisesResult(statistic=0.2187719533593024, pvalue=0.23412300795258123)
R

Validated — Executed successfully in the validation environment · needs goftest

set.seed(2026)
x <- rnorm(60)
print(goftest::cvm.test(x,null="pnorm",mean=0,sd=1,estimated=FALSE))
Output
	Cramer-von Mises test of goodness-of-fit
	Null hypothesis: Normal distribution
	with parameters mean = 0, sd = 1
	Parameters assumed to be fixed

data:  x
omega2 = 0.129, p-value = 0.4615

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 120, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT120.