# Bayes Rules! An Introduction to Bayesian Modeling with R

*2021-07-05*

# Preface

*Bayesian* statistics?!
Once an obscure term outside specialized industry and research circles, Bayesian methods are enjoying a renaissance.
The title of this book speaks to what all the fuss is about: *Bayes rules*!
Bayesian methods provide a powerful alternative to the frequentist methods that are ingrained in the standard statistics curriculum.
Though frequentist and Bayesian methods share a common goal – learning from data – the Bayesian approach to this goal is gaining popularity for many reasons:
(1) Bayesian methods allow us to interpret new data in light of prior information, formally weaving both into a set of updated information;
(2) relative to the confidence intervals and p-values utilized in frequentist analyses, Bayesian results are easier to interpret;
(3) Bayesian methods can shine in settings where frequentist “likelihood” methods break down;
and (4) the computational tools required for applying Bayesian techniques are increasingly accessible.
Unfortunately, the popularity of Bayesian statistics has outpaced the curricular resources needed to support it.
To this end, the primary goal of *Bayes Rules!* is to make modern Bayesian *thinking*, *modeling*, and *computing* accessible to a broader audience.

## Audience

*Bayes Rules!* brings the power of Bayes to advanced undergraduate students and comparably trained practitioners.
Accordingly, the book is neither written at the graduate level nor is it meant to be a first introduction to the field of statistics.
At minimum, the book assumes that readers are familiar with the content covered in a typical undergraduate-level introductory statistics course.
Readers will also, ideally, have some experience with undergraduate-level probability, calculus, and the `R`

statistical software.
*But wait*!
Please don’t go away if you don’t check off all of these boxes.
We provide all `R`

code and enough probability review so that readers without this background will still be able to follow along so long as they are eager to pick up these tools on the fly.
Further, though certain calculus *concepts* are important in Bayesian analysis (thus the book), calculus *derivations* are not.
The latter are limited to the simple model settings in early chapters and easily skippable.

## Getting set up

Once you’re ready to dive into *Bayes Rules!*, take the following steps to get set up.
First, download the most recent versions of the following software:

Next, install the following packages within RStudio:

Install the

**rstan**package by carefully following the directions at https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started.Install a set of data wrangling and Bayesian packages by typing the following in your console.

`install.packages(c("bayesrules", "tidyverse", "janitor", "rstanarm", "bayesplot", "tidybayes", "broom.mixed", "modelr", "e1071", "forcats"), dependencies = TRUE) in The downloaded binary packages are /var/folders/n5/dx5zpw8d3js2d5t_w0xj5jw00000gp/T//RtmpyBihlp/downloaded_packages`

The

**bayesrules**package contains some datasets and functions we’ve built explicitly for the*Bayes Rules!*book. Several of the datasets in this package have been subset from larger sources, using non-random methods to obtain subsets that match our pedagogical goals. These potentially biased datasets should*not*be used for rigorous research purposes. Should this be your goal, please see the relevant data help file to identify the original, complete data source.

## Accessibility and inclusion

We are dedicated to providing an inclusive and accessible Bayesian resource. We are continuing to learn, and shared our current efforts at https://www.datapedagogy.com/posts/2020-07-24a-bayes-open-access. All the figures in the online version book are supported by alternate text and should be able accessible to visually-impaired readers with a screen-reader.

**An honest word about installations**

We do anticipate some initial barriers to engaging with this resource. Mainly, though **rstan** is one of the most utilized and powerful Bayesian computing resources, it is not yet universally “easy” to install. The details can vary quite a bit from machine to machine.

## Acknowledgments

First and foremost, we’d like to thank the students we’ve worked with at Augsburg University, Carleton College, Denison University, Macalester College, Smith College, and the University of California, Irvine. Their feedback, insights, and example inspired a high bar for the type of book we wanted to put out into the world. Beyond our students, we received valuable feedback from numerous colleagues in the Statistics and Data Science community. A special thanks to: James Albert, Virgilio Gómez Rubio, Amy Herring, David Hitchcock, Nick Horton, and Yue Jiang. And to our editor, David Grubbs. He certainly made this first adventure in book publishing more chill and enjoyable than we expected.

Beyond those above, Alicia would especially like to thank…

- John Kim, Martha Skold, the Johnsons, and Minneapolis friends for their support, even on the dreaded “writing brain” days.
- Galin Jones for his inviting enthusiasm about statistical computation.
- The STAT 454 students at Macalester College for their inspiring curiosity and the STAT 454 teaching assistants for supporting their peers in learning about Bayes (Zuofu Huang, Sebastian Coll, Connie Zhang).
- Colleagues in the Department of Mathematics, Statistics, and Computer Science at Macalester College – you are a humane, hilarious, and reflective crew.

Miles would especially like to thank….

- Francesca Giardine, Sarah Glidden, and Elaona Lemoto for testing out half-formed exercises, gently pointing out errors, and giving excellent suggestions. It was an honor to get to work with you at this early stage of your statistics careers.
- The Smith College SDS 320 students from Spring of 2019 and the SDS 390 students from Fall 2020 (especially Audrey Bretin, Dianne Caravela, Marlene Jackson, and Hannah Snell who provided helpful feedback on Chapter 8).
- His colleagues from Smith College SDS.
- The WSDS conference for being the starting point for many friendships and collaborations, including this book.
- His family, Ben Capistrant, Ethan Suniewick, Malkah Bird, Henry Schneiderman, Christopher Tradowsky, Ross Elfline, Jon Knapp, and Alex Callendar.

Mine would especially like to thank…

- Morteza Khakshoor, family, and friends who are far only in distance, for their love, support, and understanding.
- The late Binnaz Melin for being supportive of her career from a young age.
- Students of STATS 115 at UC Irvine who always are the best part of teaching Bayesian Statistics.
- Her colleagues in the Department of Statistics at UC Irvine.
- All those in the statistics and R community who are supportive of and kind towards others, especially newcomers.

Finally, we would all like to thank each other for recognizing the importance of humor, empathy, and gratitude to effective collaboration. Deciding to tackle this project before we really knew one another was a pretty great gamble. It’s been fun!

## License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.