Hypergeometric test (phyper)

主宰稳场 提交于 2019-12-31 08:12:34

问题


I've a question about the hypergeometric test.

I've data like this :

pop size : 5260
sample size : 131
Number of items in the pop that are classified as successes : 1998
Number of items in the sample that are classified as successes : 62

To compute a hypergeometric test, is that correct?

phyper(62, 1998, 5260, 131)

回答1:


Almost correct. If you look at ?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.

So using your data:

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



回答2:


I think you want to compute p-value. In this case, you want

P(Observed 62 or more) = 1-P(Observed less than 62).

So you want

1.0-phyper(62-1, 1998, 5260-1998, 131)

Note that -1 there in the first parameters. And also you need to subtract that from 1.0 to get the area of the right tail.

Correct me if I'm wrong..




回答3:


@Albert,

To compute a hypergeometric test, you obtain the same p-value, P(observed 62 or more), using:

> phyper(62-1, 1998, 5260-1998, 131, lower.tail=FALSE)
[1] 0.01697598

Because:

lower.tail: logical; if TRUE (default), probabilities are P[X <= x], 
            otherwise, P[X > x]



回答4:


I think this test be should be like following:

phyper(62,1998,5260-1998,131-62,lower.tail=FALSE)

Then the sum of all the rows will equal the sum of all the columns. This is important when dealing with contingency tables.



来源:https://stackoverflow.com/questions/8382806/hypergeometric-test-phyper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!