# Beta Distribution

Definition 1: For the binomial distribution the number of successes x is the random variable and the number of trials n and the probability of success p on any single trial are parameters (i.e. constants). Instead we would like to view the probability of success on any single trial as the random variable, and the number of trials n and the total number of successes in n trials as constants.

Let α = # of successes in n trials and β = # of failures in n trials (and so α + β = n). The probability density function (pdf) for x = the probability of success on any single trial is given by

This is a special case of the beta function

where Γ  is the gamma function.

Figure 1 – Beta Distribution

Excel Functions: Excel provides the following functions:

BETADIST(x, α, β) = the cumulative distribution function F(x) at x for the pdf given above.

BETAINV(p, α, β) = x such that BETADIST(x, α, β) = p. Thus BETAINV is the inverse of BETADIST.

Excel 2010/2013 provide the following two additional functions: BETA.INV which is equivalent to BETAINV and BETA.DIST(x, α, β, cum) where cum takes the value TRUE or FALSE and BETA.DIST(x, α, β, TRUE) = BETADIST(x, α, β) while BETA.DIST(x, α, β, FALSE) is the pdf of the beta distribution at x (as described above).

Example 1: A lottery organization claims that at least one out of every ten people wins. Of the last 500 lottery tickets sold 37 were winners. Based on this sample, what is the probability that the lottery organization’s claim is true: namely players have at least a 10% probability of buying a winning ticket? What is the 95% confidence interval?

To answer the first question we use the cumulative beta distribution function as follows:

This represents that organization’s claim is false (i.e. less than 10% probability of success). Thus the probability that the organization’s claim is true is 100% – 98.1% = 1.9%

The lower bound of the 95% confidence interval is

BETAINV(.025, 37, 463) = 5.3%

The upper bound of the 95% confidence interval is

BETAINV(.975, 37, 463) = 9.8%

Since 10% is not in the 95% confidence (5.3%, 9.8%), we conclude (with 95% confidence) that the lottery’s claim is not accurate.

### 24 Responses to Beta Distribution

1. R Singh says:

Hello there,
For some reason, the equations on all webpages are not displayed. May be some background maintenance is underway; just wanted to bring to your attention.
Thanks!

• Charles says:

Thanks for bringing this to my attention.
I don’t know why the equations were not displayed. I see that they are displayed now (at least on my computer).
Charles

2. Karl Buennagel says:

Nice job Charles. That is a sweet explanation. I saved the webpage. Thanks! If this is a book, I need a copy!

• Charles says:

Karl,
There will be a series of books shortly.
Charles

I am a little confused how Bayesian updating is carried out for the following set-up:

I have developed a logistic regression model which provides % probability of a 1 or 0. The 1 or 0 is then compared to what actually happened and a Beta Distribution is updated for each new success or failure which provides % probability of successes (1s).

I now which to use my Logistic Regression model which new data to provide a new % estimate of a 1. This in turn now needs to be updated with the previously calculated probability from the Beta distribution calculated on the previous time step.

How should I use Bayes to update the current Logistic regression probity with the actual % wins/losses? I am confused as which one is the prior and psoterior?

Thanks for the help.

• Charles says:

Sorry Adam, but I really don’t understand the scenario that you are describing.
Charles

• Anthony says:

I believe Adam was referring to how the Beta distribution is often used iteratively in Bayesian stats. It can be explained as the probability of probabilities. E.g. what are the chances of having a final sample mean of 0.3 if the current sample mean is 0.27 with 2 out of 9 iterations remaining.

The usual example is baseball, see http://varianceexplained.org/statistics/beta_distribution_and_baseball/, but your lottery example works.

In summary, if we approach the goal at a faster rate than expected then we are more likely to meet or exceed that goal. And if we fall behind the less likely we are to are to meet it.

• Charles says:

Anthony,
Charles

4. mitrananda says:

how the alpha and beta values are to be taken for a problem.
thank you

• Charles says:

For the problem described on the referenced webpage, α = # of successes in n trials and β = # of failures in n trials (and so α + β = n).
Charles

5. John Vanneck says:

Hi,

When there are 0 successes or n successes (out of n trials), the formula returns #NUM!

Do you have a work around for this? As in the situation where we had 100 trials and 0 successes we could safely assume that the probability of success was close to 0 – but this formula would not give an interval.

• John Vanneck says:

