Kolmogorov-Smirnov测试

Ego*_*dym 5 simulation statistics r probability hypothesis-test

我正在使用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.
Run Code Online (Sandbox Code Playgroud)

这些"关系"是什么?

Kar*_*ius 10

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

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

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

最有可能发生的事情是,当n> 100时,与使用n = 100相比,在那里获得重复值的机会更多.因为你重复这几千次,在x中有两个相同值的概率就会增加.

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

set.seed(1234)
smth <- replicate(100000, ks.test(runif(101),y="punif"))
Run Code Online (Sandbox Code Playgroud)

  • 但是,如果我的数据集包含重复值,该怎么办? (6认同)