Unit 10, lesson 72

Bayesian Estimation and Credible Intervals

How a beta prior and a binomial likelihood give a beta posterior for a success probability, how the posterior mean and median summarize it, and what an equal-tailed credible interval says and does not say.

  • Video 72
  • Bayesian Inference

Ten participants each attempt a task once with a new instruction card, and seven succeed. The sample proportion is 0.70.7, but ten trials leave real doubt about the success probability pp behind them. In the previous lesson the unknown rate could take only a few listed values. Here pp may be any number between 00 and 11, so the prior and the posterior become distributions on that whole interval. This lesson uses the beta family to update such a distribution, summarizes the result, and shows how to read a credible interval. The data are constructed for teaching, and the model assumes that the ten attempts are independent given pp and share the same pp.

Key terms

Beta distribution

Definition Let α>0\alpha > 0 and β>0\beta > 0 be two shape parameters. A quantity pp with values in the interval (0,1)(0, 1) has the beta distribution Beta⁡(α,β)\operatorname{Beta}(\alpha, \beta) if it has the density

f(p)=pα−1(1−p)β−1B(α,β)f(p) = \frac{p^{\alpha - 1}(1 - p)^{\beta - 1}}{B(\alpha, \beta)}

for 0<p<10 < p < 1, where the constant B(α,β)B(\alpha, \beta) is the area under pα−1(1−p)β−1p^{\alpha - 1}(1 - p)^{\beta - 1} over (0,1)(0, 1), so that the total area is 11. For whole numbers it equals (α−1)! (β−1)!/(α+β−1)!(\alpha - 1)!\,(\beta - 1)!/(\alpha + \beta - 1)!. The mean and variance are

E(p)=αα+β,Var⁡(p)=E(p)(1−E(p))α+β+1.\begin{aligned} E(p) &= \frac{\alpha}{\alpha + \beta}, \\[0.4em] \operatorname{Var}(p) &= \frac{E(p)\bigl(1 - E(p)\bigr)}{\alpha + \beta + 1}. \end{aligned}

As for every density, probabilities are areas under the curve, and the height of the curve is not a probability.

In plain words The beta family is a flexible set of curves on the interval from 00 to 11, which makes it a natural way to describe uncertainty about an unknown probability. The shape parameters are not the probability itself. They set where the curve puts its weight. With α=β=1\alpha = \beta = 1 the curve is flat. Equal parameters give a curve symmetric about 12\tfrac12, more concentrated the larger they are, and a larger α\alpha relative to β\beta moves the mean toward 11.

Example For Beta⁡(2,2)\operatorname{Beta}(2, 2) the constant is B(2,2)=1! 1!/3!=1/6B(2, 2) = 1!\,1!/3! = 1/6, so the density is 6p(1−p)6p(1 - p). Its mean is 12\tfrac12 and its variance is 12⋅12/5=1/20\tfrac12 \cdot \tfrac12 / 5 = 1/20. Its cumulative distribution function is 3p2−2p33p^2 - 2p^3, so the probability that pp lies between 0.40.4 and 0.60.6 is 0.648−0.352=0.2960.648 - 0.352 = 0.296. The density reaches 1.51.5 at p=12p = \tfrac12. That height is larger than 11, yet every probability, being an area, stays between 00 and 11.

Beta-binomial conjugacy

Definition Suppose that, given pp, the number YY of successes in nn trials is Binomial⁡(n,p)\operatorname{Binomial}(n, p), as it is when the trials are independent given pp and each succeeds with probability pp. Write π(p)\pi(p) for the prior density and π(p∣y)\pi(p \mid y) for the posterior density. If the prior is Beta⁡(α,β)\operatorname{Beta}(\alpha, \beta) and yy successes are observed, with 0≤y≤n0 \le y \le n, then the posterior density is proportional to the likelihood times the prior density,

π(p∣y)∝py(1−p)n−y π(p)∝pα′−1(1−p)β′−1,\begin{aligned} \pi(p \mid y) &\propto p^{y}(1 - p)^{n - y}\,\pi(p) \\[0.4em] &\propto p^{\alpha' - 1}(1 - p)^{\beta' - 1}, \end{aligned}

where

α′=α+y,β′=β+n−y.\begin{aligned} \alpha' &= \alpha + y, \\[0.4em] \beta' &= \beta + n - y. \end{aligned}

