File Exchange

image thumbnail

Two sample Cramer-von Mises hypothesis test

version 1.4 (4.44 KB) by

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

4 Downloads

Updated

View License

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

Comments and Ratings (18)

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.

Jon

Jon (view profile)

Ruisi

Ruisi (view profile)

Juan Cardelino

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.

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.

Juan Cardelino

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

Stuart Layton

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

Stuart Layton

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

Ipek

Ipek (view profile)

Thank you so much, works great.

Juan Cardelino

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.

Juan Cardelino

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.

Siavash Jalal

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

priya priyal

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)"

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

Juan Cardelino

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.

Negar M

Very useful and clear to understand.
Thanks very much.

Min Lee

Thank you~

patrick li

thank you it is exactly what i want

Updates

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.

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.

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.

Description was incomplete.

MATLAB Release
MATLAB 7 (R14)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video