cvmNormalityTest

Performs a Cramer-von Mises test for normality.

Synopsis

cvmNormalityTest (x)

Required Arguments

float x[] (Input)Vector of length nObs containing the observations.

Return Value

The p‑value for the Cramer-von Mises test of normality.

Optional Arguments

stat (Output)
The Cramer-von Mises statistic.

nMissing (Output)The number of missing observations.

Description

Given a data sample \(\{X_i,i=1 .. n\}\), where n = nObs and \(X_i\) = x[i-1], function cvmNormalityTest computes the Cramer-von Mises (CvM) normality statistic W = cvmstat and the corresponding Return Value (p-value) P = P == {probability that a normally distributed n element sample would have a CvM statistic > W}. If P is sufficiently small (e.g. \(P<.05\)), then the CvM test indicates that the null hypothesis that the data sample is normally-distributed should be rejected. W is calculated:

\[W = \frac{1}{12n} + \sum_{i=1}^{n} \left[\phi\left(Y_i\right) - \frac{2i-1}{2n}\right]^2\]

Where \(\phi\left( Y_i \right)\) is the cumulative distribution function of standard normal N(0,1) distribution, \(Y_i=\left( X_i-\overline{X} \right)/s\), and \(\overline{X}\) and s are the sample mean and standard deviation respectively. P is calculated by first transforming W to an “n-adjusted” statistic W:

\[W* = W\left(1.0 + \frac{0.5}{n}\right)\]

and then calculating P in terms of W using a parabolic approximation taken from Table 4.9 in Stephens (1986).

Example

This example is taken from Conover (1980, pages 364 and 195). The data consists of 50 two digit numbers taken from a telephone book. The CvM test fails to reject the null hypothesis of normality at the 0.05 level of significance.

from __future__ import print_function
from numpy import *
from pyimsl.stat.cvmNormalityTest import cvmNormalityTest

x = [23.0, 36.0, 54.0, 61.0, 73.0, 23.0, 37.0, 54.0, 61.0, 73.0,
     24.0, 40.0, 56.0, 62.0, 74.0, 27.0, 42.0, 57.0, 63.0, 75.0,
     29.0, 43.0, 57.0, 64.0, 77.0, 31.0, 43.0, 58.0, 65.0, 81.0,
     32.0, 44.0, 58.0, 66.0, 87.0, 33.0, 45.0, 58.0, 68.0, 89.0,
     33.0, 48.0, 58.0, 68.0, 93.0, 35.0, 48.0, 59.0, 70.0, 97.0]
nmiss = []
adstat = []

p_value = cvmNormalityTest(x, stat=adstat, nMissing=nmiss)

print("Cramer-von Mises statistic = %11.4f" % adstat[0])
print("p-value = %11.4f" % p_value)
print("# missing values = %4d" % nmiss[0])

Output

Cramer-von Mises statistic =      0.0520
p-value =      0.4747
# missing values =    0

Informational Errors

IMSLS_PVAL_UNDERFLOW The p‑value has fallen below the minimum value of # for which its calculation has any accuracy; ZERO is returned.

Fatal Errors

IMSLS_TOO_MANY_MISSING After removing the missing observations only 2 observations remain. The test cannot proceed.