BDA3 Chapter 5 Exercise 7

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

Part a

Suppose yθPoisson(θ) with prior θGamma(α,β). Let’s derive the expectation and variance of y. Using equation 1.8 (page 21), the expectation is

E(y)=E(E(yθ))=E(θ)=αβ.

Using equation 1.9 (page 21), the variance is

V(y)=E(V(yθ))+V(E(yθ))=E(θ)+V(θ)=αβ+αβ2=α1+ββ2.

Part b

Suppose yμ,σNormal(μ,σ) with prior p(μ,σ2)σ2. Then the expectation of μy is

E(μy)=E(E(μσ2,y)y)=E(ˉyy)=ˉy.

For posterior expectations, we condition on the data, which allows us to treat y, n, and s as constants. Since θ:=n(μˉy)/s is a linear function of μ, its posterior expectation is zero. For this to hold, it is necessary that n2 for s to be well-defined (to avoid division by zero). Moreover, the first identity implicitly assumes that the expectation E(uy) is well-defined. Combining the calculation of p(μy) with this proof shows that it is well-defined only when n3.

The posterior variance is

V(ns(μˉy)y)=E(V(ns(μˉy)σ2,y)y)+V(E(ns(μˉy)σ2,y)y)=E(ns2V(μσ2,y)y)+V(0y)=E(ns2σ2ny)+0=n1n3.

Since n3 appears in the denominator, it is necessary that n4. Again, for the first identity to hold, it is implicitly assumed that the variance on the left hand side is finite. It can be verified that the variance is finite for n4.