# 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.

For a brief rundown of the version history, we have:

### Version 0.1.0.

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+.

### Version 0.1.1.

Welcome to version 0.1.1! This is a mini update designed to

• fix code breaks resulting from updates to the broom package (Robinson & Hayes, 2020), caught by Jenny Bigman;
• replace the soon-to-be retired sample_n() code with slice_sample(), caught by Randall Pruim;
• and correct a few typos along the way.

### 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:

Science is better when we work together.

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:

@book{kurzStatisticalRethinkingSecondEd2020,
title = {Statistical rethinking with brms, ggplot2, and the tidyverse: {{Second}} edition},
author = {Kurz, A. Solomon},
year = {2020},
month = {dec},
edition = {version 0.1.1},
url = {https://bookdown.org/content/4857/}
}

### References

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