TL;DR
Many questions ask for a single proportion: the share of visitors who click, the chance a coin lands heads, the fraction of a factory's parts that fail. The value is somewhere between 0 and 1, and you are never certain which value. The density of the Beta distribution describes how plausible each value in that range is. It has two settings, and , that set its shape, and it is the standard starting belief for a proportion because updating it with new counts keeps it in the same family.
Builds on: Probability Density Function, Gamma Function, Bernoulli Distribution, Prior Distribution · Leads to: Conjugate Prior, Dirichlet Distribution, Multi-Armed Bandit, Order Statistics
Where it's used
Testing two versions of a web page. A team shows a new button colour to visitors and records how many of them click. The unknown is the true click rate. A Beta belief over that rate, updated with each visit, tells the team how likely it is that the new colour beats the old one, and it stays honest when the sample is small.
Choosing among ads or recommendations. Ad and recommendation systems must decide which option to show while still learning which one works best. This is the multi-armed bandit problem. Many systems use a rule called Thompson sampling, where each option has a Beta belief about its success rate, the system draws one random value from each belief, and it shows the option with the largest draw. Options with uncertain beliefs sometimes win the draw and get tried. The idea is from William Thompson's 1933 paper on choosing between two treatments.
Quality control in manufacturing. A factory inspects 500 parts and finds 6 defective. Engineers often start from a Beta belief about the defect rate, because a rate is a proportion. Starting from a flat Beta(1, 1) prior, the 6 defects and 494 good parts give Beta(7, 495), a belief whose mean is about 1.4 percent. The update is just two additions, which keeps the reasoning simple when the inspection data are counts of pass and fail.
Order statistics. If you draw 5 numbers uniformly at random from and sort them, the third smallest (the median) follows a Beta(3, 3) distribution. This is a fact about the distribution of sorted values, not a belief, and it is one of the reasons the Beta family appears in the theory of Order Statistics.
How it works
Take one tiny instance from start to finish. We want the bias of a coin, which is the chance it lands heads. We know nothing, so every value of from 0 to 1 looks equally likely. We flip the coin three times and get heads, heads, tails.
- Start with the prior. The flat belief says every between 0 and 1 has the same height. That flat curve is the Beta(1, 1) distribution. Its area is 1, as every density's must be.
- Let each flip reweight the belief. If the coin's bias is , a head has chance and a tail has chance . So a value of that makes the observed flips likely should gain weight, and one that makes them unlikely should lose it. Check: for heads, the weight is ; if , a head is likely, so the weight is high. For tails, the weight is .
- Multiply the flips together. Two heads and one tail give the weight . Check: at this is 0 (heads are impossible if the coin never lands heads), and at it is also 0 (a tail was seen).
- Rescale so the area is 1 again. The area under between 0 and 1 is the area under minus the area under : . Dividing by , that is multiplying by 12, gives the density . Check: the area of is 1.
- Read off the result. This curve is the Beta(3, 2) distribution. Its peak is at , its average is , and it is zero at both ends. The belief has moved toward heads, but not all the way, because three flips is little evidence.
- prior Beta(1, 1)
- after HHT: Beta(3, 2)
The math
Definition
For settings and , a random value between 0 and 1 is Beta distributed, written , if its density is
where the normalising constant is
The mean is and the variance is .
Here is the . The constant is the area under the bare shape , and dividing by it makes the total area 1. The settings and play the role of counts: acts like the number of successes and like the number of failures.
Step 1 in symbols: the prior
With , the density is . Since , the density is 1 on . This is the flat prior from the walkthrough, which is also the uniform distribution on .
Step 2 in symbols: the likelihood
Suppose a coin with bias gives heads and tails in flips. Each flip is a Bernoulli trial, and the flips are independent, so the probability of this exact sequence is
This is the likelihood: a function of for the data we saw.
Step 3 in symbols: multiply
Bayes' rule (see Bayes' Rule) says the posterior is proportional to prior times likelihood. For a Beta prior ,
The product has the same form as a Beta density, with the new settings and . This is why the Beta is the standard prior for proportions: the update never leaves the family.
Step 4 in symbols: rescale
The product needs dividing by its area, which is . So the posterior is
For the coin in the walkthrough, , and , so the posterior is Beta(3, 2). This agrees with the direct calculation , since .
Mean and mode
The mean follows from the rule . Write the mean as an integral, , and note that multiplying the bare shape by turns into . So the integral is :
For , the peak (the mode) is found by setting the derivative of the log density to zero: , which gives .
Worked examples
- The settings are and , so the density is .
- , so .
- Check the area: . The density is valid.
- The chance that is at most is the area from 0 to 0.5: .
- The mean is , which is about . The density rises straight up from 0, so values near 1 are more likely than values near 0, and the mean sits above the midpoint.
- Start with the flat prior .
- Observe 7 heads and 3 tails. The posterior is .
- The mean is .
- The mode is . The peak is a little above the mean, because the curve has a longer tail toward 0.
- The variance is , so the standard deviation is .
- Read the result: the best single guess is about 0.67, and two standard deviations either side of the mean gives a range of roughly 0.41 to 0.93. Ten flips leave a wide belief, which is the honest answer.
A team sends a new subject line to 400 people, and 120 open the email. They start from the flat prior .
- The posterior is . The number of non-opens is .
- The mean open rate is , about 30.1 percent.
- The variance is , so the standard deviation is .
- Read the result: the open rate is about 30 percent, give or take about 2.3 percentage points. That spread is small because 400 people is a decent sample.
Try it: a second subject line is sent to 100 people and 30 open it. Start from the flat prior, find the posterior, and compute its mean. Answer: the posterior is , and its mean is . The two lines look about equal, and the belief is much wider for the second one, because 100 people tell you less than 400.
Common mistakes and tradeoffs
It is tempting to think that the mean of is . In fact it is , because and are weighted together. Beta(3, 1) has mean , not 3.
It is tempting to think that means "I saw 8 heads and 4 tails." In fact, with a flat prior, the observed counts are and , because the prior already contributed one of each. The settings are the observed counts only when the prior is .
It is tempting to think that a density value is a probability. In fact a density can be larger than 1. The density peaks at about 1.9. Probabilities come from areas under the curve, not from heights.
When to use it. Use the Beta when the unknown is a proportion or a probability between 0 and 1, and the data are yes-or-no counts. It is the natural prior for a Bernoulli or binomial rate, and its update rule is simple.
When not to use it. If the unknown is not confined to , the Beta does not apply. If there are more than two categories, use the Dirichlet distribution, which is the Beta's generalisation to several shares. If the prior should encode strong, specific knowledge that is not Beta-shaped, a different prior is better, and a Beta can still be used as an approximation.
Alternatives. For large samples, a plain normal approximation to the sample proportion is often enough. For a fully general posterior, sampling methods such as Markov Chain Monte Carlo can handle any prior at the cost of computation.
History
In 1763 Thomas Bayes's essay, published after his death, worked out the posterior for a success rate under a flat prior. That is the Beta(1,1) update in this lesson, although the Beta family was not yet named. In the 1700s, mathematicians including Euler studied the integral that defines the beta function, the constant in this lesson.
In the 1890s, Karl Pearson included a Beta-shaped family in his system of frequency curves, which gave the distribution its modern place in statistics. Its use as a prior grew through the twentieth century as Bayesian methods spread. The idea of the conjugate prior, which the Beta has for binomial data, was made systematic for decision analysis in the 1960s. The Beta then became the default prior for proportions in tools such as A/B testing and bandit algorithms.
Recap
- A Beta distribution describes a belief about one proportion between 0 and 1, with settings and that set its shape.
- Its density is divided by , which makes the area 1. Its mean is .
- A Beta prior updated with successes and failures becomes . The update stays in the family, which is why it is the standard prior for proportions.
- Its generalisation to several shares is the Dirichlet distribution, and its update is the basis of conjugate priors.
- Read next: Multi-Armed Bandit, where Beta beliefs drive exploration, and Order Statistics, where the Beta arises from sorted uniform draws.
Check yourself
QuestionWhich distribution is Beta(1, 1)?Show answer
It is the uniform distribution on . The density is , which is flat, so every value between 0 and 1 is equally plausible.
QuestionA belief about a rate is Beta(3, 1). What is the chance the rate is at most 0.5? Give a number.Show answer
The density is , since . The chance of being at most is . Answer: 0.125.
QuestionWhy does the update from a Beta prior to a posterior never need a new family of curves?Show answer
The likelihood for successes and failures is . Multiplying it by the prior adds the exponents: . That is the same form as a Beta density with settings and , so only the two settings change.
QuestionA team has tested 50 visitors on a page and 10 clicked. With a flat prior, what is the posterior mean click rate, and why is it not simply 10 out of 50?Show answer
The posterior is , and its mean is . The raw rate is . The flat prior adds one imagined click and one imagined non-click, which pulls the estimate slightly toward one half. With small samples this shrinkage keeps the estimate from jumping around, and with large samples the difference disappears.