CramerVonMisesTest[data]
tests whether data is normally distributed using the Cramér–von Mises test.
CramerVonMisesTest[data,dist]
tests whether data is distributed according to dist using the Cramér–von Mises test.
CramerVonMisesTest[data,dist,"property"]
returns the value of "property".
CramerVonMisesTest
CramerVonMisesTest[data]
tests whether data is normally distributed using the Cramér–von Mises test.
CramerVonMisesTest[data,dist]
tests whether data is distributed according to dist using the Cramér–von Mises test.
CramerVonMisesTest[data,dist,"property"]
returns the value of "property".
Details and Options
- CramerVonMisesTest performs the Cramér–von Mises goodness-of-fit test with null hypothesis
that data was drawn from a population with distribution dist and alternative hypothesis
that it was not. - By default, a probability value or
-value is returned. - A small
-value suggests that it is unlikely that the data came from dist. - The dist can be any symbolic distribution with numeric and symbolic parameters or a dataset.
- The data can be univariate {x1,x2,…} or multivariate {{x1,y1,…},{x2,y2,…},…}.
- The Cramér–von Mises test assumes that the data came from a continuous distribution.
- The Cramér–von Mises test effectively uses a test statistic based on the expectation value of
where
is the empirical CDF of data and
is the CDF of dist. - For univariate data, the test statistic is given by
. - For multivariate tests, the sum of the univariate marginal
-values is used and is assumed to follow a UniformSumDistribution under
. - CramerVonMisesTest[data,dist,"HypothesisTestData"] returns a HypothesisTestData object htd that can be used to extract additional test results and properties using the form htd["property"].
- CramerVonMisesTest[data,dist,"property"] can be used to directly give the value of "property".
- Properties related to the reporting of test results include:
-
"PValue"
-value"PValueTable" formatted version of "PValue" "ShortTestConclusion" a short description of the conclusion of a test "TestConclusion" a description of the conclusion of a test "TestData" test statistic and
-value"TestDataTable" formatted version of "TestData" "TestStatistic" test statistic "TestStatisticTable" formatted "TestStatistic" - The following properties are independent of which test is being performed.
- Properties related to the data distribution include:
-
"FittedDistribution" fitted distribution of data "FittedDistributionParameters" distribution parameters of data - The following options can be given:
-
Method Automatic the method to use for computing
-valuesSignificanceLevel 0.05 cutoff for diagnostics and reporting - For a test for goodness of fit, a cutoff
is chosen such that
is rejected only if
. The value of
used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the SignificanceLevel option. By default,
is set to 0.05. - With the setting Method->"MonteCarlo",
datasets of the same length as the input si are generated under
using the fitted distribution. The empirical distribution from CramerVonMisesTest[si,dist,"TestStatistic"] is then used to estimate the
-value.
Examples
open all close allBasic Examples (3)
Perform a Cramér–von Mises test for normality:
data = RandomVariate[NormalDistribution[], 10^4];CramerVonMisesTest[data]Confirm the result using QuantilePlot:
QuantilePlot[data]Test the fit of some data to a particular distribution:
data = RandomVariate[LaplaceDistribution[1, 2], 10^3];Show[SmoothHistogram[data, PlotStyle -> ColorData[97, 2]], Plot[PDF[LaplaceDistribution[1, 2], x], {x, -10, 10}, PlotStyle -> Dashed]]CramerVonMisesTest[data, LaplaceDistribution[1, 2]]Compare the distributions of two datasets:
data1 = RandomVariate[NormalDistribution[], 100];data2 = RandomVariate[NormalDistribution[], 150];SmoothHistogram[{data1, data2}]CramerVonMisesTest[data1, data2]Scope (9)
Testing (6)
Perform a Cramér–von Mises test for normality:
data1 = RandomVariate[NormalDistribution[], 10^4];
data2 = RandomVariate[StudentTDistribution[3], 10^4];The
-value for the normal data is large compared to the
-value for the non-normal data:
CramerVonMisesTest[data1]CramerVonMisesTest[data2]Test the goodness of fit to a particular distribution:
data1 = RandomVariate[NormalDistribution[], 10^3];
data2 = RandomVariate[CauchyDistribution[0, 1], 10^3];CramerVonMisesTest[data1, CauchyDistribution[0, 1]]CramerVonMisesTest[data2, CauchyDistribution[0, 1]]Compare the distributions of two datasets:
data1 = RandomVariate[NormalDistribution[], 10^3];
data2 = RandomVariate[NormalDistribution[], 10^3];CramerVonMisesTest[data1, data2]The two datasets do not have the same distribution:
data3 = RandomVariate[NormalDistribution[0, 1.25], 10^3];CramerVonMisesTest[data1, data3]Test for multivariate normality:
data1 = RandomVariate[BinormalDistribution[.5], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], {10^3, 2}];CramerVonMisesTest[data1]CramerVonMisesTest[data2]Test for goodness of fit to any multivariate distribution:
data1 = RandomVariate[BinormalDistribution[.5], 10^3];
data2 = RandomVariate[𝒹 = LaplaceDistribution[1, 2], {10^3, 2}];𝒟 = ProductDistribution[𝒹, 𝒹];CramerVonMisesTest[data1, 𝒟]CramerVonMisesTest[data2, 𝒟]Create a HypothesisTestData object for repeated property extraction:
data = RandomVariate[NormalDistribution[], 10];ℋ = CramerVonMisesTest[data, Automatic, "HypothesisTestData"]The properties available for extraction:
ℋ["Properties"]Reporting (3)
Tabulate the results of the Cramér–von Mises test:
data = RandomVariate[NormalDistribution[], 100];ℋ = CramerVonMisesTest[data, Automatic, "HypothesisTestData"];ℋ["TestDataTable"]ℋ["PValueTable"]ℋ["TestStatisticTable"]Retrieve the entries from a Cramér–von Mises test table for custom reporting:
data1 = RandomVariate[NormalDistribution[], 100];
data2 = RandomVariate[NormalDistribution[], 100];ℋ1 = CramerVonMisesTest[data1, Automatic, "TestData"]ℋ2 = CramerVonMisesTest[data2, Automatic, "TestData"]BarChart[{Labeled[ℋ1, "Set 1"], Labeled[ℋ2, "Set 2"]}, ChartLabels -> {"SuperscriptBox[ω, 2]", "p‐value"}]Report test conclusions using "ShortTestConclusion" and "TestConclusion":
data = BlockRandom[SeedRandom[1];RandomVariate[ParetoDistribution[1.05, 2], 100]];ℋ = CramerVonMisesTest[data, ParetoDistribution[1, 2], "HypothesisTestData"];ℋ["ShortTestConclusion"]ℋ["TestConclusion"]//TraditionalFormThe conclusion may differ at a different significance level:
ℋ = CramerVonMisesTest[data, ParetoDistribution[1, 2], "HypothesisTestData", SignificanceLevel -> .001];ℋ["ShortTestConclusion"]ℋ["TestConclusion"]//TraditionalFormOptions (3)
Method (3)
Use Monte Carlo-based methods or a computation formula:
data = RandomVariate[NormalDistribution[], 100];CramerVonMisesTest[data, NormalDistribution[], Method -> "MonteCarlo"]CramerVonMisesTest[data, NormalDistribution[], Method -> Automatic]Set the number of samples to use for Monte Carlo-based methods:
data = RandomVariate[NormalDistribution[], 100];pts = Table[{i, CramerVonMisesTest[data, NormalDistribution[], Method -> {"MonteCarlo", "MonteCarloSamples" -> i}]}, {i, Range[5, 100, 5]}];The Monte Carlo estimate converges to the true
-value with increasing samples:
pval = CramerVonMisesTest[data, NormalDistribution[]];Show[ListLinePlot[pts, PlotRange -> {0, 1}, FrameLabel -> {"Samples", "P-Value"}, Frame -> True, AxesOrigin -> {0, 0}], Graphics[{Dashed, Line[{{0, pval}, {100, pval}}]}]]Set the random seed used in Monte Carlo-based methods:
data = RandomVariate[NormalDistribution[], 100];pts = Table[{i, CramerVonMisesTest[data, NormalDistribution[], Method -> {"MonteCarlo", "RandomSeed" -> i, "MonteCarloSamples" -> 50}]}, {i, Range[1, 10]}];The seed affects the state of the generator and has some effect on the resulting
-value:
pval = CramerVonMisesTest[data, NormalDistribution[]];Show[ListLinePlot[pts, PlotRange -> {Min[pts[[All, 2]]], Max[pts[[All, 2]]]}, FrameLabel -> {"Seed", "P-Value"}, Frame -> True, AxesOrigin -> {0, 0}], Graphics[{Dashed, Line[{{0, pval}, {100, pval}}]}]]Applications (3)
A power curve for the Cramér–von Mises test:
data = Table[RandomVariate[UniformDistribution[{-4, 4}], {500, i}], {i, n = {7, 10, 15, 20, 25, 30, 50}}];ℋ = Table[CramerVonMisesTest[data[[i, j]], NormalDistribution[]], {i, Length[data]}, {j, Length[data[[i]]]}];pC = Interpolation[Transpose[{n, Table[Probability[x ≤ 0.05, xi], {i, ℋ}]}], InterpolationOrder -> 1];Visualize the approximate power curve:
Plot[pC[x], {x, 7, 50}, PlotRange -> {0, 1}, Ticks -> {n, Automatic}, AxesOrigin -> {0, 0}]Estimate the power of the Cramér–von Mises test when the underlying distribution is UniformDistribution[{-4, 4}], the test size is 0.05, and the sample size is 32:
pC[32.]Observations generated by a homogeneous Poisson process should exhibit complete spatial randomness, which implies that they were drawn from a uniform distribution. Determine if observations from the following images would be modeled well by a homogeneous Poisson process:
img1 = [image];img2 = [image];m = MorphologicalComponents[Binarize[#, {0, .7}]]& /@ {img1, img2};Find the centers of each point and rescale on
:
locs = ComponentMeasurements[#, "Centroid"][[All, 2]]& /@ m;s1 = MapThread[Rescale[#1, {0, #2}]&, {locs[[1]], ImageDimensions[img1]}];
s2 = MapThread[Rescale[#1, {0, #2}]&, {locs[[2]], ImageDimensions[img2]}];The points in the first image would be modeled well by a homogeneous Poisson process:
CramerVonMisesTest[s1, UniformDistribution[{{0, 1}, {0, 1}}], "TestDataTable"]A model for the second group should account for dependence:
CramerVonMisesTest[s2, UniformDistribution[{{0, 1}, {0, 1}}], "TestDataTable"]Find the parameters for distributions that minimize the Cramér–von Mises test statistic:
data = RandomVariate[NormalDistribution[], 100];f[μ_ ? NumericQ, σ_ ? NumericQ, dist_] := CramerVonMisesTest[data, dist[μ, σ], "TestStatistic"]par = FindMinimum[f[μ, σ, NormalDistribution], {{μ}, {σ}}]Compare the results to FindDistributionParameters:
estPar = FindDistributionParameters[data, NormalDistribution[μ, σ]]Show[Plot3D[f[μ, σ, NormalDistribution], {μ, -3, 3}, {σ, 0, 6}, PlotStyle -> Directive[Opacity[0.5]], PlotRange -> {{-2, 2}, {0, 3}, {-10, 35}}], Graphics3D[{Red, Tube[{{μ, σ, 40}, {μ, σ, -20}} /. par[[2]], .05]}],
Graphics3D[{Green, Tube[{{μ, σ, 40}, {μ, σ, -20}} /. estPar, .05]}], AspectRatio -> 1]Properties & Relations (8)
By default, univariate data is compared to NormalDistribution:
data = RandomVariate[NormalDistribution[2, 3], 10];ℋ = CramerVonMisesTest[data, Automatic, "HypothesisTestData"];ℋ["TestDataTable"]The parameters have been estimated from the data:
ℋ["FittedDistribution"]Multivariate data is compared to MultinormalDistribution by default:
data = RandomVariate[MultinormalDistribution[{1, 2, 3}, IdentityMatrix[3]], 1000];ℋ = CramerVonMisesTest[data, Automatic, "HypothesisTestData"];ℋ["TestDataTable"]ℋ["FittedDistribution"]//TraditionalFormThe parameters of the test distribution are estimated from the data if not specified:
data = RandomVariate[NormalDistribution[1, 2], 1000];CramerVonMisesTest[data, NormalDistribution[μ, σ], "FittedDistribution"]Specified parameters are not estimated:
CramerVonMisesTest[data, NormalDistribution[μ, 2], "FittedDistribution"]CramerVonMisesTest[data, NormalDistribution[1, 2], "FittedDistribution"]Maximum likelihood estimates are used for unspecified parameters of the test distribution:
data = RandomVariate[ExponentialDistribution[3], 10^3];ℋ = CramerVonMisesTest[data, ExponentialDistribution[λ], "FittedDistribution"]CramerVonMisesTest[data, ExponentialDistribution[λ]]If the parameters are unknown, CramerVonMisesTest applies a correction when possible:
data = RandomVariate[NormalDistribution[3, 4], 10^4];est = EstimatedDistribution[data, NormalDistribution[μ, σ]]The parameters are estimated but no correction is applied:
CramerVonMisesTest[data, est]ℋ = CramerVonMisesTest[data, NormalDistribution[μ, σ], "HypothesisTestData"];The fitted distribution is the same as before and the
-value is corrected:
ℋ["FittedDistribution"]ℋ["PValue"]Independent marginal densities are assumed in tests for multivariate goodness of fit:
data = RandomVariate[MultinormalDistribution[{0, 0}, {{0.118, 0.252}, {0.252, 0.665}}], 100];CramerVonMisesTest[data, MultinormalDistribution[{0, 0}, {{0.118, 0.252}, {0.252, 0.665}}], "TestStatistic"]The test statistic is identical when independence is assumed:
CramerVonMisesTest[data, MultinormalDistribution[{0, 0}, {{0.118, 0}, {0, 0.665}}], "TestStatistic"]The Cramér–von Mises statistic can be defined using NExpectation:
n = 10;
h0 = NormalDistribution[1, 2];
data = RandomVariate[h0, n];f[x_] := CDF[h0, x]
Overscript[f, ^ ][x_] := CDF[EmpiricalDistribution[data], x]n NExpectation[(Overscript[f, ^ ][t] - f[t])^2, th0]CramerVonMisesTest[data, h0, "TestStatistic"]The Cramér–von Mises test works with the values only when the input is a TimeSeries:
ts = TemporalData[TimeSeries, {{{1.224578634529677, 0.47929635789978015, 0.6572781300178168,
0.21496048742669355, 0.7299608014554928, -0.2495111111278263, -1.3286551762002712,
0.552725018274874, 0.19272112205837066, 1.1809144012420882, -1.1671 ... 40938613662046, 1.052394590214582, 0.9345044123980388, 0.38537803109557855,
-0.48660931166089394, -0.71203560340161}}, {{0, 100, 1}}, 1, {"Continuous", 1},
{"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];CramerVonMisesTest[ts]CramerVonMisesTest[ts["Values"]]Possible Issues (3)
The Cramér–von Mises test is not intended for discrete distributions:
data = RandomVariate[PoissonDistribution[30], 35];CramerVonMisesTest[data, PoissonDistribution[30]]The continuity correction typically does a good job of preserving the size of the test:
sim = RandomVariate[PoissonDistribution[30], {500, 35}];p = Quiet[CramerVonMisesTest[#, PoissonDistribution[30]]]& /@ sim;Show[ListLinePlot[Table[{α, Probability[pv ≤ α, pvp]}, {α, .01, 1, .01}]], Plot[x, {x, 0, 1}, PlotStyle -> Dashed]]This may not be the case in some situations:
sim = RandomVariate[DiscreteUniformDistribution[{1, 3}], {500, 35}];p = Quiet[CramerVonMisesTest[#, DiscreteUniformDistribution[{1, 3}]]]& /@ sim;Show[ListLinePlot[Table[{α, Probability[pv ≤ α, pvp]}, {α, .01, 1, .01}]], Plot[x, {x, 0, 1}, PlotStyle -> Dashed]]Use Monte Carlo methods or PearsonChiSquareTest in these cases:
CramerVonMisesTest[sim[[1]], DiscreteUniformDistribution[{1, 3}], Method -> "MonteCarlo"]PearsonChiSquareTest[sim[[1]], DiscreteUniformDistribution[{1, 3}]]The Cramér–von Mises test is not valid for some distributions when parameters have been estimated from the data:
data = RandomVariate[BetaDistribution[1, 2], 100];CramerVonMisesTest[data, BetaDistribution[1, b]]Provide parameter values if they are known:
CramerVonMisesTest[data, BetaDistribution[1, 2]]Alternatively, use Monte Carlo methods to approximate the
-value:
CramerVonMisesTest[data, BetaDistribution[1, b], Method -> "MonteCarlo"]The Cramér–von Mises test must have sample sizes of at least 7 for valid
-values:
data = RandomVariate[NormalDistribution[], 5];DistributionFitTest[data, Automatic, "CramerVonMises"]Use Monte Carlo methods to arrive at a valid
-value:
DistributionFitTest[data, Automatic, "CramerVonMises", Method -> "MonteCarlo"]Neat Examples (1)
Compute the statistic when the null hypothesis
is true:
data = RandomVariate[NormalDistribution[], {2500, 100}];T1 = CramerVonMisesTest[#, NormalDistribution[], "TestStatistic"]& /@ data;The test statistic given a particular alternative:
T2 = CramerVonMisesTest[#, NormalDistribution[.5, 2], "TestStatistic"]& /@ data;Compare the distributions of the test statistics:
SmoothHistogram[{T1, T2}, Filling -> Axis, PlotLegends -> {"SubscriptBox[H, 0] is True", "SubscriptBox[H, 0] is False"}]Related Guides
History
Text
Wolfram Research (2010), CramerVonMisesTest, Wolfram Language function, https://reference.wolfram.com/language/ref/CramerVonMisesTest.html.
CMS
Wolfram Language. 2010. "CramerVonMisesTest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CramerVonMisesTest.html.
APA
Wolfram Language. (2010). CramerVonMisesTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CramerVonMisesTest.html
BibTeX
@misc{reference.wolfram_2026_cramervonmisestest, author="Wolfram Research", title="{CramerVonMisesTest}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/CramerVonMisesTest.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_cramervonmisestest, organization={Wolfram Research}, title={CramerVonMisesTest}, year={2010}, url={https://reference.wolfram.com/language/ref/CramerVonMisesTest.html}, note=[Accessed: 13-June-2026]}