0

I am looking for a one-sample Cramer-Von Mises test for a normal distribution with unknown parameters in python.

I found some discussion here https://github.com/chrisb83/scipy/commit/9274d22fc1ca7ce40596b01322be84c81352899d but this does not seem to be released?

There is also this: https://pypi.org/project/scikit-gof/ but these tests only work for fully specified distributions (i.e. known parameters).

Is anyone aware of a CVM-test implementation in python for a normal dist with unknown parameters?

Thanks

pyguy
  • 99
  • 1
  • 6
  • The commit that you linked to is part of a [scipy pull request](https://github.com/scipy/scipy/pull/11119). It is still under development. – Warren Weckesser Apr 17 '20 at 11:49

1 Answers1

0

The test is done on the sample. Here an example using OpenTURNS in Python.

import openturns as ot

First let's build a random sample of size 200 from a centered standard Normal distribution You may haveyour own data:

sample = ot.Sample([0, 0.3, -0.1, 0.23, -0.5], 1)

but OpenTurns offers a simple way to build samples

sample = ot.Normal().getSample(200)

Now to execute the Cramer-Von Mises normality test you just call this method

test_result = ot.NormalityTest.CramerVonMisesNormal(sample)

Then print the result

print('Component is normal?', test_result.getBinaryQualityMeasure(),
      'p-value=%.6g' % test_result.getPValue(),
      'threshold=%.6g' % test_result.getThreshold())

>>> Component is normal? True 
 p-value=0.624469 
 threshold=0.01

But always remember that the threshold is arbitrary and that the test can give false negative even though the sample really comes from a Normal distribution.

If you want to test a sample coming from a Uniform distribution, replace the line 'sample' by: sample = ot.Uniform().getSample(200)

Jean A.
  • 291
  • 1
  • 17