累积分布函数(超几何)
Cumulative distribution function (hypergeometric)
我需要了解如何计算 'hypergeometric 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)
问题是,我如何将求和函数从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 定义在文件顶部 ;)
我需要了解如何计算 'hypergeometric 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)
问题是,我如何将求和函数从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 定义在文件顶部 ;)