Pre-workshop set-up

Please, follow these instructions to get ready before the workshop.

Pre-requisites

Before installing the necessary software, make sure you have installed or updated the following software.

Starter Kit

Please, download the Starter Kit.

You can get the Starter Kit from here. It is just an RStudio project with some useful files.

Installation

Important

If you have previously installed the C++ toolkit, CmdStan and/or cmdstanr, or if you have recently updated your OS, please follow these instructions to reinstall them.

Now you will need to install a few packages and extra software.

Here is an overview of what you will install:

  • C++ toolchain.
  • R packages: tidyverse, remotes, cmdstanr, brms.
  • CmdStan (including Stan).

Install the C++ toolchain

Some of the software (CmdStan) used in the workshop requires a working C++ toolchain for compilation.

You can find information on how to set up the C++ toolchain in Section 1.2.1 of the CmdStan User’s Guide.

Make sure to follow the instructions for your operating system. If you have Windows, installing RTools 42 seems to work better than installing RTools 40

Install the R packages

You need to install the following packages:

install.packages(c("tidyverse", "remotes"))
remotes::install_github("stan-dev/cmdstanr")
install.packages(c("brms"))
install.packages(c("tidybayes", "extraDistr"))

The cmdstanr package is an interface between R and CmdStan (see below), while brms is the package you will use to run Bayesian linear models (think of it as the Bayesian equivalent of lme4).

It will take several minutes to install the packages, depending on your system and configuration.

If after opening the Starter Kit in RStudio you get asked to install extra packages or software, please do so.

Install CmdStan

Now that you have installed the R packages, you need to install CmdStan.

CmdStan is a shell interface to the programming language Stan.

Stan is what runs the Bayesian models, but you don’t have to know Stan, because you will use the R packages to run the models (those packages will communicate with Stan in your stead).

To install CmdStan, run the following command in the R console:

cmdstanr::install_cmdstan(cores = parallel::detectCores(), overwrite = TRUE)

Check your installation work

Run the following in the RStudio Console. You will see text flashing.

library(cmdstanr)
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

If a mod object is created, then installation went well.

Troubleshoot

If you have issues with any of these steps, please get in touch with Stefano.