Probability and Statistics: Assignment 8

Please remember to do your homework completely in RMarkdown!

  1. In class we proved that if we use a Bernoulli likelihood with a Beta prior, the posterior is also Beta. Suppose now we have two coins and we want to infer their biases, \(\theta_1\) and \(\theta_2\). Follow a similar line of reasoning to show that, with (independent) Beta priors, the posterior consists also of independent Beta distributions. You can submit this problem on paper if you want, but, on the other hand, it’s a good opportunity to learn a little LaTeX. I can give you assistance if you want to try.

  2. I provided a function called bern_beta() for the one coin, Bernoulli likelihood, Beta prior problem. Modify this function to make a new function, bern_beta_beta(), for the two coin problem. Then use it to solve the problem illustrated in Figure 7.5. In fact, your code should reproduce the result shown in Figure 7.5. You don’t have to reproduce the left-hand column that contains the three dimensional density plots, but, if you do, it will be good for some extra credit. The right-hand column contains the corresponding (two-dimensional) contour plots. To get these, you need to modify the gather() and ggplot() lines appropriately, change geom_line to geom_contour, remove the geom_area() line, and change “free” to “fixed” in the facet_wrap() line.

  3. Now write a new function that solves this problem for the two coin problem via the Metropolis algorithm. Then use the function to solve the same problem you just solved analytically in the previous question. This is also illustrated in Figure 7.6. Your code should reproduce the result shown in Figure 7.6. See course notes on the website for help.