Advertisement
simondp

Test flexible vs equidistant models for wine data

Sep 29th, 2021
1,264
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Test flexible vs equidistant models for wine data
  2. require(ordinal)
  3. require(brms)
  4. require(ggpubr) # Only needed for plotting
  5.  
  6. # Wine flexible
  7. wineF <- brm(rating ~ temp + (1|judge), data = wine,
  8.              family = cumulative(threshold = "flexible"),
  9.              chains = 2, cores = 2, iter=4000)
  10.  
  11. # Wine equidistant
  12. wineE <- brm(rating ~ temp + (1|judge), data = wine,
  13.             family = cumulative(threshold = "equidistant"),
  14.             chains = 2, cores = 2, iter=4000)
  15.  
  16. # Visually compare equi and flexi
  17. library(ggplot2); theme_set(theme_classic())
  18. plotF <- pp_check(wineF, type = "bars", ndraws = 500)
  19. plotE <- pp_check(wineE, type = "bars", ndraws = 500)
  20. plotE <- plotE+ ylab(NULL)
  21.  
  22. # Combine
  23. figure <- ggarrange(plotF, plotE,
  24.                     labels = c("Flexible", "Equidistant"),
  25.                     ncol = 2, nrow = 1,
  26.                     common.legend = TRUE, legend = "bottom")
  27. figure
  28.  
  29. # Compare
  30. loo_wineF <- loo(wineF)
  31. loo_wineE <- loo(wineE)
  32. loo_compare(loo_wineF,loo_wineE)
  33.  
Advertisement
RAW Paste Data Copied
Advertisement