Applied Bayesian Lab 3
Complete all Questions and submit your final PDF or html (either works!) under Assignments in Canvas.
Goal
In Lab 2, we explored the posterior predictive distribution (PPD) for the Beta-Binomial model. We also started to experiment with Monte Carlo Approximation.
In this lab, we will apply these concepts to our new model, the Poisson-Gamma.
The Data Scenario (summary from last time)
We are working with a local animal shelter. They are attempting to determine how many days it takes, on average, for a mixed-breed puppy that is brought into the shelter to be adopted.
Let \(Y_i\) be a random variable that indicates the number of days it takes a mixed-breed puppy to be adopted (once the puppy is old enough for adoption). We have information on \(n = 25\) puppies that were brought into the animal shelter system during the same weekend. All of these puppies are mixed breeds that were roughly the same age when they were brought to the shelter. They all became eligible for adoption on the same day.
Our Bayesian model is:
\[Y_1, \dots, Y_{25} \stackrel{iid}{\sim} Poisson(\theta),\]
\[\theta \sim Gamma(\alpha,\beta)\] which yields the posterior distribution
\[\theta | Y_1, \dots, Y_{25} \sim Gamma( \alpha + \sum_{i=1}^n y_i, n + \beta)\]
Recall that in our data from \(n = 25\) puppies, it took an average of 20 days for a puppy to be adopted. You determined the appropriate \(\alpha\) and \(\beta\) values in the last lab.
Prediction
Now a new puppy is brought into the shelter. This puppy’s age and mixed-breed characteristics are similar to those from our sample. Based on the data we have, we want to predict how many days it will take this puppy to get adopted so they can be placed with an appropriate foster home.
Let’s add some notation to this.
Let \(Y^{*}\) be a Poisson random variable that represents the number of days it will take this new puppy to be adopted. You may assume that conditional on \(\theta\), \(Y^{*}\) is independent of \(Y_1, \dots, Y_{n}\).
\[Y^{*}|\theta \sim Poisson(\theta)\] In order to predict the number of days it will take this puppy to be adopted, we need to find the PPD of \(Y^{*}\),
\[Y^{*} | (Y_1 = y_1, \dots, Y_n=y_n).\]
There are two options at this point.
We can find the PPD exactly using integration.
We can approximate the PPD by using Monte Carlo approximation.
We are going to start with the approximation (Monte Carlo). Then, we will compute the exact PPD and compare our results!
Why are we doing it in this order?? Well, our response variable for the Beta-Binomial was binary. Now, our response variable is a count. It turns out that this has an impact on how we work with the PPD, and it helps to explore that before we get into the integration.
In the real world, if we can compute an exact PPD, we usually do that directly. Part of our goal today is to practice Monte Carlo approximation, so we will do both techniques.
Monte Carlo Approximation
Okay, so we are going to start with the Monte Carlo approximation to the PPD. We learned the steps of Monte Carlo approximation last time in terms of the Beta-Binomial. Now, let’s see if we can apply these to the Poisson-Gamma.
Question 1
Write down the 4 steps you would need to use to find the Monte Carlo approximation of the PPD for \(Y^{*}\). Be clear about what distributions you need to sample from in each step.
Question 2
Complete Step 1 from Question 1. Set a random seed of 100, and state the value of the random draw.
Question 3
Complete Step 2 from Question 1. Set a random seed of 100, and state the value of the random draw.
Question 4
Set a random seed of 100. Run a code that performs \(s = 100000\) iterations of Step 1 and Step 2. Each time through the process, you need to store your value of \(y_{j}^{*}\). Show your code as the answer to this question.
And now…we need to pause.
Considerations with the Poisson-Gamma
When we got to this point with the Beta-Binomial, the next step was to determine the proportion of our samples \(y_{j}^{*}\) that were equal to 0 and equal to 1. In other words
\[P(Y^* =1 |y_1,y_2,...y_n) \approx \frac{1}{s} \sum_{j=1}^{s} y^{*}_{j}\]
\[P(Y^* =0 |y_1,y_2,...y_n) \approx 1- \frac{1}{s} \sum_{j=1}^{s} y^{*}_{j}\]
With these two probabilities, we could approximate the PPD with a Bernoulli distribution with probability of success \(\frac{1}{s} \sum_{j=1}^{s} y^{*}_{j}\).
\[P(Y^* |Y_i =y_1,Y_2 = y_2,...Y_n = y_n) \sim Bernoulli \left(\frac{1}{s} \sum_{j=1}^{s} y^{*}_{j} \right)\]
However, in our current data example we have a Poisson random variable \(Y^{*}\) rather than Bernoulli random variable \(Y^{*}\). This means that instead of just two unique outcome values \(y^{*}\), the \(Y^{*}\) can be 0, 1, 2, 3, and so on. Accordingly, our PPD is a not defined by just two probabilities.
This means that we want to look at (1) what different values for \(y^{*}\) we sampled and (2) how often we drew each of those values. This will help us determine the characteristics of the PPD.
Question 5
Create a graph to visualize the density of your PPD. Hint: This just means plotting the distribution of your \(y^{*}\) draws. Comment on the shape of the PPD.
This is very different from what we had before! Remember that the “D” in PPD stands for “distribution”. What we are looking at is an approximation of the pmf for the PPD \(Y^{*}|Y_1 = y_1, \dots, Y_n = y_n\).
What can we do with this approximation? One thing we can do is use this to determine which values of \(y^{*}\) are likely to occur. We are trying to predict \(Y^{*}\) for a new puppy, and we are now looking at a distribution that tells what values of \(Y^{*}\) we are likely to see for that puppy.
Question 6
Based on the PPD, which values of \(Y^{*}\) seem most likely?
We can also use the PPD approximation how likely it is that \(Y^{*}\) would equal a specific value of \(y^{*}\).
Question 7
Using the Monte Carlo approximation, what is the posterior predictive probability that \(Y^{*} = 19\)? In other words, what percent of your \(y_j^{*}\) values are 19?
This allows us to evaluate how likely it is that this new puppy would be adopted in a certain number of days. This means that with the Monte Carlo approximation of the PPD, we can (1) determine a posterior probability that \(Y^{*}\) is equal to a specific number of days and (2) determine which values of \(Y^{*}\) have the highest posterior probability.
Two Posteriors - Considerations
At this point in our process, you have probably noticed that we have two posterior distributions we are working with. The first is the posterior distribution for \(\theta\), \[\theta||Y_1 = y_1, \dots, Y_n = y_n\]
and a posterior predictive distribution for \(Y^{*}\),
\[Y^{*}|Y_1 = y_1, \dots, Y_n = y_n\]
Let’s make sure we are clear on the difference between these two posterior distributions.
Question 8
If we draw a value \(\theta^{*}\) from its posterior distribution for our data today, what does that value of \(\theta^{*}\) represent?
Question 9
If we draw a value \(Y^{*}\) from its posterior predictive distribution for our data today, what does that value of \(Y^{*}=y^{*}\) represent?
Question 10
Create a graph of your posterior distribution for \(\theta\). Stack this graph on top of the graph of the Monte Carlo approximation to the PPD you made in Question 5. Make sure the x-axis limits the same on both plots. Comment on the center and spread of both distributions. Why does it make sense that the variance (the spread) of the posterior pdf for \(\theta\) is less than the variance of the PPD pmf for \(Y^{*}\)?
Computing the PPD Eaxctly
At this point, we have explored what we can do with the Monte Carlo approximation of the PPD. However, it turns out that for the Poisson-Gamma model, we can directly compute the PPD. Furthermore, it turns out that this distribution is a type of distribution one that we know!!
Question 11
Show that the PPD for \(Y^{*}\) is a Negative Binomial distribution. This means show your steps!! Clearly state the value of any needed parameters. In other words, your answer should state \[Y^{*}|Y_1 = y_1, \dots, Y_n = y_n \sim NegativeBinomial( Thing 1 , Thing 2)\]
Hint: The math is generally easier if you solve the integral as we did with the Beta-Binomial, and then look at the PMF of a negative binomial to manipulate from there. You are welcome to write your work out on paper rather than typing it out!!
Rounding matters here. Round all decimals to 4 decimal places.
Question 12
Using the Negative binomial you specified in Question 11, what is the posterior predictive probability that \(Y^{*} = 19\)? Note: Do this using the pmf for the negative binomial.
Question 13
Compare your answers for Question 7 and Question 12. Did you get similar results from the exact PPD and the Monte Carlo approximation?
Turning in your assignment
When your Markdown document is complete, do a final knit and make sure everything compiles. You will then submit your document on Canvas. You must submit a PDF or html document to Canvas. No other formats will be accepted. Make sure you look through the final document to make sure everything has knit correctly.
This
work was created by Nicole Dalzell and is licensed under a
Creative
Commons Attribution-NonCommercial 4.0 International License. Last
updated 2023 February 11.