我有一个包含“ 0”和“ 1”的向量列表(dados_obs)。头和尾巴。
我必须测试它的随机性。因此,我进行了一次巨大的仿真,以获取p值,并与我的0和1向量列表进行比较,以测试它们是否是虚构的或实际上是随机的。效果很好
我发现它可以运行。test为我做到了,但是我有一个问题。仅当我的0和1的数目被n1 = n2 = 50和n = 100均分时有效。
<p id="p1">Marco Reus is a German professional footballer who plays as a forward for Borussia Dortmund and the Germany national team. He is renowned for his versatility, speed and technique, but also for proneness to injury.</p>
<button name="b1" onclick="n()">Next</button>
给我
runs.test(dados_obs[[16]])
但是
Runs Test
data: dados_obs[[16]]
statistic = 0.60305, runs = 54, n1 = 50, n2 = 50, n = 100, p-value = 0.5465
alternative hypothesis: nonrandomness
给我
runs.test(dados_obs[[17]])
有没有办法克服这个限制?当n1与n2不同时(总和与尾部不同)?
答案 0 :(得分:2)
runs.test
中的randtests
似乎自2014年以来就没有进行过更新。也许尝试使用snpar
中的那个? (管道也需要magrittr
。)
library(snpar)
library(magrittr)
例如:
> 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
答案 1 :(得分:1)
实际上,我和您有同样的问题。然后,在语法中(使用randtests
包)添加了我使用的切点。代码示例:
runs.test(dados_obs[[17]], threshold = mean(dados_obs[[17]]))
切点可以是均值,众数,中位数等。我们用它来指定n1和n2。