BDA3 Chapter 2 Exercise 19

Here’s my solution to exercise 19, chapter 2, of Gelman’s Bayesian Data Analysis (BDA), 3rd edition. There are solutions to some of the exercises on the book’s webpage.

Let’s show that the gamma distribution is conjugate to the exponential distribution. That is, we suppose yθExp(θ) with prior θGamma(α,β), and show that the posterior is also gamma distributed.

The posterior is

p(θy)θneθn1yiθα1eβθ=θn+α1eθ(β+n1yi)

which implies θyGamma(α+n,β+n1yi).

Suppose now that we wish to do inference on ϕ:=θ1. We will show that ϕ has an inverse gamma distribution if θ has a gamma distribution. Indeed,

p(ϕ)p(θ)|dϕdθ|1=θα1eβθθ2=ϕα1eβϕ,

which corresponds to an InvGamma(α,β) distribution.

Suppose that the lifetime of a light bulb can be modelled as an exponential distribution with rate θ. Let’s compare inferences using the two different parameterisations above. For θGamma(α,β), the prior variance is αβ2 and the mean is αβ, so the prior coefficient of variation is α12. We are given that the prior coefficient of variation is 0.5, so α=4. The posterior coefficient of variation is (4+n)12. If we wish this to be at most 0.1, then we would need to test at least n=96 light bulbs.

For ϕInvGamma(α,β), the prior variance is

β2(α1)2(α2)

and the mean is βα1, so the prior coefficient of variation is (α2)12. With a prior coefficient of variation is 0.5, we have α=6. The posterior coefficient of variation is (6+n)12. If we wish this to be at most 0.1, then we would need to test at least n=94 light bulbs.