Python中的Beta二项式函数 [英] Beta Binomial Function in Python
问题描述
我想针对预定的x(成功),n(试验)和p(概率)计算由二项式分布给出的概率-后者由概率质量函数Beta(a,b)给出
I would like to calculate the probability given by a binomial distribution for predetermined x(successes), n(trials), and p(probability) - the later of which is given by a probability mass function Beta(a,b).
我知道 scipy.stats.binom.pmf(x,n,p)
-但是我不确定如何用概率函数代替p。我也想知道我是否可以使用 scipy.stats.binom.pmf
来模仿这种行为。
I am aware of scipy.stats.binom.pmf(x,n,p)
- but I am unsure how I can replace p with a probability function. I am also wondering whether I could use the loc
argument of scipy.stats.binom.pmf
to emulate this behaviour.
推荐答案
维基说,复合分布函数由
f(k|n,a,b) = comb(n,k) * B(k+a, n-k+b) / B(a,b)
其中B是beta函数,a和b是原始Beta参数,n是二项式参数。 k是您的x,而p消失是因为您对p的值进行积分以获得该值(卷积)。
就是说,您不会在scipy中找到它,但是只要您来自scipy的beta函数。
where B is the beta function, a and b are the original Beta parameters and n is the Binomial one. k here is your x and p disappears because you integrate over the values of p to obtain this (convolution). That is, you won't find it in scipy but it is a one-liner provided you have the beta function from scipy.
这篇关于Python中的Beta二项式函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!