Get startedGet started for free

Answering the question: Should I have a beach party?

1. Answering the question: Should I have a beach party?

So we have now done a whole analysis, you with zombie data, and I with temperature data. But I haven’t answered my original questions:

2. The questions

What’s likely the average water temperature for this lake on 20th of Julys, and what’s the probability the water temperature is going to be 18 or more on the next 20th? Right now

3. The posterior distribution

the posterior probability distribution is represented as a data frame with one row per parameter combination with the corresponding probability. But my questions are much easier to answer if the posterior is represented as a large number of samples, like in earlier chapters. So, let’s draw a sample from this posterior. We’re going to use the sample function to draw row indices proportionally to each rows probability. We want to be able to sample any row from 1 to the last row, we’re drawing a sample of size 10,000 (just a large enough sample), we want to be able to draw a row index twice so we sample with replacement, and we draw each row index proportional to its corresponding probability.

4. The posterior distribution

sample_indices is now a long vector of numbers, which we’ll use to pick out the corresponding mu and sigma parameters in pars. Hey, a long data frame of samples that we now can use to calculate stuff with ease. Let’s start by plotting

5. The probability distribution over the mean temperature

the probability distribution over the mean temperature. Looks like the mean is likely between 17 and 23 degrees. What would a 90% credible interval be here? We can calculate that using the quantile function

6. The probability distribution over the mean temperature

So with 90% probability, the average temperature is between 17.5 and 22.5 degrees.

7. Is the temperature 18 or above on the 20th?

Now, what’s the probability of the temperature being 18 or above on the 20th of July? Not the average temperature, the actual temperature. To get to this we need to simulate some temperature data using rnorm, but instead of using fixed parameter values, we’ll feed in our samples.

8. Is the temperature 18 or above on the 20th?

Here we’re simulating 10000 values using the posterior distributions for mu and sigma. And as rnorm is vectorized, and implicitly loops over mu and sigma, the uncertainty in the posterior will propagate and be included in the uncertainty in pred_temp. If we

9. Is the temperature 18 or above on the 20th?

plot it, we now get the probability distribution over the water temperature on the 20th. What’s the probability that it is 18 degrees or above? Is it large enough, or should I cancel my beach party? For that, we just

10. Is the temperature 18 or above on the 20th?

count up the proportion of samples that are 18 or more which gives us a 73% probability that the temperature in the lake is going to be 18 degrees or more. Good enough for me!

11. Beach party!

So I’m doing a beach party, nice!

12. What about the IQ of zombies?

Now you try to answer some of your questions about the IQ of zombies.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.