我需要了解如何计算"超几何cdf":
我知道函数的外观以及它是如何工作的,但是我将函数倾斜到python中遇到了一些问题:
def hypergeometricCDF(N,K,n,x):
"""
Call:
p = hypergeometricCDF(N,K,n,x)
Input argument:
N: integer
K: integer
n: integer
x: integer
Output argument:
p: float
Example:
hypergeometricCDF(120,34,12,7)
=>
0.995786
"""
f=sum(range(x+1))
p = log_binomial_coeff(N-K,n-f) + log_binomial_coeff(K,f) - log_binomial_coeff(N,n)
return(p)
问题是,如何将 sum 函数从 i 积分到 x?我尝试了 sum(range(x+1)),但它不起作用。
试试这个:
def hypergeometricCDF(N,K,n,x):
"""
Call:
p = hypergeometricCDF(N,K,n,x)
Input argument:
N: integer
K: integer
n: integer
x: integer
Output argument:
p: float
Example:
hypergeometricCDF(120,34,12,7)
=>
0.995786
"""
k = arange(x+1)
p = sum(exp(log_hypergeometricPMF(N,K,n,k)))
return(p)
log_hypergeometricPMF在文件;)之上定义