The binomial coefficient (ny)\binom{n}{y} does not depend on pp and is absorbed into the normalizing constant. The only density with this shape is a beta density, so the posterior is Beta⁡(α′,β′)\operatorname{Beta}(\alpha', \beta'), that is, Beta⁡(α+y,β+n−y)\operatorname{Beta}(\alpha + y, \beta + n - y). A family of priors is called conjugate to a likelihood when the posterior always stays in the same family, and the beta family is conjugate to the binomial likelihood.

In plain words Each success adds 11 to the first shape parameter and each failure adds 11 to the second. Conjugacy turns the update into addition. It does not show that the binomial model fits the data or that the prior is a good one, and those still have to be argued.

Example With the Beta⁡(2,2)\operatorname{Beta}(2, 2) prior and 77 successes in 1010 trials, the posterior density is proportional to p1+7(1−p)1+3=p8(1−p)4p^{1 + 7}(1 - p)^{1 + 3} = p^{8}(1 - p)^{4}. Shape parameters are one more than the exponents, so the posterior is Beta⁡(9,5)\operatorname{Beta}(9, 5), not Beta⁡(8,4)\operatorname{Beta}(8, 4). Updating in batches gives the same answer under the same model. If the first 66 attempts contain 44 successes, the prior becomes Beta⁡(6,4)\operatorname{Beta}(6, 4), and the remaining 44 attempts with 33 successes turn that into Beta⁡(9,5)\operatorname{Beta}(9, 5). Recording the order of the outcomes instead of only the count changes the likelihood by a constant factor and leaves the posterior unchanged.

Posterior mean

Definition The posterior mean E(p∣y)E(p \mid y) is the mean of the posterior distribution. For the Beta⁡(α+y,β+n−y)\operatorname{Beta}(\alpha + y, \beta + n - y) posterior it is

E(p∣y)=α+yα+β+n.E(p \mid y) = \frac{\alpha + y}{\alpha + \beta + n}.

For n≥1n \ge 1 it is a weighted average of the prior mean and the sample proportion p^=y/n\hat{p} = y/n,

E(p∣y)=(1−w) αα+β+w p^,\begin{aligned} E(p \mid y) &= (1 - w)\,\frac{\alpha}{\alpha + \beta} \\[0.4em] &\quad + w\,\hat{p}, \end{aligned}

with weight w=n/(α+β+n)w = n/(\alpha + \beta + n) on the data. So it lies between the prior mean and p^\hat{p}, and for a fixed prior the weight on p^\hat{p} approaches 11 as nn grows. Among all single-number estimates of pp, the posterior mean gives the smallest posterior expected squared error.

In plain words The posterior mean is the prior’s center pulled toward the observed proportion, and more data pull harder. In this formula the sum α+β\alpha + \beta plays the part of a number of trials, which is why the shape parameters are sometimes called prior successes and failures. That reading is a convention for this summary, not a record of past data. The parameters need not be whole numbers, and other summaries suggest other counts. Lying between the prior mean and p^\hat{p} is a fact about the estimate, and the true pp may lie outside that range.

Example For the Beta⁡(9,5)\operatorname{Beta}(9, 5) posterior, E(p∣y)=9/14≈0.6429E(p \mid y) = 9/14 \approx 0.6429. The weight on the data is w=10/14w = 10/14, and

914=414⋅12+1014⋅710.\frac{9}{14} = \frac{4}{14} \cdot \frac{1}{2} + \frac{10}{14} \cdot \frac{7}{10}.

The posterior standard deviation is 3/196≈0.124\sqrt{3/196} \approx 0.124, a reminder that the single number 0.64290.6429 leaves plenty of uncertainty.

Posterior median

Definition A posterior median of pp is a value mm with P(p≤m∣y)≥12P(p \le m \mid y) \ge \tfrac12 and P(p≥m∣y)≥12P(p \ge m \mid y) \ge \tfrac12. The cumulative distribution function FF of a beta posterior is continuous and strictly increasing on [0,1][0, 1], so the posterior median is the unique mm with F(m)=12F(m) = \tfrac12. Except in special cases it has no simple formula and is found numerically. Among all single-number estimates of pp, the posterior median gives the smallest posterior expected absolute error.

In plain words Half the posterior probability lies below the median and half above it. For a symmetric posterior the median and the mean coincide. For a skewed posterior they usually differ, and neither one shows how spread out the posterior is.

