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 shifted towards , since the flat prior adds one success and one failure to the data. 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 . Thus the sentence which was wrong for the confidence intervals of section 27.1 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 the update from example 28.5 one observation at a time. 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 misplaced prior , with mean and equivalent sample size . 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 two weak posteriors take their largest values at , since no successes have been observed so far, while the misplaced posterior has only moved from to around . At all three posteriors are humps, narrower than before. The two weak posteriors sit well below the truth after an unlucky start, and the misplaced one is closest to ; this shows how much the prior still matters after twenty observations, not that the misplaced prior is correct. At the two weak posteriors coincide and the misplaced posterior overlaps them: as the weight of the prior decreases, as discussed in example 28.5, every posterior concentrates near the truth.
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. After observations the prior is still noticeable, but after its influence is small.