Skip to content

kolmogorov-Smirnov critical values

9 messages · Uwe Ligges, aramos, Petr Savicky +2 more

#
On Wed, May 16, 2012 at 9:52 AM, aramos <aramos at fep.up.pt> wrote:
Take a look at ?ks.test and the code of ks.test to see how R does it.
OSS is super helpful for these sorts of things.

Michael
#
On 16.05.2012 15:52, aramos wrote:
ks.test(.....)$statistic

Uwe ligges
#
On Wed, May 16, 2012 at 06:52:48AM -0700, aramos wrote:
Hi.

I do not know, whether there is a function for this. However, the following
randomized approach allows to extract a table of statistic/p.value pairs
from ks.test() for fixed sample sizes.

  n1 <- 30
  n2 <- 50
  d <- 10000
  res <- matrix(nrow=d, ncol=2)
  for (i in seq.int(length=d)) {
      x1 <- runif(n1) + runif(1)
      x2 <- runif(n2) + runif(1)
      out <- ks.test(x1, x2)
      res[i, 1] <- out$statistic
      res[i, 2] <- out$p.value
  }
  tab <- unique(res[order(res[, 1]), ])
  colnames(tab) <- c("statistic", "p.val")

If you are mainly interested in the range of the p-values for relatively
close distributions, then replace

      x1 <- runif(n1) + runif(1)
      x2 <- runif(n2) + runif(1)

by

      x1 <- runif(n1)
      x2 <- runif(n2)

Part of the obtained table is

         statistic        p.val
  
  [39,] 0.30000000 5.642910e-02
  [40,] 0.30666667 4.815638e-02
  [41,] 0.31333333 4.091424e-02
  [42,] 0.32000000 3.466530e-02
  [43,] 0.32666667 2.925540e-02
  [44,] 0.33333333 2.458672e-02
  [45,] 0.34000000 2.060188e-02
  [46,] 0.34666667 1.719140e-02
  [47,] 0.35333333 1.428992e-02
  [48,] 0.36000000 1.183727e-02
  [49,] 0.36666667 9.767969e-03

Hope this helps.

Petr Savicky.
#
Open source software (what you're driving)

Michael
On Wed, May 16, 2012 at 12:27 PM, aramos <aramos at fep.up.pt> wrote:
#
On May 16, 2012, at 12:27 PM, aramos wrote:

            
But the illustration for how you get the statistics is in the code.

Describe what you want: number of samples, two versus single sided,  
two sample versus comparing to theory, which table columns should be  
used. Then someone can probably help.
David Winsemius, MD
West Hartford, CT