Example For Beta⁡(9,5)\operatorname{Beta}(9, 5) a numerical quantile routine gives the median m≈0.6498m \approx 0.6498, slightly above the mean 0.64290.6429. The posterior is skewed, with a longer tail toward 00, and its peak is at 8/12=2/38/12 = 2/3, so the mean, the median and the peak appear in that order from left to right. For a symmetric posterior such as Beta⁡(5,5)\operatorname{Beta}(5, 5) all three equal 12\tfrac12.

Credible interval

Definition Let 0<c<10 < c < 1. A credible interval for pp at level cc is an interval [a,b][a, b] whose posterior probability is cc,

P(a≤p≤b∣y)=c.P(a \le p \le b \mid y) = c.

The probability is computed from the posterior distribution, so it is conditional on the likelihood model, the prior and the observed data. Many intervals have the same posterior probability, so a report should name its construction. Two common ones are the equal-tailed interval of the next card and the highest posterior density interval, which keeps every value whose posterior density is above a cutoff. For a posterior density with a single peak, the highest posterior density interval is the shortest interval with probability cc. A credible interval is defined differently from a confidence interval. A 95 percent confidence procedure is built to cover each fixed value of pp in 95 percent of repeated samples, exactly or approximately, while a credible interval is a probability statement about pp given the data, and the procedure that produces it need not have 95 percent coverage at every pp.

In plain words Given the model, the prior and the data, the posterior assigns probability cc to the event that pp lies in the interval. The interval describes uncertainty about the parameter. Individual outcomes are 00 or 11 and do not spread across the interval. A different prior or a different model usually gives a different interval.

Example For the Beta⁡(9,5)\operatorname{Beta}(9, 5) posterior the interval [0.3857,0.8614][0.3857, 0.8614], constructed in the next card, has posterior probability 0.950.95. The same posterior answers other questions directly, for example P(p>0.5∣y)≈0.8666P(p > 0.5 \mid y) \approx 0.8666, which is a posterior probability about pp and not a p-value. The 95 percent Wilson confidence interval for 77 successes in 1010 trials is about [0.397,0.892][0.397, 0.892], close in its numbers but a statement about a procedure. Coverage is a separate question. With n=10n = 10, the 95 percent equal-tailed procedure under this Beta⁡(2,2)\operatorname{Beta}(2, 2) prior covers p=0.5p = 0.5 in about 97.997.9 percent of samples, but if the true pp were 0.050.05 it would cover it only when y=0y = 0, which has probability 0.9510≈0.5990.95^{10} \approx 0.599.

Equal-tailed credible interval

Definition Let FF be the cumulative distribution function of a continuous posterior, and for 0<u<10 < u < 1 let the posterior quantile quq_u be a value with F(qu)=uF(q_u) = u. The equal-tailed credible interval at level cc is [q(1−c)/2,q(1+c)/2][q_{(1 - c)/2}, q_{(1 + c)/2}]. At level 0.950.95 its endpoints solve

F(q0.025)=0.025,F(q0.975)=0.975,\begin{aligned} F(q_{0.025}) &= 0.025, \\[0.4em] F(q_{0.975}) &= 0.975, \end{aligned}

so posterior probability 0.0250.025 lies below the interval and 0.0250.025 above it. For a beta posterior the quantiles are unique, and they are usually found with a numerical quantile routine. When the posterior is skewed, the equal-tailed interval generally differs from the highest posterior density interval, and it can contain values of lower density than some values it leaves out.

In plain words Cut off half of the remaining posterior probability 1−c1 - c at each end and keep the middle, so a 95 percent interval leaves out 2.52.5 percent at each end. The rule is easy to state and to compute, and the interval always contains the median. Equal tails do not mean equal distances from the center.

Example For Beta⁡(9,5)\operatorname{Beta}(9, 5) the quantiles are q0.025≈0.3857q_{0.025} \approx 0.3857 and q0.975≈0.8614q_{0.975} \approx 0.8614. Conditional on the binomial model, the Beta⁡(2,2)\operatorname{Beta}(2, 2) prior and the seven successes, pp lies between these endpoints with posterior probability 0.950.95, up to rounding of the endpoints. The lower endpoint is 0.26410.2641 below the median and the upper endpoint only 0.21160.2116 above it, because of the skew. The highest posterior density interval is about [0.4013,0.8737][0.4013, 0.8737], slightly shorter, with width 0.47240.4724 against 0.47570.4757. The density is about 0.4490.449 at the lower equal-tailed endpoint and 0.7200.720 at the upper one, so the equal-tailed interval keeps some values near 0.390.39 while leaving out values just above 0.86140.8614 that have higher density.

