# 29 Assignment 3

Assignment 3 is be completed individually or with a partner (i.e., the maximum group size is two). Please submit the assignment as a single pdf or html file (one file per individual/group). Save the file as Yourlastname_Assignment3 (e.g., Hefley_Assignment3). Make sure to show your work in R to ensure that I can reproduce your results (e.g., figures, calculations, etc). Upload your completed assignment to Canvas before 5 pm on Tuesday 9/29/20.

## 29.1 Motivation

Assignment 3 is designed to give you experience with sampling-based approaches to fit Bayesian hierarchical models to spatio-temporal data.

## 29.3 Part 1

Suppose that we lived in a world where there was a test for COVID-19 that was 100% accurate (i.e., a test with no false-negatives and no false positives). In this world, a fictitious version of me decided to get tested for COVID-19 last week.

1. Let the process model be $$[y|\phi]=\text{Bernoulli}(\phi)$$ and the parameter model be $$[\phi]=\text{Beta}(\alpha,\beta)$$. Use Bayes’ theorem to find $$[\phi|y]$$. Show all of your work. You can insert a image of your work if you want to use pencil and paper rather than typesetting it. Note that because the test is 100% accurate there is no need for a data model when using the Bayesian hierarchical modeling framework.

2. Prior to being tested for COVID-19, I was unsure if I was infected. For the Bayesian model from #1, determine the exact parameter model (i.e., the values of the $$\alpha$$ and $$\beta$$) that represent this prior knowledge.

3. My test results came back negative. Using the data from my test results and your results from problem #1 and #2, obtain 1,000 samples from $$[\phi|y]$$. With these samples, represent $$[\phi|y]$$ using a histogram. Make sure to put appropriate axis labels on this histogram.

## 29.4 Part 2

For most Bayesian models, you won’t be able to find the posterior distribution (i.e., $$[\phi|y]$$) using mathematical tools. Instead you will only be able to obtain samples using computational tools. Below you will use two different algorithms to obtain samples from $$[\phi|y]$$.

1. Use your results from problem 1-3 and rejection sampling to obtain 1,000 samples from $$[\phi|y]$$. With these samples, represent $$[\phi|y]$$ using a histogram. Make sure to put appropriate axis labels on this histogram.

2. Use your results from problem 1-3 and a Metropolis or Metropolis-Hastings algorithm to obtain 1,000 samples from $$[\phi|y]$$. With these samples, represent $$[\phi|y]$$ using a histogram. Make sure to put appropriate axis labels on this histogram.

## 29.5 Part 3

For most tests, there is a probability of obtaining a false-negative test result. Because there is the potential for false-negative test results, we need to include a data model in our Bayesian hierarchical model. To accommodate the potential for false-negatives use the data model $[z|y]=\begin{cases} \text{Bernoulli(0.9)} & \text{if}\:y=1\\ 0 & \text{if}\:y=0 \end{cases}$ where $$z$$ is my test result (which was negative), 0.9 is the probability that a true positive (i.e., $$y=1$$) result in a positive test result (i.e., $$z=1$$).

1. Obtain samples from the posterior distribution $$[y,\phi|z]$$. With these samples, represent $$[y|z]$$ using one histogram and $$[\phi|z]$$ with another histogram. Make sure to put appropriate axis labels on this histogram.

2. Given my test results, what is the probability I have COVID-19?