简体   繁体   English

running.test() 仅适用于偶数 n1 和 n2

[英]runs.test() works only with even numbers of n1 and n2

I have a list of vectors (dados_obs) that contains "0" and "1".我有一个包含“0”和“1”的向量列表(dados_obs)。 Head and Tails.头和尾。

I have to test it's randomness.我必须测试它的随机性。 So I made a huge simulation to get the p-value and compare with my list of vectors of 0 and 1 to test if they were made up or actually random.所以我做了一个巨大的模拟来获得 p 值并与我的 0 和 1 向量列表进行比较,以测试它们是组成的还是实际上是随机的。 It worked fine它工作得很好

I discovered it runs.test does that for me, but i have a problem.我发现它 running.test 为我做了这个,但我有一个问题。 It only works when my number of 0's and 1's are evenly split with n1 = n2 = 50, with n = 100.它仅在我的 0 和 1 的数量与 n1 = n2 = 50、n = 100 平均分配时才有效。

runs.test(dados_obs[[16]])

Gives me给我

Runs Test

data:  dados_obs[[16]]
statistic = 0.60305, runs = 54, n1 = 50, n2 = 50, n = 100, p-value = 0.5465
alternative hypothesis: nonrandomness

But

runs.test(dados_obs[[17]])

Gives me给我

    Runs Test

data:  dados_obs[[17]]
statistic = NaN, runs = 1, n1 = 0, n2 = 49, n = 49, p-value = NA
alternative hypothesis: nonrandomness

Is there a way to overcome this limitation?有没有办法克服这个限制? When n1 differs from n2 (Sum of Head differs from Sum of Tails)?当 n1 与 n2 不同时(头的总和与尾的总和不同)?

The runs.test from randtests looks like it has not been updated since 2014. Maybe try the one in snpar ?runs.testrandtests好像还没有被2014年更新的外观也许尝试之一snpar (Also need magrittr for pipes.) (管道也需要magrittr 。)

library(snpar)
library(magrittr)

For example:例如:

> sample(c(0,1),20,replace=TRUE) %>% snpar::runs.test()

    Approximate runs rest

data:  .
Runs = 13, p-value = 0.3581
alternative hypothesis: two.sided

> sample(c(0,1),100,replace=TRUE) %>% snpar::runs.test()

    Approximate runs rest

data:  .
Runs = 43, p-value = 0.1146
alternative hypothesis: two.sided

Actually, I had the same problem as you.其实我遇到了和你一样的问题。 Then I added the cut point that i used, in the syntax (with randtests package).然后我在语法中添加了我使用的切点(使用randtests包)。 Example with your code :您的代码示例:

runs.test(dados_obs[[17]], threshold = mean(dados_obs[[17]]))

The cut points can be mean, mode, median, etc. We used it to specified the n1 and n2.切割点可以是均值、众数、中位数等。我们用它来指定 n1 和 n2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM