How can I calculate the $\alpha$ and $\beta$ parameters for a Beta distribution if I know the mean and variance that I want the distribution to have? Examples of an R command to do this would be most helpful.
-
9Note that the [betareg](http://cran.r-project.org/web/packages/betareg/index.html) package in R uses an alternative parameterization (with the mean, $\mu=\alpha/(\alpha+\beta)$, & the precision, $\phi=\alpha+\beta$--and hence the variance is $\mu(1-\mu)/(1+\phi)$) which obviates the need for these calculations. – gung - Reinstate Monica Jul 25 '12 at 15:48
-
1This post could be subtitled "help! I don't want to do algebra!" (that's my reason for being here at least) – Matthew Turner Oct 06 '21 at 20:41
7 Answers
I set$$\mu=\frac{\alpha}{\alpha+\beta}$$and$$\sigma^2=\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}$$and solved for $\alpha$ and $\beta$. My results show that$$\alpha=\left(\frac{1-\mu}{\sigma^2}-\frac{1}{\mu}\right)\mu^2$$and$$\beta=\alpha\left(\frac{1}{\mu}-1\right)$$
I've written up some R code to estimate the parameters of the Beta distribution from a given mean, mu, and variance, var:
estBetaParams <- function(mu, var) {
alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
beta <- alpha * (1 / mu - 1)
return(params = list(alpha = alpha, beta = beta))
}
There's been some confusion around the bounds of $\mu$ and $\sigma^2$ for any given Beta distribution, so let's make that clear here.
- $\mu=\frac{\alpha}{\alpha+\beta}\in\left(0, 1\right)$
- $\sigma^2=\frac{\alpha\beta}{\left(\alpha+\beta\right)^2\left(\alpha+\beta+1\right)}=\frac{\mu\left(1-\mu\right)}{\alpha+\beta+1}<\frac{\mu\left(1-\mu\right)}{1}=\mu\left(1-\mu\right)\in\left(0,0.5^2\right)$

- 3,724
- 3
- 19
- 24
-
Can one use it for generating beta distribution based on sample Mean and Variance = SD^2? I mean I want to check whether my sample (with Mean and SD^2) belongs to beta distribution with Mu=Mean and SD^2=Var). Is this a correct way? – abc Aug 19 '12 at 17:29
-
2@stan This will give you the Beta distribution which has the same mean and variance as your data. It will not tell you how well the distribution fits the data. Try the [Kolmogorov-Smirnov Test](http://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test). – assumednormal Aug 19 '12 at 20:19
-
4When I call this function with `estBetaParams(0.06657, 0.1)` I get `alpha=-0.025`, `beta=-0.35`. How is this possible? – Amelio Vazquez-Reina May 07 '14 at 23:46
-
I have to second Amelio's concern, here. I am getting results from this code that should not be possible, and do not result in a beta distribution... – danno Oct 29 '15 at 18:11
-
4These calculations will only work if the variance is less than the mean*(1-mean). – danno Oct 29 '15 at 18:20
-
3@danno - It's always the case that $\sigma^2\leq\mu\left(1-\mu\right)$. To see this, rewrite the variance as $\sigma^2=\frac{\mu\left(1-\mu\right)}{\alpha+\beta+1}$. Since $\alpha+\beta+1\geq1$, $\sigma^2\leq\mu\left(1-\mu\right)$. – assumednormal Nov 04 '15 at 03:06
-
@AmelioVazquez-Reina - There's no Beta distribution with that mean and variance, which is why the estimates you get in return are nonsensical. – assumednormal Nov 04 '15 at 03:10
-
1@AmelioVazquez-Reina If you give your original data I expect it will quickly be obvious why a beta distribution isn't suitable. – Glen_b Nov 04 '15 at 03:49
-
When I use this with the empirical estimates of $\mu=0.712$ and $\sigma=0.205$ I get zero for $\alpha$ and $\beta$ – Toke Faurby Apr 12 '18 at 08:34
-
-
4Given arbitrary $\mu\in(0,1)$ and $\sigma^2\in(0,0.5^2)$, there exists a beta distribution with mean $\mu$ and variance $\sigma^2$ _if and only if_ $\sigma^2\leq\mu(1-\mu)$. @assumednormal showed the "only if" part of this claim, and danno hints at the "if" part. The takeaway is that not all values of $(\mu,\sigma^2)\in(0,1)\times(0,0.5^2)$ lead to valid beta distributions. Hopefully this clears up a little confusion about negative $\alpha$ and $\beta$! – David M. Dec 15 '20 at 19:30
Here's a generic way to solve these types of problems, using Maple instead of R. This works for other distributions as well:
with(Statistics):
eq1 := mu = Mean(BetaDistribution(alpha, beta)):
eq2 := sigma^2 = Variance(BetaDistribution(alpha, beta)):
solve([eq1, eq2], [alpha, beta]);
which leads to the solution
$$ \begin{align*} \alpha &= - \frac{\mu (\sigma^2 + \mu^2 - \mu)}{\sigma^2} \\ \beta &= \frac{(\sigma^2 + \mu^2 - \mu) (\mu - 1)}{\sigma^2}. \end{align*} $$
This is equivalent to Max's solution.

- 1,802
- 14
- 17
In R, the beta distribution with parameters $\textbf{shape1} = a$ and $\textbf{shape2} = b$ has density
$f(x) = \frac{\Gamma(a+b)}{\Gamma(a) \Gamma(b)} x^{a-1}(1-x)^{b-1}$,
for $a > 0$, $b >0$, and $0 < x < 1$.
In R, you can compute it by
dbeta(x, shape1=a, shape2=b)
In that parametrisation, the mean is $E(X) = \frac{a}{a+b}$ and the variance is $V(X) = \frac{ab}{(a + b)^2 (a + b + 1)}$. So, you can now follow Nick Sabbe's answer.
Good work!
Edit
I find:
$a = \left( \frac{1 - \mu}{V} - \frac{1}{\mu} \right) \mu^2$,
and
$b = \left( \frac{1 - \mu}{V} - \frac{1}{\mu} \right) \mu (1 - \mu)$,
where $\mu=E(X)$ and $V=V(X)$.

- 19,898
- 5
- 76
- 77
-
I realise my answer is very similar to the others. Nonetheless, I believe it is always a good point to first check what parametrisation R uses.... – ocram Jun 22 '11 at 18:25
On Wikipedia for example, you can find the following formulas for mean and variance of a beta distribution given alpha and beta: $$ \mu=\frac{\alpha}{\alpha+\beta} $$ and $$ \sigma^2=\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)} $$ Inverting these ( fill out $\beta=\alpha(\frac{1}{\mu}-1)$ in the bottom equation) should give you the result you want (though it may take some work).

- 12,119
- 2
- 35
- 43
-
1Wikipedia has a section on parameter estimation that lets you avoid too much work :) – rm999 Jun 22 '11 at 18:10
Solve the $\mu$ equation for either $\alpha$ or $\beta$, solving for $\beta$, you get $$\beta=\frac{\alpha(1-\mu)}{\mu}$$ Then plug this into the second equation, and solve for $\alpha$. So you get $$\sigma^2=\frac{\frac{\alpha^2(1-\mu)}{\mu}}{(\alpha+\frac{\alpha(1-\mu)}{\mu})^2(\alpha+\frac{\alpha(1-\mu)}{\mu}+1)}$$ Which simplifies to $$\sigma^2=\frac{\frac{\alpha^2(1-\mu)}{\mu}}{(\frac{\alpha}{\mu})^2\frac{\alpha+\mu}{\mu}}$$ $$\sigma^2=\frac{(1-\mu)\mu^2}{\alpha+\mu}$$ Then finish solving for $\alpha$.

- 218
- 1
- 6
For a generalized Beta distribution defined on the interval $[a,b]$, you have the relations:
$$\mu=\frac{a\beta+b\alpha}{\alpha+\beta},\quad\sigma^{2}=\frac{\alpha\beta\left(b-a\right)^{2}}{\left(\alpha+\beta\right)^{2}\left(1+\alpha+\beta\right)}$$
which can be inverted to give:
$$\alpha=\lambda\frac{\mu-a}{b-a},\quad\beta=\lambda\frac{b-\mu}{b-a}$$
where
$$\lambda=\frac{\left(\mu-a\right)\left(b-\mu\right)}{\sigma^{2}}-1$$

- 3,298
- 1
- 19
- 36
-
A user has attempted to leave the following comment: "there's an error somewhere here. Current formulation does not return the correct variance." – Silverfish Apr 12 '15 at 15:14
I was looking for python, but stumbled upon this. So this would be useful for others like me.
Here is a python code to estimate beta parameters (according to the equations given above):
# estimate parameters of beta dist.
def getAlphaBeta(mu, sigma):
alpha = mu**2 * ((1 - mu) / sigma**2 - 1 / mu)
beta = alpha * (1 / mu - 1)
return {"alpha": 0.5, "beta": 0.1}
print(getAlphaBeta(0.5, 0.1) # {alpha: 12, beta: 12}
You can verify the parameters $\alpha$ and $\beta$ by importing scipy.stats.beta
package.

- 101
- 2
-
2Thanks! I guess you should return {"alpha": alpha, "beta": beta} instead of {"alpha": 0.5, "beta": 0.1} – Yahia Jan 29 '20 at 18:15