STAT314/461 Semester 2, 2021
Assignment 5
Instructions
1. Total Marks: This assessment can be worth 10% of your final grade
(7.5% for STAT461 students). Remember, the best four of your assign-
ments will count for the internal component of your final grade. Note
that there is a “bonus question” worth 4 marks. You do not have to
complete this question for the assignment. However, if you do submit
the question, the marks from this question can be used to top-up your
mark from Questions 1 and 2, in the (unlikely) event that you don’t
quite get full marks for those questions. Otherwise, you can regard
the bonus question as practice, either to be done now or later during
revision for the exam.
2. Official due date: 11:55pm Friday October 2021;
3. While you are welcome and encouraged to discuss assignment problems
with other STAT314/461 students you must ultimately submit a docu-
ment that persuades the marker that you, individually, understand the
material.
Questions
1. Consider a Metropolis-Hastings algorithm that by iteration (t− 1) has
reached the point θa, i.e θ
(t−1) = θa.
Consider another point in the parameter space, θb which is such that
p(θ = θa|data)Jt(θb|θa) > p(θ = θb|data)Jt(θa|θb). (1)
where Jt(·|·) is an asymmetric density, so Jt(θb|θa) 6= Jt(θa|θb)
Write down an expression for the probability of the Metropolis-Hastings
sampler moving to θb at the t
th iteration, given that it is θa at iteration
(t− 1). The expression should involve only the posterior density (or the
unnormalised posterior density) and the jumping density (Hint: The
answer is not just Jt(θb|θa)!)
[ 3 marks ].
2. Suppose a survey of exercise habits is conducted and asks participants
about the number of days out of the last 7 that they have engaged in
moderate or vigorous exercise for 30 or more minutes. Let Y denote the
response (number of days). We consider that the survey respondents
1
are a mixture of “never-exercisers,” Z = 0, and occasional or regular
exercisers, Z = 1. However the survey asks only about the last 7 days
and not about regular or typical exercise habits. Consequently Z is not
directly observed. We adopt the model
[Z|φ] ∼ Bernoulli(φ)
[Y |Z = 1, θ] ∼ Binomial(θ, 7)
Pr(Y = 0|Z = 0, θ) = 1
and beta priors: φ ∼ beta(7, 3); θ ∼ beta(4, 6).
We let Y = (Y1, . . . , Yn)
′ and Z = (Z1, . . . , Zn)
′ and make the usual
conditional independence assumptions over individuals, so p(Z|φ) =∏n
i=1 p(Zi|φ) and p(Y|Zθ) =
∏
i p(Yi|Zi, θ) =
∏
i:Zi=1
p(Yi|Zi = 1, θ)
where the last equality follows because Y = 0 when Z = 0. Note also
that the model for Y depends on θ, whereas the model for Z depends
on φ but not θ.
(a) Derive an expression for the probability that a survey respondent
who reports no exercise in the last 7 days (Y=0) is, in fact, and
occasional or regular exerciser; i.e. derive an an expression for
Pr(Z = 1|Y = 0, φ, θ).
[ 3 marks ]
(b) The full conditional posterior distributions for the remaining pa-
rameters are
[φ|Y,Z, θ] ∼ Beta
(
7 +
n∑
i=1
Zi, 3 +
n∑
i=1
(1− Zi)
)
[θ|Y,Z, φ] ∼ Beta
(
4 +
∑
i:Zi=1
Yi, 6 +
∑
i:Zi=1
(7− Yi)
)
Using these full conditionals and your answer to part (a) imple-
ment a Gibbs sampler for this problem using the data in exercise.rds.The
implementation should involve multiple chains and some check for
convergence. You can use the shell programme exercise shellcode.r
to get started. The program reads in the data and a function for
convergence checking, GRchunk.r.
[ 4 marks ].
Bonus question Derive the full conditionals for θ and φ. i.e show the condi-
tional posteriors given above for φ and β are the correct conditional posterior
distributions for this problem.
[ 4 marks ].
2