Answering the question: Should I have a beach party?

Fundamentals of Bayesian Data Analysis in R

Rasmus Bååth

Data Scientist

The questions

  • What's likely the average water temperature on 20th of Julys?
  • What's the probability that the water temperature is going to be 18 or more on the next 20th?

Fundamentals of Bayesian Data Analysis in R

The posterior distribution

pars
  mu sigma probability
17.5   1.9      0.0001
18.0   1.9      0.0003
18.5   1.9      0.0014
19.0   1.9      0.0043
19.5   1.9      0.0094
20.0   1.9      0.0142
20.5   1.9      0.0151
21.0   1.9      0.0112
21.5   1.9      0.0058
22.0   1.9      0.0021
...    ...       ...
sample_indices <- sample(1:nrow(pars), size = 10000, 
                         replace = TRUE, prob = pars$probability)
Fundamentals of Bayesian Data Analysis in R
sample_indices <- sample(1:nrow(pars), size = 10000, 
                         replace = TRUE, prob = pars$probability) 
head(sample_indices)
430  428 1010  383  343  385
pars_sample <- pars[sample_indices, c("mu", "sigma")]
head(pars_sample)
     mu sigma
1  20.0   2.8
2  19.0   2.8
3  17.5   6.7
4  19.0   2.5
5  21.5   2.2
6  20.0   2.5
7  20.0   2.8
8  20.5   1.6
9  19.0   2.5
10 17.0   4.0
Fundamentals of Bayesian Data Analysis in R

The probability distribution over the mean temperature

hist(pars_sample$mu, 30)

Fundamentals of Bayesian Data Analysis in R

The probability distribution over the mean temperature

quantile(pars_sample$mu, c(0.05, 0.95))
  5%  95% 
17.5 22.5 
Fundamentals of Bayesian Data Analysis in R

Is the temperature 18 or above on the 20th?

pred_temp <- rnorm(10000, mean = , sd = )
Fundamentals of Bayesian Data Analysis in R

Is the temperature 18 or above on the 20th?

pred_temp <- rnorm(10000, mean = pars_sample$mu, sd = pars_sample$sigma)
Fundamentals of Bayesian Data Analysis in R

Is the temperature 18 or above on the 20th?

pred_temp <- rnorm(10000, mean = pars_sample$mu, sd = pars_sample$sigma)
hist(pred_temp, 30)

Fundamentals of Bayesian Data Analysis in R

Is the temperature 18 or above on the 20th?

pred_temp <- rnorm(10000, mean = pars_sample$mu, sd = pars_sample$sigma)
hist(pred_temp, 30)
sum(pred_temp >= 18) / length(pred_temp )
0.73
Fundamentals of Bayesian Data Analysis in R

Fundamentals of Bayesian Data Analysis in R

What about the IQ of zombies?

Fundamentals of Bayesian Data Analysis in R

Preparing Video For Download...