Statistical rethinking with brms, ggplot2, and the tidyverse: Second edition
What and why
This ebook is based on the second edition of Richard McElreath’s (2020b) text, Statistical rethinking: A Bayesian course with examples in R and Stan. My contributions show how to fit the models he covered with Paul Bürkner’s brms package (Bürkner, 2017, 2018, 2020a), which makes it easy to fit Bayesian regression models in R (R Core Team, 2020) using Hamiltonian Monte Carlo. I also prefer plotting and data wrangling with the packages from the tidyverse (Wickham, 2019; Wickham et al., 2019). So we’ll be using those methods, too.
Caution: Work in progress
After chipping away at mini releases of partial drafts, welcome to version 0.1.0! This is the first “full length” draft of this book. I say “full length” in quotes because although we have chapters corresponding to all the 17 chapters in McElreath’s source material, some areas could use a little fleshing out. The sections I’m particularly anxious to improve are
- 4.6, which introduces the brms approach to b-splines;
- 15.3, which may someday include a brms workflow for categorical missing data;
- 16.2.3, which contains a mixture model that McElreath fit directly in Stan and I suspect may be possible in brms with a custom likelihood; and
- 16.4.2, which contains an ordinary differential equation model that McElreath fit directly in Stan and I suspect may be possible in brms, but is beyond my current skill set.
If you have insights on how to improve any of these sections, please share your thoughts on GitHub at https://github.com/ASKurz/Statistical_Rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed/issues.
Thank-you’s are in order
I’d like to thank the following for their helpful contributions:
- E. David Aja (@edavidaja),
- Monica Alexander (@MJAlexander),
- Shaan Amin (@Shaan-Amin),
- Malcolm Barrett (@malcolmbarrett),
- Adam Bear (@adambear91),
- Louis Bliard (@lbiard),
- Paul-Christian Bürkner (@paul-buerkner),
- Sebastian Lobentanzer (@slobentanzer),
- Ed Merkle (@ecmerkle),
- Gavin Simpson (@gavinsimpson),
- Richard Torkar (@torkar), and
- Donald R. Williams (@donaldRwilliams).
Science is better when we work together.
License and citation
This book is licensed under the Creative Commons Zero v1.0 Universal license. You can learn the details, here. In short, you can use my work. Just make sure you give me the appropriate credit the same way you would for any other scholarly resource. Here’s the citation information:
Bürkner, P.-C. (2017). brms: An R package for Bayesian multilevel models using Stan. Journal of Statistical Software, 80(1), 1–28. https://doi.org/10.18637/jss.v080.i01
Bürkner, P.-C. (2018). Advanced Bayesian multilevel modeling with the R package brms. The R Journal, 10(1), 395–411. https://doi.org/10.32614/RJ-2018-017
Bürkner, P.-C. (2020a). brms: Bayesian regression models using ’Stan’. https://CRAN.R-project.org/package=brms
McElreath, R. (2020b). Statistical rethinking: A Bayesian course with examples in R and Stan (Second Edition). CRC Press. https://xcelab.net/rm/statistical-rethinking/
R Core Team. (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/
Wickham, H. (2019). tidyverse: Easily install and load the ’tidyverse’. https://CRAN.R-project.org/package=tidyverse
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686. https://doi.org/10.21105/joss.01686