6

我正在使用 R 函数ks.test()来测试 R 随机数生成器的均匀分布。我正在使用以下代码: replicate(100000, ks.test(runif(n),y="punif").

n小于或等于 100 时,它可以工作,但是当n大于 100 时,我收到以下警告消息:

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

那些“关系”是什么?

4

1 回答 1

11

如果您检查函数的主体,ks.test您将在主体的某处看到以下行:

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

这告诉您,当 x 中的唯一元素数低于元素数时 - 您将收到此警告。换句话说,如果您的向量有重复的条目 - 您将收到警告。

最有可能发生的情况是,当 n > 100 时,与使用 n = 100 相比,在某处获得重复值的机会更多。由于您重复了数千次,因此在 x 中具有两个相同值的概率会上升。

作为一个例子,这段代码没有给我任何警告:

set.seed(1234)
smth <- replicate(100000, ks.test(runif(101),y="punif"))
于 2015-01-26T21:05:00.030 回答