超几何测试(phyper)

时间:2011-12-05 08:47:51

标签: r testing

我对超几何测试有疑问。

我有这样的数据:

弹出尺寸:5260
样本量:131
pop中被归类为成功的项目数:1998
样本中被分类为成功的项目数:62

要计算超几何测试,这是正确的吗?

phyper(62, 1998, 5260, 131)

4 个答案:

答案 0 :(得分:21)

几乎正确。如果你看?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

答案 1 :(得分:18)

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

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

所以你想要

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

注意第一个参数中有-1。而且你还需要从1.0中减去它以得到右尾区域。

如果我错了,请纠正我。

答案 2 :(得分:8)

@Albert,

要计算超几何测试,您可以使用以下方法获得相同的p值P(观察到62或更多)

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

由于:

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

答案 3 :(得分:0)

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

std::atomic<size_t> mNextBufferIndex;

    Buffer* GetNextBuffer()
    {
       // How to make this operation atomic?
       size_t index = mNextBufferIndex ++; 

       size_t id = index % mTotalBuffers;

       // If size could wrap, then re-write the modulo value.
       // oldValue keeps getting re-read.  
       // modulo occurs when nothing else updates it.
       size_t oldValue =mNextBufferIndex;
       size_t newValue = oldValue % mTotalBuffers;
       while (!m_mNextBufferIndex.compare_exchange_weak( oldValue, newValue, std::memory_order_relaxed ) )
            newValue = oldValue % mTotalBuffers; 
       return mBuffers[id ];
    }

然后所有行的总和将等于所有列的总和。 这在处理列联表时非常重要。