大数的累积二项分布

2024-05-12 20:26:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中实现了以下函数:

# Calculation of cumulative binomial distribution
def PDP(p, N, min):
    pdp=0
    for k in range(min, N+1):
        pdp += (float(factorial(N))/(factorial(k)*factorial(N-k)))*(p**k)*((1-p)**(N-k))
    return pdp

但是,计算产生的值太大,n值很高(高达255)。我已经找过这些值的近似值,但没有用。你会怎么做?在


Tags: of函数infordefrangefloatmin
2条回答

假设X服从二项分布

你想计算p(X>;=m),我先做一个连续性校正,用p(X>;=m-0.5)近似,然后用法向近似法近似。在

P((X - np)/ sqrt(np(1-p)) >= (m-0.5-np)/sqrt(np(1-p)) 

这是近似值

^{pr2}$

其中Z是标准正态分布。在

References表示这种近似。在

根据辛格的回答,我提出了以下解决方案:

import math

# Cumulative distribution function
def CDF(x):
    return (1.0 + math.erf(x/math.sqrt(2.0)))/2.0

# Approximation of binomial cdf with continuity correction for large n
# n: trials, p: success prob, m: starting successes
def BCDF(p, n, m):
    return 1-CDF((m-0.5-(n*p))/math.sqrt(n*p*(1-p)))

相关问题 更多 >