Lecture 30 Confidence Versus Credibility
This is the R session for week 10. In lectures this week we have introduced priors, posteriors and credible intervals. In this session we compute a confidence interval and a credible interval for the same data, and we look at how a prior turns into a posterior as observations are added. As before, appendix B contains a written reference for the R commands used.
30.1 The Same Data, Two Intervals
We take the data of example 26.9, successes in Bernoulli trials, and compute two intervals for the success probability . The first is the Wald interval of that example. For the second we use the Bayesian model of lecture 28 with the flat prior: the posterior is by example 28.5, and the interval between its and quantiles is the equal-tailed credible interval with credibility from definition 29.1. The command qbeta can be used to find these quantiles. Before you run the code, predict whether the credible interval will be wider or narrower than the Wald interval, and whether it will sit to the left or to the right of it.
The two intervals, and , agree to within . The credible interval is slightly narrower and is shifted towards , since the flat prior acts like one additional success and one additional failure. Although the numbers are close, the two statements are different. The Wald interval comes with the guarantee that the recipe used to compute it covers the truth in approximately of samples, and it makes no statement about this particular interval. The credible interval means that, given the observations and the flat prior, the probability that lies between and is . A sentence of this form, “ lies in the computed interval with probability ”, was wrong for the confidence intervals of section 27.1. It is the correct interpretation here, since is a random variable in the Bayesian model. A different prior would give a different interval, and the numerical agreement is a property of the flat prior and of the sample size.
30.2 From Prior to Posterior
We now look at how the posterior from example 28.5 changes as observations are added. In the script R/S30-posterior.R we simulate Bernoulli observations with . After observations with successes, the prior has turned into the posterior , and we plot this posterior density for three priors: the flat prior , the Jeffreys prior from example 28.10 and the informative prior . The last prior has mean and equivalent sample size , and thus is centred far from the true value. In the simulated sequence, the first five observations are all failures, there are successes among the first and among all . Before you look at figure 30.1, sketch the panel for : which curves are steep, where are their peaks and how wide are the curves?

At the three curves in figure 30.1 are the priors, and we can see that the Jeffreys prior is not flat. At the posteriors for the flat prior and for the Jeffreys prior take their largest values at , since no successes have been observed so far, while the posterior for the informative prior has only moved from to around . At all three posteriors are humps, narrower than before. After an unlucky start, the first two posteriors sit well below the true value, and the third is closest to . This shows how much the prior still matters after twenty observations, not that the informative prior was a good choice. At the first two posteriors coincide and the third overlaps them: the weight of the prior has decreased, as discussed in example 28.5, and every posterior is concentrated near the true value.
30.3 A Task to Take Home
For the data of section 30.1, compute the equal-tailed credible interval with credibility under the prior from section 30.2, and compare it with the two intervals found there. Then compute all three intervals for successes in trials. Write a short paragraph about how the influence of the prior depends on the sample size.
After the session, you should type the commands used in this session, and should check that you get the same results as the text.
-
•
The written reference for the commands used in this session is appendix B.
-
•
For the same Bernoulli data, the Wald interval and the credible interval with flat prior agree to within , but they are different statements: the credible interval is a probability statement about , conditioned on the data and on the prior, and thus depends on the prior.
-
•
The Beta posterior becomes sharper as observations are added. In the simulated sequence the prior is still noticeable after observations, but after its influence is small.