# Bayesian Data Analysis course

This is the web page for the Bayesian Data Analysis course at Aalto (CS-E5710) by Aki Vehtari.

Aalto students should check the 2024 specific course web page and MyCourses. **In 2024** Aalto course can be taken online except for the final project presentation. The lectures will be given on campus, but recorded and the recording will be made available online after the course. The registration for the course lectures will be used to estimate the need for the resources. If you are unable to register for the course at the moment in the Sisu, there is no need to email the lecturer. You can start taking the course and register before the end of the course. Sisu shows rooms on campus for the computer exercises, but you can join the TA sessions also online via Zulip and Zoom. You can choose which TA session to join each week separately, without a need to register for those sessions.

All the course material is available in a git repo (and these pages are for easier navigation). All the material can be used in other courses. Text (except the BDA3 book) and videos licensed under CC-BY-NC 4.0. Code licensed under BSD-3.

The electronic version of the course book Bayesian Data Analysis, 3rd ed, by Andrew Gelman, John Carlin, Hal Stern, David Dunson, Aki Vehtari, and Donald Rubin is available for non-commercial purposes. Hard copies are available from the publisher and many book stores. See also home page for the book, errata for the book, and chapter notes.

## Prerequisites

- Basic terms of probability theory
- probability, probability density, distribution
- sum, product rule, and Bayes’ rule
- expectation, mean, variance, median
- in Finnish, see e.g. Stokastiikka ja tilastollinen ajattelu
- in English, see e.g. Wikipedia and Introduction to probability and statistics

- Some algebra and calculus
- Basic visualisation techniques (R or Python)
- histogram, density plot, scatter plot
- see e.g. BDA R demos
- see e.g. BDA Python demos

This course has been designed so that there is strong emphasis in computational aspects of Bayesian data analysis and using the latest computational tools.

If you find BDA3 too difficult to start with, I recommend

- For regression models, their connection to statistical testing and causal analysis see Gelman, Hill and Vehtari, “Regression and Other Stories”.
- Richard McElreath’s Statistical Rethinking, 2nd ed book is easier than BDA3 and the 2nd ed is excellent. Statistical Rethinking doesn’t go as deep in some details, math, algorithms and programming as BDA course. Richard’s lecture videos of Statistical Rethinking: A Bayesian Course Using R and Stan are highly recommended even if you are following BDA3.
- For background prerequisites some students have found chapters 2, 4 and 5 in Kruschke, “Doing Bayesian Data Analysis” useful.

## Course contents following BDA3

Bayesian Data Analysis, 3rd ed, by Andrew Gelman, John Carlin, Hal Stern, David Dunson, Aki Vehtari, and Donald Rubin. Home page for the book. Errata for the book. Electronic edition for non-commercial purposes only.

- Background (Ch 1, Lecture 1)
- Single-parameter models (Ch 2, Lecture 2)
- Multiparameter models (Ch 3, Lecture 3)
- Computational methods (Ch 10 , Lecture 4)
- Markov chain Monte Carlo (Chs 11-12, Lectures 5-6)
- Extra material for Stan and probabilistic programming (see below, Lecture 6)
- Hierarchical models (Ch 5, Lecture 7)
- Model checking (Ch 6, Lectures 8-9)
- Evaluating and comparing models (Ch 7)
- Decision analysis (Ch 9, Lecture 10)
- Large sample properties and Laplace approximation (Ch 4, Lecture 11-12)
- In addition you learn workflow for Bayesian data analysis

## How to study

Recommended way to go through the material is

- Read the reading instructions for a chapter in chapter notes.
- Read the chapter in BDA3 and check that you find the terms listed in the reading instructions.
- Watch the corresponding lecture video to get explanations for most important parts.
- Read corresponding additional information in the chapter notes.
- Run the corresponding demos in R demos or Python demos.
- Read the exercise instructions and make the corresponding assignments. Demo codes in R demos and Python demos have a lot of useful examples for handling data and plotting figures. If you have problems, visit TA sessions or ask in course slack channel.
- If you want to learn more, make also self study exercises listed below

## Slides and chapter notes

- Slides
- including code for reproducing some of the figures

- Chapter notes
- including reading instructions highlighting most important parts and terms

## Videos

The following video motivates why computational probabilistic methods and probabilistic programming are important part of modern Bayesian data analysis.

Short video clips on selected introductory topics are available in a Panopto folder.

The 2022 lecture videos are in a Panopto folder. The 2023 lecture videos will be uploaded in another folder after each lecture.

## R and Python

We strongly recommend using R in the course as there are more packages for Stan and statistical analysis in R. If you are already fluent in Python, but not in R, then using Python may be easier, but it can still be more useful to learn also R. Unless you are already experienced and have figured out your preferred way to work with R, we recommend installing RStudio Desktop or using Aalto teaching JupyterHub. See FAQ for frequently asked questions about R problems in this course. The demo codes provide useful starting points for all the assignments.

- For learning R programming basics we recommend
- For learning basic and advanced plotting using R we recommend

## Demos

These demos include a lot of useful code for making the assignments.

## Self study exercises

Great self study BDA3 exercises for this course are listed below. Most of these have also model solutions available.

- 1.1-1.4, 1.6-1.8 (model solutions for 1.1-1.6)
- 2.1-2.5, 2.8, 2.9, 2.14, 2.17, 2.22 (model solutions for 2.1-2.5, 2.7-2.13, 2.16, 2.17, 2.20, and 2.14 is in slides)
- 3.2, 3.3, 3.9 (model solutions for 3.1-3.3, 3.5, 3.9, 3.10)
- 4.2, 4.4, 4.6 (model solutions for 3.2-3.4, 3.6, 3.7, 3.9, 3.10)
- 5.1, 5.2 (model solutions for 5.3-5.5, 5.7-5.12)
- 6.1 (model solutions for 6.1, 6.5-6.7)
- 9.1
- 10.1, 10.2 (model solution for 10.4)
- 11.1 (model solution for 11.1)

## Stan

- Stan home page
- Introductory article in Journal of Statistical Software
- Documentation
- RStan installation
- PyStan installation
- Basics of Bayesian inference and Stan, Jonah Gabry & Lauren Kennedy Part 1 and Part 2

## Extra reading

## Acknowledgements

The course material has been greatly improved by the previous and current course assistants (in alphabetical order): Michael Riis Andersen, Paul Bürkner, Akash Daka, Alejandro Catalina, Kunal Ghosh, Meenal Jhajharia, Andrew Johnson, Noa Kallioinen, Joona Karjalainen, David Kohns, Juho Kokkala, Leevi Lindgren, Yann McLatchie, Måns Magnusson, Anton Mallasto, Janne Ojanen, Topi Paananen, Markus Paasiniemi, Juho Piironen, Anna Riha, Jaakko Riihimäki, Niko Siccha, Eero Siivola, Tuomas Sivula, Teemu Säilynoja, Jarno Vanhatalo.

The web page has been made with rmarkdown’s site generator.