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.
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 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
##  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.,
- 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.,
- R objects, such as data or function arguments, are in typewriter font atop a gray background (e.g.,
size = 2).
- Hyperlinks are denoted by their typical blue-colored font.
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.
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:
- Jenny Bryan’s Happy Git and GitHub for the useR (Bryan et al., 2020) is the reference that finally got me working on GitHub.
- Again and again, I return to Grolemund and Wickham’s (2017) R for data science to learn about the tidyverse way of coding.
- Yihui Xie’s (2022) bookdown: Authoring books and technical documents with R Markdown is the primary source from which I learned how to make online books like this.
- While you’re at it, also check out Xie, Allaire, and Grolemund’s (2022) R Markdown: The definitive guide to learn more about how you can mix your R code with well-formatted prose.
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.
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: ##  en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 ## ## attached base packages: ##  stats graphics grDevices utils datasets methods base ## ## loaded via a namespace (and not attached): ##  bookdown_0.26 digest_0.6.29 R6_2.5.1 jsonlite_1.8.0 ##  magrittr_2.0.3 evaluate_0.15 stringi_1.7.6 rlang_1.0.2 ##  cli_3.2.0 rstudioapi_0.13 jquerylib_0.1.4 bslib_0.3.1 ##  rmarkdown_2.13 tools_4.1.2 stringr_1.4.0 xfun_0.30 ##  fastmap_1.1.0 compiler_4.1.2 htmltools_0.5.2 knitr_1.38 ##  sass_0.4.1