11.5 Model evaluation & comparison

library(patchwork)
# Posterior predictive checks. For example:
p1<- pp_check(weather_model_1)+labs(title="Model 1")
p2<- pp_check(weather_model_2)+labs(title="Model 2")
p3<- pp_check(weather_model_3)+labs(title="Model 3")
p4<- pp_check(weather_model_4)+labs(title="Model 4")

(p1|p2|p3|p4) +
  plot_layout(guides = "collect") &
  theme(legend.position = "bottom")

11.5.1 Evaluating predictive accuracy using visualizations

set.seed(84735)
predictions_1 <- posterior_predict(weather_model_1,
                                   newdata = weather_WU)

# Posterior predictive models for weather_model_1
ppc_intervals(weather_WU$temp3pm, 
              yrep = predictions_1, 
              x = weather_WU$temp9am, 
              prob = 0.5, 
              prob_outer = 0.95) + 
  labs(x = "temp9am", y = "temp3pm")

set.seed(84736)
predictions_2 <- posterior_predict(weather_model_2,
                                   newdata = weather_WU)
# Posterior predictive models for weather_model_2
ppc_violin_grouped(weather_WU$temp3pm, 
                   yrep = predictions_2, 
                   group = weather_WU$location, 
                   y_draw = "points") + 
  labs(y = "temp3pm")

set.seed(84737)
predictions_3 <- posterior_predict(weather_model_3,
                                   newdata = weather_WU)
# Posterior predictive models for weather_model_3
ppc_intervals_grouped(weather_WU$temp3pm, 
                      yrep = predictions_3, 
                      x = weather_WU$temp9am, 
                      group = weather_WU$location,
                      prob = 0.5, 
                      prob_outer = 0.95,
                      facet_args = list(scales = "fixed")) + 
  labs(x = "temp9am", y = "temp3pm")