15.1 Hierarchical Models are Exciting
Learning objectives
Explore the limitations of our current Bayesian modeling toolbox under two extremes, complete pooling and no pooling.
Examine the benefits of the partial pooling provided by hierarchical Bayesian models.
Focus on the big ideas and leave the details to subsequent chapters.
# Load packages
library("broom.mixed")
library("bayesrules")
library("dplyr")
library("ggplot2")
library("rstanarm")
sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
##
## locale:
## [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
## [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
## [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
##
## time zone: UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggtext_0.1.2 e1071_1.7-13 tidybayes_3.0.4
## [4] rstanarm_2.21.4 Rcpp_1.0.11 broom.mixed_0.2.9.4
## [7] patchwork_1.1.2 bayesplot_1.10.0 rstan_2.21.8
## [10] StanHeaders_2.26.27 latex2exp_0.9.6 gt_0.9.0
## [13] janitor_2.2.0 bayesrules_0.0.2 lubridate_1.9.2
## [16] forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2
## [19] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0
## [22] tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0
##
## loaded via a namespace (and not attached):
## [1] RColorBrewer_1.1-3 tensorA_0.36.2 rstudioapi_0.15.0
## [4] jsonlite_1.8.7 magrittr_2.0.3 farver_2.1.1
## [7] nloptr_2.0.3 rmarkdown_2.23 vctrs_0.6.3
## [10] minqa_1.2.5 base64enc_0.1-3 htmltools_0.5.5
## [13] distributional_0.3.2 broom_1.0.5 parallelly_1.36.0
## [16] sass_0.4.6 bslib_0.5.0 htmlwidgets_1.6.2
## [19] plyr_1.8.8 zoo_1.8-12 cachem_1.0.8
## [22] commonmark_1.9.0 igraph_1.5.0 mime_0.12
## [25] lifecycle_1.0.3 pkgconfig_2.0.3 colourpicker_1.2.0
## [28] Matrix_1.5-4.1 R6_2.5.1 fastmap_1.1.1
## [31] future_1.33.0 shiny_1.7.4.1 snakecase_0.11.0
## [34] digest_0.6.33 colorspace_2.1-0 furrr_0.3.1
## [37] ps_1.7.5 crosstalk_1.2.0 labeling_0.4.2
## [40] fansi_1.0.4 timechange_0.2.0 mgcv_1.8-42
## [43] abind_1.4-5 compiler_4.3.1 proxy_0.4-27
## [46] withr_2.5.0 backports_1.4.1 inline_0.3.19
## [49] shinystan_2.6.0 pkgbuild_1.4.2 highr_0.10
## [52] MASS_7.3-60 gtools_3.9.4 loo_2.6.0
## [55] tools_4.3.1 httpuv_1.6.11 threejs_0.3.3
## [58] glue_1.6.2 DiagrammeR_1.0.10 callr_3.7.3
## [61] nlme_3.1-162 promises_1.2.0.1 gridtext_0.1.5
## [64] grid_4.3.1 checkmate_2.2.0 reshape2_1.4.4
## [67] generics_0.1.3 gtable_0.3.3 tzdb_0.4.0
## [70] class_7.3-22 hms_1.1.3 xml2_1.3.5
## [73] utf8_1.2.3 ggdist_3.3.0 pillar_1.9.0
## [76] markdown_1.7 posterior_1.4.1 later_1.3.1
## [79] splines_4.3.1 lattice_0.21-8 survival_3.5-5
## [82] tidyselect_1.2.0 miniUI_0.1.1.1 knitr_1.43
## [85] arrayhelpers_1.1-0 gridExtra_2.3 bookdown_0.34
## [88] groupdata2_2.0.3 stats4_4.3.1 xfun_0.39
## [91] matrixStats_1.0.0 DT_0.28 visNetwork_2.1.2
## [94] stringi_1.7.12 yaml_2.3.7 boot_1.3-28.1
## [97] evaluate_0.21 codetools_0.2-19 cli_3.6.1
## [100] RcppParallel_5.1.7 shinythemes_1.2.0 xtable_1.8-4
## [103] munsell_0.5.0 processx_3.8.2 jquerylib_0.1.4
## [106] globals_0.16.2 coda_0.19-4 png_0.1-8
## [109] svUnit_1.0.6 parallel_4.3.1 rstantools_2.3.1
## [112] ellipsis_0.3.2 prettyunits_1.1.1 dygraphs_1.1.1.6
## [115] listenv_0.9.0 lme4_1.1-34 ggthemes_4.2.4
## [118] ggridges_0.5.4 scales_1.2.1 xts_0.13.1
## [121] crayon_1.5.2 rlang_1.1.1 shinyjs_2.1.0