Beta distribution (source code)

= Beta distribution
{title2=$\operatorname{Beta}(\alpha,\beta)$}
{wiki}

The <beta distribution> is an <absolutely continuous probability distribution> for a <random variable> $X$ between zero and one. It can describe uncertainty about a <probability>, such as an unknown coin's chance of heads. For any real $\alpha,\beta>0$, its <probability density function> is
$$
f_X(x)=\frac{x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha,\beta)},\qquad 0<x<1,
$$
and zero outside $[0,1]$. The normalizer is the <Euler beta function>, related to the <gamma function> by the <beta-gamma identity>:
$$
B(\alpha,\beta)=\int_0^1x^{\alpha-1}(1-x)^{\beta-1}\,dx=\frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha+\beta)}.
$$
Thus the <probability density function> integrates to one. https://dlmf.nist.gov/5.12#E1[NIST DLMF 5.12.1: the beta integral and gamma-function normalizer]{ref}.

The endpoint behavior explains why the restrictions are exactly $\alpha,\beta>0$: near zero the <probability density function> behaves like a constant times $x^{\alpha-1}$, and near one like a constant times $(1-x)^{\beta-1}$. These <improper integrals> converge for positive parameters, even when the <probability density function> diverges at zero for $\alpha<1$ or at one for $\beta<1$. There is no <probability mass> at either endpoint: $\mathbb P(X=0)=\mathbb P(X=1)=0$. A <probability density function>'s height is not a <probability>; an interval's <probability> is the area under it.

Some useful examples of the <beta distribution> are:

* $\operatorname{Beta}(1,1)$ is the <uniform distribution> on $(0,1)$, with <probability density function> $f_X(x)=1$.
* $\operatorname{Beta}(2,2)$ has <probability density function> $f_X(x)=6x(1-x)$: values near one half are favored, and it is a <symmetric probability distribution> about one half.
* $\operatorname{Beta}(2,5)$ has <probability density function> $f_X(x)=30x(1-x)^4$. Its <mean> is $2/7$ and its <variance> is $10/(49\cdot8)=5/196\approx0.0255102$; most of its area lies toward the lower end.
* $\operatorname{Beta}(1/2,1/2)$ is the <arcsine distribution>, with <probability density function> $f_X(x)=1/(\pi\sqrt{x(1-x)})$. It favors values near both endpoints despite having <mean> $1/2$; its <variance> is $1/8$.

\Image[/beta-density-shapes.png]
{title=Beta density shapes: uniform, central, asymmetric, and boundary singular}

The <arcsine distribution> curve is plotted only for $0.001\leq x\leq0.999$; its finite plotted ends do not represent finite endpoint values of the <probability density function>. Using the <inverse sine>, the shaded central interval has exact <probability> $\mathbb P(0.1<X<0.9)=1-4\arcsin(\sqrt{0.1})/\pi\approx0.5903$, calculated analytically rather than by treating the cropped curve as normalized.

To separate location from spread, write $\kappa=\alpha+\beta$ and $m=\alpha/\kappa$. The <mean> and <variance> of the <beta distribution> are
$$
\mathbb E[X]=m=\frac{\alpha}{\kappa},\qquad
\operatorname{Var}(X)=\frac{\alpha\beta}{\kappa^2(\kappa+1)}=\frac{m(1-m)}{\kappa+1}.
$$
The <mean> specifies the balance between the parameters; their sum $\kappa$ controls concentration about that <mean>. Multiplying both parameters by the same positive number preserves the <mean> and changes the <variance>. Larger $\kappa$ puts more area near $m$ and makes the <probability density function> taller there; the total area stays one. Small $\kappa$ allows much greater spread, sometimes favoring the endpoints rather than the <mean> itself.

For example, keeping <mean> $m=0.3$ and taking $\kappa=5,20,80$ gives the <beta distributions> $\operatorname{Beta}(1.5,3.5)$, $\operatorname{Beta}(6,14)$, and $\operatorname{Beta}(24,56)$. Their <variances> are $0.035$, $0.01$, and $0.21/81\approx0.00259259$, respectively. Parameters need not be integers.

\Image[/beta-mean-and-concentration.png]
{title=The same beta mean with three concentrations and decreasing variance}

The formulas follow from two short <moment> calculations. Multiplying the <probability density function> by $x$ or $x^2$ increases the first parameter of the <Euler beta function>:
$$
\mathbb E[X]=\frac{B(\alpha+1,\beta)}{B(\alpha,\beta)}=\frac{\alpha}{\kappa},\qquad
\mathbb E[X^2]=\frac{B(\alpha+2,\beta)}{B(\alpha,\beta)}=\frac{\alpha(\alpha+1)}{\kappa(\kappa+1)}.
$$
Apply the <Gamma function recurrence> to the <beta-gamma identity>, then subtract $(\mathbb E[X])^2$ from $\mathbb E[X^2]$ to obtain the <variance>.

The <beta distribution> is especially convenient as a <prior distribution> for the unknown success <probability> $P$ of <Bernoulli trials>. The <Beta-binomial conjugacy> says that $h$ successes and $t$ failures update a <prior distribution> $\operatorname{Beta}(\alpha,\beta)$ to a <posterior distribution> $\operatorname{Beta}(\alpha+h,\beta+t)$. For example, suppose a coin has <prior distribution> $\operatorname{Beta}(2,2)$ and we observe eight heads and two tails. Its <posterior distribution> is then $\operatorname{Beta}(10,4)$, with <posterior> <mean> $5/7$. https://ocw.mit.edu/courses/18-05-introduction-to-probability-and-statistics-spring-2022/mit18_05_s22_class15-prep.pdf[MIT 18.05, Reading 15: beta priors and conjugate updating]{ref}.