6

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

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
Egodym
  • 453
  • 1
  • 8
  • 23
  • Have you tried `?ks.test` – Marat Talipov Jan 26 '15 at 21:00
  • Sounds like `runif()` returned duplicate values. Try looking at `x<-runif(100000);ks.test(x, y = "punif");sum(duplicated(x))` instead to see if that's the case. (Because it's random you might not get the same result each time) – MrFlick Jan 26 '15 at 21:00

1 Answers1

11

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"))
Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89