Module 1: Setting Up Your Environment

Before we can begin, we need to ensure you have the correct tools installed. This module will walk you through installing R, RStudio, and the R packages required for this course.

1. Install R

R is the programming language we will be using. You can download the latest version for your operating system from the official R website.

Please follow the installation instructions for your system.

2. Install RStudio

RStudio is an integrated development environment (IDE) that makes working with R much easier. We highly recommend using it.

Once downloaded, install it as you would any other application.

3. Install Required R Packages

With R and RStudio installed, we now need to install the specific R packages for this training. These packages provide essential functions for data manipulation, visualization, and Bayesian modelling.

Open RStudio and run the following command in the console to install all the necessary packages at once:

# This command will install all the packages we need for the course.
install.packages(c("tidyverse", "rstan", "lubridate", "patchwork", "knitr", "forecast"))

This may take a few minutes to complete.

4. Verify Your Stan Installation

The rstan package is the most critical piece, as it connects R to the Stan modelling language. To ensure it’s working correctly, run the following R code:

# Load the rstan library
library(rstan)

# Define a very simple Stan model
test_model <- "
data {
  real y[2];
}
parameters {
  real mu;
}
model {
  mu ~ normal(0, 1);
  y ~ normal(mu, 1);
}
"

# Compile and run the model
fit <- stan(model_code = test_model, data = list(y = c(-1, 1)))

# Print the results
print(fit)

If this code runs without any errors and prints a summary of the model fit, your environment is set up correctly.


Once you have successfully completed these steps, you are ready to move on to the next module.