oops – I forgot to mention that I am talking about estimating confidence intervals using the beta.inv(p,alpha,beta) formula. Thank you

• Charles says:

John,

Note that BETA.DIST(p, s, n-s, True) = 1 – BINOM.DIST(s-1, n-1, p, True).

Thus, BETA.DIST(p, 0, 100, True) = 1 – BINOM.DIST(-1, 99, p, True).

This means that the problem you are addressing is equivalent to asking (the binomial distribution question) what is the probability of getting -1 successes in 99 trials (for any value of p = probability of success on any single trial)? This is clearly 0 with a confidence interval consisting only of the point zero. Thus the confidence interval you are looking for is [1,1], i.e. the point 1.

Charles

6. Rick says:

“Thus the probability that the organization’s claim is true is 100% – 98.1% = 1.9%”

This sure sounds like the inverse probability error.

Pr(.074 | π = .1) = .019
does not mean
Pr(π = .1 | .074) = .019

Would it not be better to say that obtaining p < 37/500 = .074 would occur only 1.9% of the time if the organization’s claim (H0: π = .1) were true?

Rick

• Charles says:

Rick,

While you are right to be cautious, I believe the logic used is correct.

Pr(π < .1 | # of successes in 500 trials = 37 and # of failures in 500 trials) = BETADIST(.1, 37, 463) = 98.1% Thus Pr(π >= .1 | # of successes in 500 trials = 37 and # of failures in 500 trials) = 1 – 98.1% = 1.9%

Charles

• Charles says:

Rick,

While you are right to be cautious, I believe the logic used is correct.

Pr(π < .1 | # of successes in 500 trials = 37 and # of failures in 500 trials) = BETADIST(.1, 37, 463) = 98.1% Thus Pr(π >= .1 | # of successes in 500 trials = 37 and # of failures in 500 trials) = 1 – 98.1% = 1.9%

Charles

7. Justin says:

Good and simple explanation of beta distribution compared to 99% sites I looked.Could you tell why we place (n-1)! in the numerator when the number of trials will always be an whole number.It might be certain to have (\alpha-1)! and (\beta-1)! in the denominator since and might be real numbers.Also why isn’t the power of x and (x-1) in the numerator \alpha and \beta instead of (\alpha-1) and (\beta-1) given in the expression?

• Charles says:

Justin,
The only time I need to use the beta distribution on the website is when the alpha and beta values are integers, although the beta distribution is used for many other purposes, including cases where the alpha and beta parameters are not integers. The distribution uses the gamma function. You see a number of instances of some integer minus 1. The reason for this is that Gamma(n) = (n-1)! when n is a positive integer.
Charles

• Richard says:

I like your derivation (whenever I have seen this done previously, it has been through repeated application of integration by parts on the cdf, and is much more complicated), but I have a similar problem to Justin. To go from the pdf
f(x) = n!/k!/(n-k)!*x^k*(1-x)^(n-k)
I would have to set a-1=k and b-1=n-k, which gives
f(x) = n!/(a-1)!/(b-1)!*x^(a-1)*(1-x)^(b-1)
and is therefore not the same as the first of your equations above (by a factor of n). Do you see where I’m going wrong?

• Charles says:

Richard,

First note that Gamma(m) = (m-1)! for any positive integer m. Thus for any positive integers alpha and beta, (alpha-1)! = Gamma(alpha) and (beta-1)! = Gamma(beta). Now let n = alpha + beta. Then (n-1)! = Gamma(n) = Gamma(alpha+beta).

Putting the pieces together yields (n-1)!/((alpha-1)!*(beta-1)!) = Gamma(alpha+beta)/(Gamma(alpha)*Gamma(beta)).

This is not the same thing as deriving the cdf from the pdf.

Charles

8. Rob says:

It appears a typo propagated in the examples, surely you did not mean 163 for β – that gives a P of ~.9999 of tickets being at least 10% winners.

Neat site, BTW.

Rob

• Charles says:

Hi Rob,
There is a typo. The value for beta should actually be 463 Thanks for catching the error. I have just made the corrections to the website.
Charles

9. m.r.sh says:

Hi PRO!
If α + β = n then 37+163=200 but in your example 1 “…Of the last 500 lottery tickets 37 were winners…”! are you sure this is true?!

• Charles says:

There is a typo. The value for beta should be 463. Thanks for catching the error. I have just made the corrections to the website.
Charles