Introduction

  • The code and data are provided to fully reproduce the examples and figurs in the book. They can be a good way to see what the code does. Different people have different styles of code. The code here is not supposed to be a model. The statistical analyses and graphs in the book are intended to be models for good practice, but the code here is meant to be simple with minimal dependencies.
  • For R programming basics see Appendix A of Regression and Other Stories. If you want to learn more, see our recommendations for R programming and visualization with R.

  • The folders below (ending /) point to the code (.R and .Rmd) and data folders (.csv or .txt) in github, and .html -files point to knitted notebooks.
  • Most examples have cleaned data in .csv file in data subfolder for easy experimenting. For completeness and reproducibility, the data subfolders have also the raw data and *_setup.R file showing how the data pre-processing has been done (to do the exercises and follow along with the examples, you don’t need to worry about the setup code).


Examples by chapters

1 Introduction

2 Data and measurement

3 Some basic methods in mathematics and probability

4 Generative models and statistical inference

5 Simulation

6 Background on regression modeling

7 Linear regression with a single predictor

8 Fitting regression models

9 Prediction and Bayesian inference

10 Linear regression with multiple predictors

11 Assumptions, diagnostics, and model evaluation

12 Transformations

13 Logistic regression

14 Working with logistic regression

15 Other generalized linear models

16 Design and sample size decisions

17 Poststratification and missing-data imputation

18 Causal inference basics and randomized experiments

19 Causal inference using regression on the treatment variable

20 Observational studies with all confounders assumed to be measured

21 More advanced topics in causal inference

22 Advanced regression and multilevel models

Appendix A


Examples alphabetically


Tidyverse code

Bill Behrman has revised all the example code to use Tidyverse

brms + tidyverse code

Solomon A. Kurz is revising all the example code to use brms and tidyverse

Python code

Ravin Kumar, Tomás Capretto, and Osvaldo Martin are porting ROS examples to Python using bambi (BAyesian Model-Building Interface) which has similar formula syntax as rstanarm and brms.