Multilevel regression analysis is now a widely used statistical technique in psychology, being used for repeated measures analyses or for when data are hierarchically nested or cross classified into different groups. Popular R based packages such as lme4 have done much to facilitate the use of multilevel regression. However, these packages are limited in terms of the types of regression analyses that can accomplish. Bayesian modelling is a powerful and flexible approach to statistical modelling generally, including multilevel regression modelling. The brms R package, which uses the Stan probabilistic programming language, is a remarkably powerful yet easy to learn and easy to use tool for Bayesian regression modelling, including general, generalized, and nonlinear multilevel modelling. This workshop provides an introduction to multilevel modelling, describes the Bayesian approach to the topic, and provides hands-on advice on how to use brms using a range of interesting real world examples. This workshop is aimed at anyone interested in multilevel regression modelling in general, and Bayesian multilevel regression in particular.

Schedule

  • 10:30-11:00 Introduction to brms
  • 11:00-12:30 Linear models
  • 13:30-14:30 Generalized linear models
  • 14:30-14:45 Break
  • 14:45-17:00 Multilevel models

Software

The required software for this workshop is all free and open source and will run identically on Windows, Mac OS X, and Linux platforms.

There are six main pieces of software to install:

  • R: An environment for statistical computing.
  • Rstudio: An integrated development environment for using R.
  • tidyverse: A bundle of R packages to use R the modern way.
  • Miscellaneous R packages: Other vital, or just handy, R packages.
  • Stan: A Bayesian probabilistic modelling language.
  • brms: An R package to interface with Stan.

All of the above installation should be easy and painless except possibly for the installation of Stan, which can possibly be tricky because it is an external program and requires addition programming tools like c++ libraries and compilers etc. However, in the instructions below there are links to pages that provide ample detail on how to install and test Stan and all its dependencies.

Installing R

Go to the R website and follow the links for downloading. On Windows, this should lead you to

Downloading this and following the usual Windows installation process, you'll then have a full working version of R.

On Macs, the installation procedure is essentially identical. The latest Mac installer should be available at

Download this and follow the usual Mac installation process to get a full working version of R for Macs.

Installing Rstudio

Using Rstudio is not strictly necessary. You can do all you need to do with R without using Rstudio. However, many people have found that using R is more convenient and pleasant when working through Rstudio. To install it, go to the Rstudio website, specifically to

which will list all the available installers. Note that you just want the Rstudio desktop program. The Rstudio server is something else (basically it is for providing remote access to Rstudio hosted on Linux servers).

Again, you'll just follow the usual installation process for Windows or Macs to install Rstudio using these installers.

Installing the tidyverse packages

The so-called tidyverse is a collection of interrelated R packages that implement essentially a new standard library for R. In other words, the tidyverse gives us a bundle tools for doing commonplace data manipulation and visualization and programming. It represents the modern way to use R, and in my opinion, it's the best way to use R. All the tidyverse packages can be installed by typing the following command in R:

install.packages("tidyverse")

The main packages that are contained within the tidyverse bundle are listed here.

Installing Miscellaneous R packages

There are a bunch of other R packages that we either will, or just may, use. Here are there installation commands:

install.packages("MCMCglmm")
install.packages("lme4")

Installing Stan

Stan is a probabilistic programming language. Using the Stan language, you can define arbitrary probabilistic models and then perform Bayesian inference on them using MCMC, specifically using Hamiltonian Monte Carlo.

In general, Stan is a external program to R; it does not need to be used with R. However, one of the most common ways of using Stan is by using it through R and that is what we will be doing in this workshop.

To use Stan with R, you need to install an R package called rstan. However, you also need additional external tools installed in order for rstan to work.

Instructions for installing rstan on can be found here:

Specific instructions for different platforms can be found by following links from this page.

Installing brms

If the installation of R, Rstudio and Stan seemed to go fine, you can get the brms R package, which makes using Stan with R particularly easy when using conventional models.

To get brms, first start Rstudio (whether on Windows, Macs, Linux) and then run

install.packages('brms')

You can test the installation of brms with

library('brms')

If no errors are raised, you can assume the installation was successful.

GitHub resources

Further resources for this training course can be found on Github at mark-andrews/bps-cog-2018-bayes-workshop.