Check yourself

  1. Keep the Beta⁡(2,2)\operatorname{Beta}(2, 2) prior, but suppose the ten attempts give 33 successes and 77 failures. Find the posterior, its mean, its median and its 95 percent equal-tailed credible interval, using the results for Beta⁡(9,5)\operatorname{Beta}(9, 5) above. What does the interval describe?
Show the answer

Three successes add 33 to the first parameter and seven failures add 77 to the second, so the posterior is Beta⁡(5,9)\operatorname{Beta}(5, 9) with mean 5/14≈0.3575/14 \approx 0.357. If pp has the Beta⁡(9,5)\operatorname{Beta}(9, 5) distribution, then 1−p1 - p has the Beta⁡(5,9)\operatorname{Beta}(5, 9) distribution, so the new posterior is the old one reflected about 12\tfrac12. The median is about 1−0.6498=0.35021 - 0.6498 = 0.3502, and the interval endpoints are reflected and swapped, giving about [1−0.8614,1−0.3857]=[0.1386,0.6143][1 - 0.8614, 1 - 0.3857] = [0.1386, 0.6143]. The interval describes uncertainty about the common success probability pp. It is not a range for individual outcomes, each of which is 00 or 11.

  1. A report on the original data says that the 95 percent credible interval [0.386,0.861][0.386, 0.861] means two things. If the study were repeated many times, 95 percent of such intervals would contain pp, and about 95 percent of future participants will have outcomes in this range. Correct both claims and state what the interval does mean.
Show the answer

The interval means that, given the binomial model, the Beta⁡(2,2)\operatorname{Beta}(2, 2) prior and the observed 77 successes in 1010 trials, the posterior probability that pp lies between 0.3860.386 and 0.8610.861 is about 0.950.95. The first claim describes confidence coverage, a property of a procedure over repeated samples, and a credible procedure does not guarantee it. With this prior and n=10n = 10, the equal-tailed procedure would cover a true pp of 0.050.05 only about 60 percent of the time. The second claim confuses the parameter with the outcomes. Each future outcome is 00 or 11, so none of them falls inside [0.386,0.861][0.386, 0.861], and a statement about future outcomes needs a predictive distribution.

  1. With a flat Beta⁡(1,1)\operatorname{Beta}(1, 1) prior, five attempts that are independent given pp all fail. Find the posterior, its mean and median, the 95 percent equal-tailed credible interval and the 95 percent highest posterior density interval. Use the fact that the posterior cumulative distribution function is F(p)=1−(1−p)6F(p) = 1 - (1 - p)^6. Why do the two intervals differ?
Show the answer

The posterior is Beta⁡(1,6)\operatorname{Beta}(1, 6), with density 6(1−p)56(1 - p)^5 and mean 1/7≈0.1431/7 \approx 0.143. Solving F(m)=12F(m) = \tfrac12 gives the median m=1−0.51/6≈0.109m = 1 - 0.5^{1/6} \approx 0.109. The equal-tailed endpoints solve 1−(1−q)6=0.0251 - (1 - q)^6 = 0.025 and 1−(1−q)6=0.9751 - (1 - q)^6 = 0.975, so

q0.025=1−0.9751/6,q0.975=1−0.0251/6,\begin{aligned} q_{0.025} &= 1 - 0.975^{1/6}, \\[0.4em] q_{0.975} &= 1 - 0.025^{1/6}, \end{aligned}

which are about 0.00420.0042 and 0.45930.4593. The density 6(1−p)56(1 - p)^5 is largest at p=0p = 0 and decreases, so the highest posterior density interval starts at 00 and ends where the probability reaches 0.950.95, at 1−0.051/6≈0.39301 - 0.05^{1/6} \approx 0.3930. That interval, [0,0.3930][0, 0.3930], is shorter than the equal-tailed interval [0.0042,0.4593][0.0042, 0.4593]. The equal-tailed rule must leave 2.52.5 percent of the probability below its lower endpoint, so it excludes the values near 00 where the density is highest. Both intervals have posterior probability 0.950.95, which is why a report should say which construction it used. Five failures also do not show that p=0p = 0. The posterior probability that pp exceeds 0.10.1 is 0.96≈0.530.9^6 \approx 0.53.

How this lesson connects