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.
We have updates
For a brief rundown of the version history, we have:
I released the 0.1.0 version of this project in November 24, 2020. It was the first full-length and nearly complete draft including material from all the 17 chapters in McElreath’s source material. All brms models were fit with version 2.14.0+.
Welcome to version 0.1.1! This is a mini update designed to
We’re not done yet and I could use your help.
Some areas of the book could use some 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. The contribution guidelines for this book are listed at https://github.com/ASKurz/Statistical_Rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed/blob/master/CONTRIBUTING.md.
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),
- Jenny Bigman (@jennybigman),
- Louis Bliard (@lbiard),
- Paul-Christian Bürkner (@paul-buerkner),
- Sebastian Lobentanzer (@slobentanzer),
- Ed Merkle (@ecmerkle),
- Randall Pruim (@rpruim),
- 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/
Robinson, D., & Hayes, A. (2020). broom: Convert statistical analysis objects into tidy tibbles [Manual]. https://CRAN.R-project.org/package=broom
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