Beta-binomial distribution (source code)

= Beta-binomial distribution
{title2=$\Pr(Y=y)=\binom ny\frac{\mathrm B(\alpha+y,\beta+n-y)}{\mathrm B(\alpha,\beta)}$}
{wiki}

Mix a <binomial distribution> with a <beta distribution> for its success probability: $\Theta\sim\operatorname{Beta}(\alpha,\beta)$ and $Y\mid\Theta\sim\operatorname{Binomial}(n,\Theta)$. Integrating their densities gives the displayed mass for $y=0,\ldots,n$. Its <expectation> is $n\alpha/(\alpha+\beta)$, and its <variance> is $n\alpha\beta(\alpha+\beta+n)/[(\alpha+\beta)^2(\alpha+\beta+1)]$. It is the <posterior predictive distribution> for repeated <Bernoulli trials> after a beta-prior update.