Instructions

Please make sure your final output file is a pdf document. You can submit handwritten solutions for non-programming exercises or type them using R Markdown, LaTeX or any other word processor. All programming exercises MUST be done in R, typed up clearly and with all code attached. Submissions should be made on gradescope: go to Assignments \(\rightarrow\) Homework 4.

Questions

  1. Hoff problem 6.1

  2. Continuation of question 4 from homework 3. Suppose we have count data \(y_i\) with \((i = 1,\ldots, n)\), where \(x_i = 0\) for control subjects and \(x_i = 1\) for treated subjects. Consider the following model for the data: \[y_i \sim \textrm{Poisson}(\lambda \gamma^{x_i}),\] where \(\lambda = \mathbb{E}[y_i | x_i = 0]\) and \(\gamma\) is a multiplicative change in the mean in the treated group. Choose gamma priors for the parameters \(\lambda\) and \(\gamma\), \[\lambda \sim \textrm{Ga}(1,1),\ \ \ \gamma \sim \textrm{Ga}(1,1).\] You should already have the correct posterior density from homework 3.
    • Part (a): Show the exact steps involved in an algorithm for sampling from the posterior distribution for \(\lambda\) and \(\gamma\).
    • Part (b): Simulate data in which n = 100, with 50 in each group, where \(\lambda = \gamma = 1\), and generate samples from the posterior distribution for these data.
    • Part (c): Use your code to (i) estimate the posterior mean and a 95% credible interval for \(\textrm{log}(\lambda)\); and (ii) estimate the predictive distribution for subjects having \(x_i = 0\) and \(x_i = 1\). Are these predictive distributions different?
    • Part (d): Run convergence diagnostics – is your chain mixing well? What is the effective sample size? Does the mixing differ for \(\lambda\) and \(\gamma\)?

Grading

15 points.