
ST740 – Assignment 3 – Due 9/29
1. MCMC for Bayesian density estimation: A common way to do density estimation
is to model the density as a mixture of normals. Assume the likelihood is a two-
component mixture
p(yi|µ0, µ1, τ0, τ1, π) = (1 −π)N(µ0, τ0) + πN(µ1, τ1),
where i= 1, ..., n,N(a, b) is the normal density with mean aand variance 1/b (this
parameterization is used throughout the assignment) and the priors are π∼Beta(1,1),
µ0, µ1∼N(0,0.01), and τ0, τ1∼Gamma(0.01,0.01), parameterized (this parameteriza-
tion is used throughout the assignment) to have mean 1 and variance 100. To make
the model fully-conjugate, we introduce the auxiliary variable giand rewrite the model
as
yi|gi, µ0, µ1, τ0, τ1∼N(µgi, τgi) and gi∼Bern(π),
where the remaining parameters have the same priors.
•Marginalize over gito verify that these models are indeed equivalent.
•Specify the full-conditional distributions of gi,π,µ0,µ1,τ0and τ1.
•Write MCMC code for this model. Turn in commented code.
•Generate a data set of size n= 1000 from the model p(y|rest)=0.5∗N(1,1) +
0.5∗N(5,0.1) and analyze it with your MCMC code. Submit a single plot with
a histogram of the data, the true density, and the posterior mean density (that
is, for each sample compute the density on a grid, and record the posterior mean
density at each grid location).
•Postulate a fully-conjugate model for a k > 2 component mixture of normals.
2. MCMC for the balanced one-way random effects model: The balanced one-
way random effects model is yij =µj+εij, where i= 1, ..., n is the replication number
within subject, j= 1, ..., m is the subject number, µj∼N(0, τ1), and εij ∼N(0, τ2).
Use the hyperpriors τ1, τ2∼Gamma(0.01,0.01).
•Specify the full-conditional distributions of µj,τ1, and τ2.
•Write MCMC code for this model. Turn in commented code.
•Analyze these data: first subject y1= (y11, ..., yn1)=(−3,−2,−1,0,1), second
subject y2= (4,5,6,7,8), third subject y3= (−1,0,0,0,1). Summarize the
posteriors of τ1,τ2, and r=τ2/τ1in a table and make a scatter plot of the
posterior draws of (τ1, τ2).
•Give a closed-form expression for p(τ1, τ2|y). Make a contour plot of p(τ1, τ2|y)
on a grid of (τ1, τ2). Does the contour plot resemble the scatter plot from the
previous question?
1