我有一个关于超几何测试的问题.
我有这样的数据:
pop size:5260
sample size:131
pop中被归类为成功
的项目数:1998 样本中被分类为成功的项目数:62
要计算超几何测试,这是正确的吗?
phyper(62, 1998, 5260, 131)
Run Code Online (Sandbox Code Playgroud)
Jam*_*mes 23
差不多正确.如果你看看?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.
Run Code Online (Sandbox Code Playgroud)
所以使用你的数据:
phyper(62,1998,5260-1998,131)
[1] 0.989247
Run Code Online (Sandbox Code Playgroud)
小智 19
我想你想要计算p值.在这种情况下,你想要
P(Observed 62 or more) = 1-P(Observed less than 62).
Run Code Online (Sandbox Code Playgroud)
所以你要
1.0-phyper(62-1, 1998, 5260-1998, 131)
Run Code Online (Sandbox Code Playgroud)
请注意,-1在第一个参数中.而且你需要从1.0中减去它以获得右尾区域.
如我错了请纠正我..
小智 9
@Albert,
要计算超几何测试,您可以使用以下方法获得相同的p值P(观察到62或更多):
> phyper(62-1, 1998, 5260-1998, 131, lower.tail=FALSE)
[1] 0.01697598
Run Code Online (Sandbox Code Playgroud)
因为:
lower.tail: logical; if TRUE (default), probabilities are P[X <= x],
otherwise, P[X > x]
Run Code Online (Sandbox Code Playgroud)