Code covered by the BSD License

### Highlights from Two sample Cramer-von Mises hypothesis test

4.375
4.4 | 10 ratings Rate this file 5 Downloads (last 30 days) File Size: 4.44 KB File ID: #13407 Version: 1.4

# Two sample Cramer-von Mises hypothesis test

### Juan Cardelino (view profile)

15 Dec 2006 (Updated )

A non parametric test to determine if to independent samples were drawn from the same distribution.

File Information
Description

This was inspired by kstest2 from the matlab statistics toolbox.
Works from medium to large sample sizes, look at the references in the code.

Required Products Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7 (R14)
08 May 2014 Jon

### Jon (view profile)

This does not seem to work correctly. As a test I ran cmtest2(random('Normal',0,1,1,4000000),random('Normal',0,1,1,4000000)) that's 4 million samples from the same normal distribution and I got a p value of .067.

08 May 2014 Jon

### Jon (view profile)

24 Apr 2014 Ruisi

### Ruisi (view profile)

27 Jul 2013 Juan Cardelino

### Juan Cardelino (view profile)

I wrote this a while ago. I don't recall at the moment. I will look into it as soon as possible.
Thanks for the feedback.

Comment only
29 Nov 2012 Dan

### Dan (view profile)

Which equation in academic reference (1) does the formula for 'CMstatistic' on line 143 refer to? Equation (6) in "On the distribution of the two-sample Cramer-von Mises criterion" looks very different.

Comment only
06 Nov 2012 Juan Cardelino

### Juan Cardelino (view profile)

I will look into both issues. Thanks for the feedback.

Comment only
06 Nov 2012 Stuart Layton

### Stuart Layton (view profile)

In the case that "CM_limiting_stat > z(end)" it is incorrect to report a pValue of 0. Instead it should be reported that p is less than .001

06 Nov 2012 Stuart Layton

### Stuart Layton (view profile)

Good function! Why does the help documentation show a 4th input argument "tail" that isn't accepted by the function?

18 May 2012 Ipek

### Ipek (view profile)

Thank you so much, works great.

16 Nov 2011 Juan Cardelino

### Juan Cardelino (view profile)

I've uploaded a new and improved version. Corrected a bug in the rejection rule, as pointed out in the comments. Now it works as intended. Added an example along with an extensive test and a comparison with the Kolgomorov-Smirnov test provided by Matlab.

Comment only
30 Dec 2009 Juan Cardelino

### Juan Cardelino (view profile)

Yeah, someone pointed this out earlier too. As soon as I get time I will check it, and provide a test sequence too.
Thanks guys for the feedback.

Comment only
29 Dec 2009 Siavash Jalal

### Siavash Jalal (view profile)

I think Soma is right. pValue should be 1-pValue. Then we reject H_null when alpha > pValue.

Comment only
25 Dec 2009 priya priyal

### priya priyal (view profile)

hi juan,
Thanx, it is very useful.

the hypothesis is computed as "not(alpha>pValue)", is this correct?
i suppose it should be "H=(alpha>pValue)"

17 Oct 2009 Soma

### Soma (view profile)

I think, the problem is not with reversing the boolean decision. The tables in reference (2), what is given is the CDF. So, the p-value is 1-p(T<T*), where T* is the observed/computed statistics.

I think, the p-value is actually 1-pValue* where pValue* is what is currently computed this function.

Please let me know if I am wrong

Comment only
26 May 2009 Juan Cardelino

### Juan Cardelino (view profile)

thanks for the feedback guys. ive expanded the documentation and corrected one bug with the boolean output. let me know if you find something else.

Comment only
11 May 2008 Negar M

Very useful and clear to understand.
Thanks very much.

03 Jan 2008 Min Lee

Thank you~

05 Aug 2007 patrick li

thank you it is exactly what i want

09 Jan 2007

Description was incomplete.

26 May 2009 1.2

The boolean output of the test was reversed. Although the probability was correctly computed, the test rejected the null hypothesis when it had to accept it and vice versa.

16 Nov 2011 1.3

Corrected a bug in the rejection rule, as pointed out in the comments. Now it works as intented. Added an example along with an extensive test.

16 Nov 2011 1.4

Corrected a bug in the rejection rule, as pointed out in the comments. Now it works as intented. Added an example along with an extensive test and comparison with the Kolgomorov-Smirnov test.