超几何测试(phyper)

超几何测试(phyper),r,testing,R,Testing,我有一个关于超几何测试的问题 我有这样的数据: 弹出窗口大小:5260 样本量:131 pop中归类为成功的项目数:1998 样本中分类为成功的项目数:62 计算超几何检验,对吗 phyper(62, 1998, 5260, 131) 几乎正确。如果你看《代码》?phyper: phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE) x, q vector of quantiles representing the number of wh

我有一个关于超几何测试的问题

我有这样的数据:

弹出窗口大小:5260
样本量:131
pop中归类为成功的项目数:1998
样本中分类为成功的项目数:62

计算超几何检验,对吗

phyper(62, 1998, 5260, 131)

几乎正确。如果你看《代码》?phyper:

phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE)

x, q vector of quantiles representing the number of white balls drawn
without replacement from an urn which contains both black and white
balls.

m the number of white balls in the urn.

n the number of black balls in the urn.

k the number of balls drawn from the urn.
因此,使用您的数据:

phyper(62,1998,5260-1998,131)
[1] 0.989247

我想你需要计算p值。在这种情况下,您需要

P(Observed 62 or more) = 1-P(Observed less than 62).
1.0-phyper(62-1, 1998, 5260-1998, 131)
所以你想要

P(Observed 62 or more) = 1-P(Observed less than 62).
1.0-phyper(62-1, 1998, 5260-1998, 131)
请注意,第一个参数中有
-1
。你还需要从1.0中减去它,得到右尾的面积

如果我错了,请纠正我。

@Albert

要计算超几何测试,可使用以下公式获得相同的p值p(观测值为62或更多):

因为:

lower.tail: logical; if TRUE (default), probabilities are P[X <= x], 
            otherwise, P[X > x]
lower.tail:逻辑;如果为真(默认),概率为P[X]

我认为这个测试应该如下所示:

phyper(62,1998,5260-1998,131-62,lower.tail=FALSE)
然后所有行的总和将等于所有列的总和。
这在处理列联表时很重要。

不是phyper(6119985260-1998131)吗?@NicoBxl否,62是样本中的成功次数,对吗?是的,是62。但我在某个地方读到,我必须在这里减去一个(幻灯片20):@NicoBxl我不确定他们试图计算什么,或者你是什么。但是,
phyper
给出了累计概率,包括您的输入观察值,即P(观察值为62或更少)。如果你想要P(观测值小于62),那么显然使用61。如果你想要的正好是62,那么使用
dhyper
OP想要的是右尾还是左尾将取决于测试中替代假设的方向,这在问题中没有明确说明。相关帖子:Meng关于phyper和fisher.test的注释(它们做同样的事情,但是有一个非常不同的界面)也非常有用: