1 What’s in This Book (Read This First!)

1.1 Real people can read this book

Kruschke began his (2015, p. 1) text with “This book explains how to actually do Bayesian data analysis, by real people (like you), for realistic data (like yours).” Agreed. Similarly, this project is designed to help those real people do Bayesian data analysis. While I’m at it, I may as well explicate my assumptions about you.

If you’re looking at this project, I’m guessing you’re a graduate student, a post-graduate academic or researcher of some sort. Which means I’m presuming you have at least a 101-level foundation in statistics. In his text, it seems like Kruschke presumed his readers would have a good foundation in calculus, too. I make no such presumption. But if your stats 101 chops are rusty, check out Legler and Roback’s free (2019) bookdown text, Broadening your statistical horizons or Navarro’s free (2019) text, Learning statistics with R: A tutorial for psychology students and other beginners.

I presume a basic working fluency in R and a vague idea about what the tidyverse is. Kruschke does some R warm-up in Chapter 3, and I follow suit. But if you’re totally new to R, you might also consider starting with Peng’s (2020) R programming for data science. The best introduction to the tidyvese-style of data analysis I’ve found is Grolemund and Wickham’s (2017) R for data science. If you prefer learning by video, Navarro has some nice introductory playlists here.

1.2 What’s in this book

This ebook is not meant to stand alone. It’s a supplement to the second edition of Kruschke’s (2015) Doing Bayesian data analysis. I follow the structure of his text, chapter by chapter, translating his analyses into brms and tidyverse code. However, many of the sections in the text are composed entirely of equations and prose, leaving us nothing to translate. When we run into those, the corresponding sections in this ebook may be missing.

Also beware the content herein will depart at times from Kruschke’s source material. Bayesian data analysis with HMC is an active area of development in terms of both statistical methods and software implementation. There will also be times when my thoughts and preferences on Bayesian data analysis diverge a bit from Kruschke’s. In those places of divergence, I will often provide references and explanations.

I use a handful of formatting conventions gleaned from R4DS and Xie, Allaire, and Grolemund’s (2022) R markdown: The definitive guide. For example:

  • I put R and R packages (e.g., brms) in boldface.
  • R code blocks and their output appear in a gray background. E.g.,
2 + 2
## [1] 4
  • Did you notice how there were two strips of gray background, there? The first one designated the actual code. The second one was the output of that code, and the output of a code block often begins with ##.
  • Functions are in a typewriter font and followed by parentheses, all atop a gray background (e.g., brm()).
  • When I want to make explicit what packages a given function comes from, I insert the double-colon operator :: between the package name and the function (e.g., tidyr::pivot_longer()).
  • R objects, such as data or function arguments, are in typewriter font atop a gray background (e.g., d or size = 2).
  • Hyperlinks are denoted by their typical blue-colored font.

1.3 What’s new in the second edition

There’s nothing new from my end. I have only translated the edition of Kruschke’s text. If you’d like to review the version history of this ebook, go here or here.

1.4 Gimme feedback (be polite)

I am not a statistician and I have no formal background in computer science. I finished my PhD in clinical psychology in 2018. During my graduate training I developed an unexpected interest in applied statistics and programming. I became an R user in 2015 and started learning about Bayesian statistics around 2013. There is still so much to learn, so my apologies for when my code appears dated or inelegant. There will also be occasions in which I’m not yet sure how to reproduce models or plots in the text. Which is all to say, suggestions on how to improve my code are welcome. My preference is to do so by opening a GitHub issue. You can find more guidelines on contributing to this ebook in the GitHub CONTRIBUTING section. If you’d like to learn more about me, you can find my website at https://solomonkurz.netlify.com.

1.5 Thank you!

While in grad school, I benefited tremendously from free online content. This ebook and other projects like it (see here and here) are my attempts to pay it forward. As soon as you’ve gained a little proficiency, do consider doing to same.

I addition to great texts like Kruschke’s, I’d like to point out a few other important resources that have allowed me to release an ebook like this:

If you haven’t already, bookmark these resources and share them with your friends. With time and practice, these resources might help you write books and other online projects with R.

Session info

At the end of every chapter, I use the sessionInfo() function to help make my results more reproducible.

## R version 4.1.2 (2021-11-01)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Catalina 10.15.7
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## loaded via a namespace (and not attached):
##  [1] bookdown_0.26   digest_0.6.29   R6_2.5.1        jsonlite_1.8.0 
##  [5] magrittr_2.0.3  evaluate_0.15   stringi_1.7.6   rlang_1.0.2    
##  [9] cli_3.2.0       rstudioapi_0.13 jquerylib_0.1.4 bslib_0.3.1    
## [13] rmarkdown_2.13  tools_4.1.2     stringr_1.4.0   xfun_0.30      
## [17] fastmap_1.1.0   compiler_4.1.2  htmltools_0.5.2 knitr_1.38     
## [21] sass_0.4.1


Bryan, J., the STAT 545 TAs, & Hester, J. (2020). Happy Git and GitHub for the useR. https://happygitwithr.com
Grolemund, G., & Wickham, H. (2017). R for data science. O’Reilly. https://r4ds.had.co.nz
Kruschke, J. K. (2015). Doing Bayesian data analysis: A tutorial with R, JAGS, and Stan. Academic Press. https://sites.google.com/site/doingbayesiandataanalysis/
Legler, J., & Roback, P. (2019). Broadening your statistical horizons: Generalized linear models and multilevel models. https://bookdown.org/roback/bookdown-bysh/
Navarro, D. (2019). Learning statistics with R. https://learningstatisticswithr.com
Peng, R. D. (2020). R programming for data science. https://bookdown.org/rdpeng/rprogdatascience/
Xie, Y. (2022). Bookdown: Authoring books and technical documents with R Markdown. Chapman and Hall/CRC. https://bookdown.org/yihui/bookdown/
Xie, Y., Allaire, J. J., & Grolemund, G. (2022). R Markdown: The definitive guide. Chapman and Hall/CRC. https://bookdown.org/yihui/rmarkdown/