Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kolmogorov-Smirnov test

I'm using the R function ks.test() to test the Uniform distribution of the R random number generator. I'm using the following code: replicate(100000, ks.test(runif(n),y="punif").

When n is less than or equal to 100 it works, but when n is greater than 100 I get the following Warning Message:

In ks.test(runif(100000), y = "punif") :
  ties should not be present for the Kolmogorov-Smirnov test.

What are those "ties"?

like image 501
Egodym Avatar asked Jan 26 '15 20:01

Egodym


1 Answers

If you inspect the body of the function ks.test you will see the following line somewhere in the body:

if (length(unique(x)) < n) {
    warning("ties should not be present for the Kolmogorov-Smirnov test")
    TIES <- TRUE
}

This tells you that when the number of unique elements in x is below the number of elements - you will get this warning. In other words if your vector has duplicate entries - you will get the warning.

Most likely what happened is that when n > 100 there are more chances to get a duplicated value in there somewhere compared with using n = 100. Since you are repeating this thousands of times the probability for having two identical values in x goes up.

As an example this code didn't give me any warning:

set.seed(1234)
smth <- replicate(100000, ks.test(runif(101),y="punif"))
like image 153
Karolis Koncevičius Avatar answered Sep 27 '22 21:09

Karolis Koncevičius