Hi,
I need some help getting the hypergeom distr. I've started with this code, but it doesn't seem work:

def logchoose(n, k):
    	lgn = special.gammaln(n+1)
   	lgk = special.gammaln(k+1)
   	lgnk = special.gammaln(n-k+1)
   	return lgn - (lgnk + lgk)

def hypgeo(x, r, b, n):
	return exp(logchoose(r, x) + logchoose(b, n-x) - logchoose(r+b, n))

b = 2450
r = 346
N = r + b
n = 5000  
x = 1000
p = hypgeo(x,r,b,n)
print p

I think arguments to logchoose() should be swapped

from scipy import exp, special

def logchoose(n, k):
        lgn = special.gammaln(n+1)
        lgk = special.gammaln(k+1)
        lgnk = special.gammaln(n-k+1)
        return lgn - (lgnk + lgk)


def hypgeo(x, r, b, n):
    u = logchoose(x, r)
    v = logchoose(n-x, b)
    w = logchoose(n, r + b)
    return exp(u + v - w)

    
b = 2450
r = 346
N = r + b
n = 5000  
x = 1000
p = hypgeo(x,r,b,n)
print p

""" my output -->
2.79971621598e-52
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.