Introduction

What is this course? It is a crash course in brms: a brief and practical introduction to fitting Bayesian multilevel models in R and Stan using the brms package (Bayesian Regression Models using Stan). Because this is intended as a practical skills course, I will only give a quick and surface-level description of Bayesian analysis and how it can be used for multilevel regression models.

Download the worksheet for this lesson here.

What should you know coming into this course?

This course is designed for practicing researchers who have some experience with statistical analysis and coding in R.

Minimal prerequisites

  • You should have at least heard of a mixed model or multilevel model.
  • You should have at least tried to do stats and/or data science in R before.
  • You should have at least a vague knowledge of what Bayesian analysis and inference are.

Advanced prerequisites

  • If you have experience with the R package lme4, that’s great because the syntax of brms is modeled after lme4.
  • If you have experience with the tidyverse packages, including ggplot2, for manipulating and plotting data, that’s also great because we will be using them in this course.

If you don’t know what those packages are, don’t sweat it because you can just follow along by copying the code.

What will you learn from this course?

Conceptual learning objectives

At the end of this course, you will understand …

  • The very basics of Bayesian inference
  • What a prior, likelihood, and posterior are in the context of a Bayesian model
  • The very basics of how Markov Chain Monte Carlo works
  • What a credible interval is

Practical skills

At the end of this course, you will be able to …

  • Write the code to specify and sample a multilevel model with random intercepts and random slopes in brms
  • Generate plots and statistics to make sure your model converged
  • Interpret the summary output of a multilevel model in brms
  • Compare different models with leave-one-out information criteria
  • Use Bayes factors to assess strength of evidence for effects
  • Make plots of model parameters and predictions, with credible intervals to show uncertainty

What is Bayesian inference?

portrait presumed to be Thomas Bayes
This may or may not actually be a portrait of Thomas Bayes

In its simplest form, Bayesian inference is a method of statistical inference that allows you to use information you already know to assign a prior probability to a hypothesis, then update the probability of that hypothesis as you get more information. If that seems like common sense, it is!

It is a very powerful tool that has been applied across many fields of human endeavor. Today we are only going to look at its application in estimating the parameters of multilevel statistical models to analyze scientific data, but that’s only one of the many things we can use Bayesian inference for. Bayesian methods are only growing in popularity, thanks in large part to the rapid growth of user-friendly, open-source, computationally powerful software – like Stan and its companion R package brms that we are going to learn about today!

Bayesian inference is named after Reverend Thomas Bayes, an English clergyman, philosopher, and yes, statistician, who wrote a scholarly work on probability (published after his death in 1763). His essay included an algorithm to use evidence to find the distribution of the probability parameter of a binomial distribution … using what we now call Bayes’ Theorem! However, much of the foundations of Bayesian inference were really developed by Pierre-Simon Laplace independently of Bayes and at roughly the same time. Give credit where it’s due!

Bayes’ Theorem