BDA3 Chapter 3 Exercise 1

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

Let yθMultinomialJ(θ) with prior θDirichletJ(α). We would like to find the marginal distribution of ϕ:=θ1θ1+θ2.

Marginal posterior of Dirichlet-multinomial

As shown in the book, the posterior is θyDirichlet(y+α). The marginal posterior of (θ1,θ2)y can be written as

p(θ1,θ2y)=10p(θy)dθ3dθJ1θy1+α111θy2+α21210θy3+α313θyJ1+αJ11J1(1J11θj)yJ+αJ1dθ3dθJ1.

The tricky part is calculating the integral part, which we define

I:=10θy3+α313θyJ1+αJ11J1(1J11θj)yJ+αJ1dθ3dθJ1.

To calculate I, first note that

10θs(cθ)tdθ=10θs(1θc)tctdθ=10(θc)s(1θc)tcs+tdθ=10ϕs(1ϕ)tcs+t+1dϕ,ϕ:=θc=B(s+1,t+1)cs+t+1,

if c is not a function of θ. With c:=1J21θj,

I=10θy3+α313θyJ2+αJ21J2θyJ1+αJ11J1(1J21θjθJ1)yJ+αJ1dθ3dθJ1=10θy3+α313θyJ2+αJ21J2(10θyJ1+αJ11J1(cθJ1)yJ+αJ1dθJ1)dθ3dθJ210θy3+α313θyJ2+αJ21J2(c)yJ1+yJ+αJ1+αJ1dθ3dθJ2=10θy3+α313θyJ2+αJ21J2(1J21θj)yJ1+yJ+αJ1+αJ1dθ3dθJ2.

Continuing by induction,

I=(1θ1θ2)J3(yj+αj)1.

Now that we have the integral part, the marginal posterior can be written

p(θ1,θ2y)θy1+α111θy2+α212(1θ1θ2)J3(yj+αj)1.

This has the form of a Dirichlet distribution, so the marginal posterior is

(θ1,θ2,1θ1θ2)yDirichlet(y1+α1,y2+α2,J3(yj+αj)).

Change of variables

Now define (ϕ1,ϕ2):=(θ1θ1+θ2,θ1+θ2), so that (θ1,θ2)=(ϕ1ϕ2,ϕ2ϕ1ϕ2). The Jacobian of this transformation is

|θ1ϕ1θ1ϕ2θ2ϕ1θ2ϕ2|=|ϕ2ϕ1ϕ21ϕ1|=ϕ2.

Therefore, the probability distribution of the new variables is

p(ϕ1,ϕ2y)=(ϕ1ϕ2)y1+α11(ϕ2(1ϕ1))y2+α21(1ϕ2)J3(yj+αj)11ϕ2=ϕy1+α111(1ϕ1)y2+α21ϕy1+y2+α1+α232(1ϕ2)J3(yj+αj)1=p(ϕ1y)p(ϕ2y),

where

ϕ1yBeta(y1+α1,y2+α2)ϕ2yBeta(y1+y2+α1+α22,J3(yj+αj)).

The marginal posterior for ϕ1 is equivalent to the posterior obtained from a ϕ1Beta(α1,α2) prior with a y1ϕ1Binomial(y1+y2,ϕ1) likelihood.