Back to Course
Introduction to Modelling Infectious Diseases in R
0% Complete
0/0 Steps
-
MODULE 1: SIR Model Basics
Introduction to Compartmental Models for Infectious Disease -
Introduction to Ordinary Differential Equations (ODEs) and the SIR Model
-
Introduction to SIR Modelling in R
-
MODULE 2: SIR Model ExtensionsModelling Density-dependent vs. Frequency-dependent Transmission
-
SIR model with Demographics
-
CASE STUDY: Modelling with Real-World DataSEIR & SEIRW models for Hepatitis E Virus (HEV) Outbreaks: A Case Study
-
MODULE 3: Epidemic ThresholdsThe Basic Reproduction Number (R0)
-
The Effective Reproduction Number (Re)
-
Vaccination and Herd Immunity
-
Practical Example: Models for Infectious Disease Management & PolicyVaccination Strategies to Control Hepatitis E Outbreaks: A Modeling Study (Cooper et al. 2018)
Lesson 5 of 10
In Progress
SIR model with Demographics
Lesson Video
🚗 Video too fast or too slow? Click the gear icon ⚙️ at the bottom-right to change the speed!
Click here to view and download this video from Vimeo.
Lesson code
Please download the R Markdown script linked below to code along with the instructor.
You need to click the download button on the top right menu.

Lesson Notes
Lesson Slides
👋 Before you go, leave an anonymous rating & feedback
Average rating 4 / 5. Vote count: 4
No votes so far! Be the first to rate this post.
Please share any positive or negative feedback you may have.
Feedback is completely anonymous
For Exercise 4, the solution does not match the prompt:
The prompt asks for a model seir_vital_dynamics and the model diagram includes an exposed population with a sigma disease progression parameter.
The solution function describes an SIR model without an exposed population.
FYI in section 1.3.1 Step 1: Setting Initial Conditions and Parameters the parameters in the text and the given parameters in the code block do not match. The code block seems to give the correct values to match the plot.
Here is what the text says
We begin by defining the initial conditions and parameters for the model:
Here is what the code block says
# Define initial conditions
initial_state <- c(S = 99, I = 1, R = 0)
# Define parameters including birth and death rate
parameters <- c(beta = 0.002, # Transmission rate
gamma = 0.1, # Recovery rate
mu = 0.02) # Natural Birth/Death rate
# Time span for simulation
times <- seq(0, 400, by = 1)
In the third exercise (using the SIR model simulator, investigate how different values of Alpha: infection-induced mortality rate, impact the dynamics of the disease. ), I used also in Studio R, the same data used in the simulator, I don’t know why I don’t find the same result with the simulator. There is some explanation ? ::: practice **Exercise 3** Using the SIR model simulator, investigate how different values of $\alpha$ (infection-induced death rate) impact the disease dynamics. Use the following parameters: – Initial population: 100 (with 99 susceptible, 1 infected, and 0 recovered) – Transmission rate ($\beta$): 0.1 – Recovery rate ($\gamma$): 0.014 – Birth/death rate ($\mu$): 0.01 – Infection-Induced death rate ($\alpha$): 0.01 – Transmission Type: Frequency Dependent Vary $\alpha$ from 0.01 to 0.05 in increments of 0.01. ::: ##### Step 1: Defining Initial Conditions and Parameters SIR model simulator {r} <pre class="ql-syntax" spellcheck="false">initial_state <- c (S = 99, I = 1, R = 0) N <- 100 parameters <- c(beta = 0.1, gamma = 0.014, mu = 0.01, alpha = 0.01) </pre> ##### Step 2: Writing the SI Model Function with Infection-Induced Deaths {r} <pre class="ql-syntax" spellcheck="false">sir_model_infections_deaths <- function(times, states, parameters) {with(as.list(c(states, parameters)),{ dS = (-beta * S * I )/N dI = (beta * S… Read more »
Hello! It looks like the Birth/death rate parameter (mu) is missing in your differential equations. This model has both infection-induced deaths and natural births and deaths. So the dS equation should have + mu*N and – mu*S, and the dI and dR equations should have -mu*I and -mu*R, respectively. Try adding those terms and running the simulation again.