DCS-training / Bayesian-Statistics

Materials for the CDCS Introduction to Bayesian Statistics course. Go to the readme file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction to Bayesian Statistics

Date: April 2024

Author: Aislinn Keogh

This two-class course will introduce you to working with Bayesian Statistics. Distinct from frequentist statistics, which is concerned with accepting or rejecting the null hypothesis, Bayesian Statistics asks what the probability of different hypotheses is, given the data and our prior beliefs about the world.

On this course, we will talk through the conceptual underpinnings of Bayesian Statistics, and give you hands-on practice fitting Bayesian models in R.

Learning outcomes:

  • Understand how beliefs about the world are formalised
  • See how different priors influence a model's estimates
  • Get to grips with interpreting posterior distributions
  • Familiarise yourself with the workflow for running a Bayesian analysis
  • Practise fitting and inspecting Bayesian models using the brms package in R

The course will be split into two sessions:

  • Week 1: Theoretical introduction to Bayesian Statistics
  • Week 2: Hands-on practice fitting Bayesian models in R

This is an advanced-level course. We will assume that you are comfortable using R and RStudio, and familiar with linear regression models (e.g. in lme4). You may want to have a quick read through the following articles to refresh your memory on some relevant theoretical concepts:

Setup instructions

Please make sure to follow these instructions before the course begins as we won't have time to troubleshoot installation problems during the classes.

First, please make sure you have the latest version of R and the latest version of RStudio.

R packages

Next, you'll need to install a few R packages. We're going to be using brms, which is an R interface to fit Bayesian models using a backend language called Stan. You don't need to know anything about Stan to use brms, and the syntax should be very familiar if you're used to lme4! The bayesplot package has some nice built-in functions for visualising distributions. The extraDistr package includes some useful functions (density, distribution, quantile and random generation) for a number of distributions that are not available in base R. If you don't already use tidyverse, you'll need to install that too; we'll be using it for general data wrangling.

Open RStudio and run the following in the Console:

install.packages("brms")
install.packages("bayesplot")
install.packages("extraDistr")
install.packages("tidyverse")

If you get any error messages for any of these installs that you can't resolve by googling, please post in the Teams group to get help.

C++ compiler

You'll also need a C++ compiler (because brms internally creates Stan code which is translated to C++ and compiled afterwards).

  • On Windows: Install RTools, ensuring that you tick the box to add RTools to the system PATH, then run system("g++ -v") in the R Console
  • On macOS: Install XCode from the App Store, then run system("clang++ -v") in the R Console

You should see a few lines of indecipherable system code in the Console. As long as you don't see any warnings or errors, you're good to go!

Materials

We're going to be using this wonderful tutorial created by Elizabeth Pankratz for the theoretical introduction (Week 1): Bayes, stat! (Day 1).

Materials for the practical class (Week 2) are in the folder practical: you can download this entire folder to work through the RMarkdown notebook.

Additional resources

Feedback

If you attended this course in April 2024, please fill in our feedback form.

License: CC BY-NC 4.0

About

Materials for the CDCS Introduction to Bayesian Statistics course. Go to the readme file

License:Other


Languages

Language:HTML 100.0%