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:
self.phyper(self,q,m,n,k)
Calculate p-value using R function phyper from rpy2 low-level
interface.
"R Documentation
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)
return phyper(phyper_q,phyper_m,phyper_n,phyper_k,**myparams)[0]
I have looked to scipy.stats.hypergeom but it is giving me a different result which is also negative.
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:
thank you very much in advance for any help.