[Numpy-discussion] Alternative to R phyper
Mon Apr 30 06:09:20 CDT 2012
I have a bit of code where I am using rpy2 to import R phyper so I can
perform an hypergeometric test. Unfortunately our cluster does not have a
functional installation of rpy2 working. So I am wondering if I could
translate to scipy which would make the code completly independent of R.
The python code I have is as following:
Calculate p-value using R function phyper from rpy2 low-level
phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE)
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.
log.p: logical; if TRUE, probabilities p are given as log(p).
lower.tail: logical; if TRUE (default), probabilities are P[X <= x],
otherwise, P[X > x].
phyper_q = SexpVector([q,], rinterface.INTSXP)
phyper_m = SexpVector([m,], rinterface.INTSXP)
phyper_n = SexpVector([n,], rinterface.INTSXP)
phyper_k = SexpVector([k,], rinterface.INTSXP)
I have looked to scipy.stats.hypergeom but it is giving me a different
result which is also negative.
> 1-phyper(45, 92, 7518, 1329)
In : stats.hypergeom.sf(45,(92+7518),92,1329)
This was supposed to be an error with an older version of scipy but I am
using more recent versions of it which should not contain the error anymore:
In : numpy.__version__
In : scipy.__version__
thank you very much in advance for any help.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion