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 3 (360) for students in STA 360 and Homework 3 (602) for students in STA 602.

Questions

  1. Hoff problem 6.1
    • Part (a): Students in STA 360: 1 point; Students in STA 602: 1 point
    • Part (b): Students in STA 360: 2 points; Students in STA 602: 1.5 points
    • Part (c): Students in STA 360: 2 points; Students in STA 602: 1.5 points
    • Part (d): Students in STA 360: 3 points; Students in STA 602: 2 points
  2. 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).\]
    • Part (a): Is the joint posterior for \(\lambda\) and \(\gamma\), that is, \(\pi(\lambda,\gamma | X, Y)\), conjugate? Why or why not?
      (Students in STA 360: 4 points; Students in STA 602: 3 points)
    • Part (b): Derive the full conditional distributions for \(\lambda\) and \(\gamma\).
      (3 points for all students)
    • Part (c): 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.
      (2 points for all students)
    • Part (d): 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?
      (2 points for all students)
    • Part (e): Run convergence diagnostics – is your chain mixing well? What is the effective sample size? Does the mixing differ for \(\lambda\) and \(\gamma\)?
      (1 point for all students)
  3. Rejection sampling.
    (Not graded for students in STA 360; you can attempt for practice but you don’t need to submit. Graded for students in STA 602)
    Recall from class that the idea of rejection sampling is to create an importance/proposal/envelope function which is greater than or equal to the distribution we wish to sample from at all points, and which we can sample from easily. Suppose we end up with the following form for our posterior: \[f(\theta) \propto sin^2(\pi \theta), \ \ \ \theta \in [0,1],\] where \(\pi = 3.141593\). This density looks like:
    • Part (a): Implement a rejection sampler in R to sample from this density using a Unif(0,1) density as your proposal function, since it is greater than or equal to the given density (up to proportionality) at all points and is easy to sample from. Provide a plot of your sampled values.
      (1 point for all students)
    • Part (b): Propose a different envelope function and implement a rejection sampler for it in R. How does the efficiency of your envelope function compare to the uniform envelope function? Provide plots (histograms or density estimates) of the samples from the two approaches.
      (2 points for all students)

Grading

20 points.