Performs the Cramer-von Mises test for normality to assess whether a given
sample comes from a normal distribution. This implementation follows the
methodology from the nortest R package.
Value
A list with class "htest" containing the following components:
statistic- The Cramer-von Mises test statistic (W)p.value- The p-value for the testmethod- The name of the method ("Cramer-von Mises normality test")data.name- The name of the data used in the test
Details
The Cramer-von Mises test is a statistical test of whether a given sample of data is drawn from a normal distribution. It is an empirical distribution function (EDF) test that compares the empirical distribution function of the sample with the cumulative distribution function of the normal distribution.
This implementation requires a minimum sample size of 8 observations. The test statistic is calculated as: $$W = \frac{1}{12n} + \sum_{i=1}^n \left(p_i - \frac{2i-1}{2n}\right)^2$$ where \(p_i = \Phi((x_i - \mu)/\sigma)\) and \(\Phi\) is the cumulative distribution function of the standard normal distribution.
The p-value is calculated using different approximation formulas depending on the value of the adjusted test statistic WW = W × (1 + 0.5/n):
For WW < 0.0275: \(p = 1 - \exp(-13.953 + 775.5 \times WW - 12542.61 \times WW^2)\)
For 0.0275 ≤ WW < 0.051: \(p = 1 - \exp(-5.903 + 179.546 \times WW - 1515.29 \times WW^2)\)
For 0.051 ≤ WW < 0.092: \(p = \exp(0.886 - 31.62 \times WW + 10.897 \times WW^2)\)
For 0.092 ≤ WW < 1.1: \(p = \exp(1.111 - 34.242 \times WW + 12.832 \times WW^2)\)
For WW ≥ 1.1: \(p = 7.37 \times 10^{-10}\) with a warning
References
This implementation is based on the nortest package:
Gross, J. and Ligges, U. (2015). nortest: Tests for Normality. R package version 1.0-4. https://CRAN.R-project.org/package=nortest
The original test is described in:
Cramer, H. (1928). On the Composition of Elementary Errors. Scandinavian Actuarial Journal, 1928(1), 13-74.
Von Mises, R. (1931). Wahrscheinlichkeitsrechnung und ihre Anwendung in der Statistik und theoretischen Physik. Leipzig: Deuticke.
Stephens, M.A. (1970). Use of the Kolmogorov-Smirnov, Cramer-von Mises and Related Statistics Without Extensive Tables. Journal of the Royal Statistical Society. Series B (Methodological), 32(1), 115-122.
See also
cvm.test for the original implementation in the nortest package.
ad.test for the Anderson-Darling normality test.
shapiro.test for the Shapiro-Wilk normality test.
ks.test for the Kolmogorov-Smirnov test.
Other normality_test:
ad.test(),
dagostino.test(),
jb.test.modified(),
pearson.test(),
sf.test()
Examples
if (FALSE) { # \dontrun{
# Test a sample from normal distribution
set.seed(123)
normal_data <- rnorm(100)
cvm.test(normal_data)
# Test a sample from non-normal distribution
exponential_data <- rexp(50)
cvm.test(exponential_data)
# Test with real data
if (require("datasets")) {
cvm.test(iris$Sepal.Length)
}
} # }