macpan-workshop

Technical Preparation

This document outlines the steps required to prepare your computer for the macpan2 workshop.

Table of Contents

The Most Important Things

If you have any difficulties or questions about the technical instructions below, please contact Steve Walker (the instructor) as soon as possible so that we can focus on the material during the workshop without technical distractions.

Ideally, you should be able to install open-source software from the internet both before and during the workshop. If this is not possible, please contact Steve as soon as possible.

Everything we do in the workshop will involve R. If you do not use R, please email Steve and briefly describe your coding background.

Installing a Sufficiently Recent Version of R

If you are familiar with R and already have it installed, ensure that you have a sufficiently recent version. To check, start R and print the version using the following command:

print(R.version.string)
## [1] "R version 4.4.2 (2024-10-31)"

This shows that I am using R version 4.4.2 (2024-10-31). The version you get will likely be different. You need R version 4.3.0 or newer. If your version is too old, please install the latest version of R by following the instructions here.

If you do not have R installed, I recommend following the installation instructions for RStudio. These instructions guide you through installing R first, followed by RStudio, which is the program I will use to interact with R during the workshop.

You are welcome to use R without RStudio but, unless you have a strong preference, I recommend using RStudio.

Installing Supporting R Packages

The macpan2 package is designed to be used alongside a collection of packages known as the tidyverse. To install these packages, along with an additional package we will be using, open R and run the following command:

install.packages(c("tidyverse", "broom.mixed"))

Installing macpan2

To install macpan2, please run the following commands in R:

repos = c('https://canmod.r-universe.dev', 'https://cloud.r-project.org')
install.packages('macpan2', repos = repos)

Verify that Everything Worked

First, ensure that the packages load without errors. Run the following command in R and check that you receive a similar report about loaded packages. The output does not need to be identical, but it should be free of errors.

library(macpan2); library(tidyverse)
## Warning: package 'macpan2' was built under R version 4.4.3

## ── Attaching core tidyverse packages ──────────────────────────────────────────────────────────────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::all_equal() masks macpan2::all_equal()
## ✖ dplyr::filter()    masks stats::filter()
## ✖ dplyr::lag()       masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

To fully verify that everything is set up correctly, copy and paste the following lines of code into R to simulate an SIR model. Ensure that the output matches the graph shown below.

("starter_models"
 |> mp_tmb_library("sir", package = "macpan2")
 |> mp_simulator(time_steps = 50, outputs = "infection")
 |> mp_trajectory()
 |> mutate(incidence = value)
 |> ggplot() 
 + geom_line(aes(time, incidence))
 + theme_bw()
)