Beta-binomial with given mean and variance

The previous post looked at an application of the beta-binomial distribution. The probability mass function for a beta-binomial with parameters n, a, and b is given by

\text{Prob}(X = x) = \binom{n}{x} \frac{B(x + a, n - x + b)}{B(a, b)}

The mean μ and the variance σ² are given by

\begin{align*} \mu &= \frac{na}{a+b} \\ \sigma^2 &= \frac{nab(a + b + n)}{(a+b)^2(a + b + 1)} \end{align*}

Solving for a and b to meet a specified mean and variance appears at first to require solving a cubic equation, but it’s easier than that.

If we define p = a/(a+b) then the system becomes

\begin{align*} \mu &= np \\ \sigma^2 &= n p (1-p)\frac{a + np}{a + b} \end{align*}

We assume n is known and so p is known, and we are left with a linear equation for a. With a little work we find

\begin{align*} a &= -\frac{\mu(\mu^2 - \mu n + \sigma^2)}{\mu^2 - \mu n + \sigma^2 n} \\ b &= \frac{a(n - \mu)}{\mu} \end{align*}

I verified the calculations above with Mathematica.

One use for solving for a and b would be to fit a beta-binomial distribution to data using moment matching. I don’t know how robust this would be, but at least it’s something.

Another application would be to find a beta-binomial prior distribution with elicited mean and variance.