In this lesson, we will extend the classic SIR model by first introducing vital dynamics—the processes of birth and natural death. After establishing the fundamentals of incorporating these dynamics, we’ll further refine our model to include infection-induced deaths. This progression will allow us to understand the effects of both natural and infection-specific mortality on disease dynamics.
Today, you will learn how to modify the SIR model to incorporate both types of mortality and how to implement these modifications in R.
Let’s get started!
By the end of this lesson, you should be able to:
This lesson will require the following packages to be installed and loaded:
The classic SIR model assumes a closed population with no births, deaths, or migration. To model real-world scenarios more accurately, we introduce vital dynamics—the inclusion of birth and natural death rates.
Including natural birth and death rates in the SIR model provides a more realistic representation of population dynamics, especially over longer time periods. This modification is crucial when:
The Role of Migration in Vital Dynamics
In addition to birth and death rates, migration—which includes both immigration (inflow) and emigration (outflow)—plays a crucial role in shaping population dynamics.
Migration can introduce or remove individuals from any of the compartments: susceptible (S), infected (I), or recovered (R). This means that population movement can bring in or take away susceptible individuals, active infections, or recovered cases, significantly influencing the spread and progression of an epidemic. By incorporating both inflow and outflow, the model more accurately captures real-world scenarios where migration affects transmission rates and population structure over time.
Adding birth and death rates to the SIR model affects the behavior of the system in several important ways, especially when modeling populations over long periods of time. Here’s what happens when we incorporate vital dynamics:
Endemic Equilibrium: The continuous inflow of newborns into the susceptible compartment keeps the disease circulating in the population, potentially leading to an endemic equilibrium. This is where the number of infected individuals stabilizes over time, and the disease remains present at a low level without completely dying out.
Disease Persistence: In the basic SIR model, the disease might fade out after a large portion of the population has recovered. However, with births replenishing the susceptible population, the disease can persist indefinitely. This is particularly important for modeling diseases that never fully disappear, like seasonal flu or endemic infections.
Cyclical Patterns: In populations where the birth rate is high, the disease may exhibit cyclical patterns. New susceptible individuals enter the population regularly, and once they accumulate to a certain threshold, outbreaks may occur again. This leads to cycles of infection over time, which more accurately reflects long-term disease dynamics in the real world.
Population Turnover: By including natural deaths, we introduce population turnover—the replacement of individuals through birth and death. Infected individuals who would otherwise remain in the infected or recovered compartments are regularly removed from the population due to natural mortality, balancing the system and preventing any one compartment from indefinitely growing.
Incorporating vital dynamics into the SIR model introduces the following critical insights:
Long-Term Disease Dynamics: Over long time periods, this extended model captures how diseases behave in populations with continuous births and deaths. It accounts for both the inflow of susceptible individuals and the gradual removal of infected and recovered individuals through natural deaths.
More Realistic Epidemic Predictions: The model with vital dynamics provides a more realistic depiction of diseases that persist in populations over time, especially for endemic diseases. It also allows for the exploration of long-term interventions and public health strategies to manage such diseases.
In real-world populations, individuals are born and die continuously. Over long periods, it’s essential to incorporate these vital dynamics into our model to capture realistic disease dynamics.
In the basic SIR model, we assumed a closed population, meaning that the population does not change over time. This assumption is reasonable for short-term outbreaks, but over longer periods, populations change through births and deaths, which can significantly influence disease transmission patterns. In this section, we’ll extend the SIR model to include natural births and deaths, creating a more comprehensive model.
In our extended model, newborns enter the population as susceptible individuals because they are not infected at birth. Therefore, the birth rate directly increases the S compartment. We assume that the birth rate is proportional to the total population size, and that newborns are immediately susceptible to the disease.
Deaths can occur in any of the three compartments—susceptible, infected, or recovered. This means that individuals may die regardless of their disease status. Therefore, we apply the same death rate, \(\mu\), across all compartments.
For simplicity, let’s also assume that the total population size will remain constant, at \(N\). This is not always the case - if we, for example, model a disease over decades in a setting with high birth rate, the birth rate can be higher than death rate.
Let’s try to create a conceptual diagram that incorporates births and accounts for deaths in our SIR model. For this we will build on from our SIR model’s conceptual diagram.
The SIR Model
The SIR model consists of three compartments:
And two critical parameters:
Let’s explore the SIR model with births and natural deaths!
where:
This extended SIR model divides the population into three compartments:
And three critical parameters:
To mathematically represent the model, we modify the system of differential equations for each compartment:
Susceptible individuals can increase through births and decrease by becoming infected or through natural deaths.
\[ \frac{dS}{dt} = \mu N - \beta SI - \mu S \]
Infected individuals increase when susceptible individuals become infected, but they decrease through recovery or natural deaths.
\[ \frac{dI}{dt} = \beta SI - \gamma I - \mu I \]
Recovered individuals increase when infected individuals recover, but they also decrease through natural deaths.
\[ \frac{dR}{dt} = \gamma I - \mu R \]
where:
ODEs for Frequency-dependent Transmission
To mathematically represent the model for a frequency-dependent transmission, we modify the differential equations:
\[ \frac{dS}{dt} = \mu N - \frac{\beta SI}{N} - \mu S \]
\[ \frac{dI}{dt} = \frac{\beta SI}{N} - \gamma I - \mu I \]
\[ \frac{dR}{dt} = \gamma I - \mu R \]
where:
Let’s start by implementing the SIR model with natural birth and death rates in R. For this, we will use a generic example.
We begin by defining the initial conditions and parameters for the model:
Let’s define this in R:
Next, we define the SIR model function that incorporates vital dynamics:
sir_model_vital <- function(time, state, parameters) {
with(as.list(c(state, parameters)), {
# Calculate total population size
N <- S + I + R
# Rate of change with vital dynamics
dS <- mu * N - beta * S * I - mu * S
dI <- beta * S * I - gamma * I - mu * I
dR <- gamma * I - mu * R
# Return the rate of change
list(c(dS, dI, dR))
})
}We then use the ode function from the {deSolve} package
to solve the differential equations:
We now need to convert the output to a data frame and visualize the dynamics:
# Convert to dataframe
sir_vital_out <- as.data.frame(sir_vital_out)
# Plot the results
ggplot(sir_vital_out, aes(x = time)) +
geom_line(aes(y = S, color = "Susceptible")) +
geom_line(aes(y = I, color = "Infectious")) +
geom_line(aes(y = R, color = "Recovered")) +
labs(title = "SIR Model with Births and Deaths", x = "Time (days)", y = "Proportion of Population") +
scale_color_manual(values = c("Susceptible" = "#2F5597", "Infectious" = "#C00000", "Recovered" = "#548235")) +
theme_minimal() +
theme(legend.title = element_blank())In this model, with \(\mu = 0.02\), we introduce a natural birth and death process:
The introduction of a birth/death rate ensures that the disease becomes endemic, meaning it persists over time, rather than disappearing entirely, as in the no-birth/death case.
Exercise 1
Modify the SIR model with vital dynamics to include an Exposed (E) compartment, creating an SEIR model. The model should also incorporate natural births and deaths (i.e., include the birth/death rate \(\mu\)). Use the following parameters and conceptual diagram:
Tasks:
In some infectious diseases, the mortality caused directly by the infection can significantly influence the disease’s dynamics. This concept is known as infection-induced deaths, where individuals succumb to the disease rather than dying from natural causes.
Infections like Ebola or severe strains of influenza lead to high mortality rates among those infected. In such scenarios, it’s crucial to model the epidemic by considering the infection-induced death rate (\(\alpha\)) to understand the true impact of the disease on the population. This is particularly relevant when:
By incorporating only infection-induced deaths into the SIR model, we can observe the following effects:
Direct Impact on Infected Population: The infection-induced death rate (\(\alpha\)) specifically reduces the number of infected individuals, representing the direct fatalities caused by the disease.
Altered Recovery and Disease Progression: As some infected individuals die, fewer people recover, which alters the disease’s progression through the population.
Simplified Model: Without the birth and natural death rates, the model focuses purely on disease transmission, recovery, and infection-induced mortality, making it clearer and easier to analyze.
To incorporate infection-induced deaths into the SIR model, we introduce the parameter \(\alpha\). This modification gives us a more straightforward view of how the disease affects the population.
Let’s explore the SIR model with infection-induced deaths:
The simplified SIR model includes three compartments:
And three critical parameters:
The differential equations for this modified SIR model are:
\[ \frac{dS}{dt} = -\beta SI \]
\[ \frac{dI}{dt} = \beta SI - \gamma I - \alpha I \]
\[ \frac{dR}{dt} = \gamma I \]
where:
\(\beta\) is the transmission rate (rate at which susceptible individuals become infected),
\(\gamma\) is the recovery rate (rate at which infected individuals recover),
\(\alpha\) is the infection-induced death rate (rate at which infected individuals die from the disease).
The transmission is density-dependent.
ODEs for Frequency-dependent Transmission
To mathematically represent the model for a frequency-dependent transmission, we modify the differential equations:
\[ \frac{dS}{dt} = \mu N - \frac{\beta SI}{N} - \mu S \]
\[ \frac{dI}{dt} = \frac{\beta SI}{N} - \gamma I - \alpha I \]
\[ \frac{dR}{dt} = \gamma I - \mu R \]
where:
To implement this model, we will once again use the same generic example as before.
Let’s start by setting our initial conditions, similarily as we did in our previous example:
The next step is to define the SIR model function that incorporates only infection-induced deaths:
We solve the differential equations using the ode
function from the {deSolve} package.
We convert the output to a data frame and visualize it using
ggplot2:
# Convert the output to a data frame
sir_infection_deaths_out <- as.data.frame(sir_infection_deaths_out)
# Plot the results
ggplot(sir_infection_deaths_out, aes(x = time)) +
geom_line(aes(y = S, color = "Susceptible")) +
geom_line(aes(y = I, color = "Infectious")) +
geom_line(aes(y = R, color = "Recovered")) +
labs(title = "SIR Model with Infection-Induced Deaths",
x = "Time (days)", y = "Proportion of Population") +
scale_color_manual(values = c("Susceptible" = "#2F5597", "Infectious" = "#C00000", "Recovered" = "#548235")) +
theme_minimal() +
theme(legend.title = element_blank())In this model, you will notice several key differences:
Since there’s no natural birth or death process (\(\mu = 0\)), the total population (N) decreases over time, contributing to the eventual disappearance of the disease.
Exercise 2
Modify the SIR model with vital dynamics to create an SI model that only includes Susceptible (S) and Infected (I) compartments. The model should incorporate infection-induced deaths (i.e., include the infection-induced rate \(\alpha\)) with a frequency-dependent transmission. Use the following parameters and the conceptual diagram below:
Tasks:
ggplot2.Now that you are familiar with the concepts of vital dynamics, let’s explore how these elaborations to the SIR model impact the spread and dynamic of a disease!
The simulation below allows you to explore how changes in the parameters \(\beta\), \(\gamma\), \(\mu\), and \(\alpha\) affect the dynamics of the SIR model. Adjust the values to see how the susceptible (S), infected (I), and recovered (R) populations change over time.
To view the live version of the simulation, click here!
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:
Vary \(\alpha\) from 0.01 to 0.05 in increments of 0.01.
Let’s explore how the vital dynamic parameters (\(\mu\) and \(\alpha\)) influence the spread of a disease using a practical example and using the SIR Model Simulation.
Assume the following initial settings for our population of 100 individuals over the course of 1 year:
This graph shows the classic SIR (Susceptible-Infected-Recovered) model with no vital dynamics (no births or deaths). At the start:
Since there are no births, natural deaths, or infection-induced deaths, the total population (N) remains constant, and the dynamics only depend on transmission and recovery rates.
We have previously seen how \(\mu\) and \(\alpha\) individually affect the SIR model; however, we have not explored their effect when both are introduced. Let’s now see what happens in that case!
For this, let’s set \(\mu = 0.02\) and \(\alpha = 0.02\).
In this combined scenario:
Overall, this model balances the effects of both vital dynamics and infection-induced deaths, showing a sustained yet lower-level presence of the disease over time. The system reaches a steady state where births maintain the population, while infection-induced deaths prevent uncontrolled outbreaks.
Exercise 4
Write an R function called seir_vital_dynamics that
represents a frequency-dependent SIR model that
includes natural births/deaths and infection-induced deaths. Use the SIR
conceptual diagram below as a reference.
In this lesson, we first extended the classic SIR model to include vital dynamics, accounting for natural births and deaths. We then introduced infection-induced deaths to further refine the model, providing a more realistic view of disease impact. These modifications help us understand the complex interplay between natural and infection-specific mortality and the spread of disease in a population.
By implementing these models in R, we gained practical insights into modeling disease dynamics and the importance of considering different mortality factors.
Exercise 1
Defining Initial Conditions and Parameters
# Initial conditions
initial_state <- c(S = 990, E = 5, I = 4, R = 1)
# Define parameters
parameters <- c(beta = 0.002, # Transmission rate
sigma = 0.1, # Progression rate
gamma = 0.05, # Recovery rate
mu = 0.01) # Birth/Death rateSEIR Model Function with Births/Deaths (\(\mu\))
# Define the SEIR model function with birth/death rate (mu)
seir_model_vital <- function(time, state, parameters) {
with(as.list(c(state, parameters)), {
# Total population
N <- S + E + I + R
# Rate of change
dS <- mu * N - beta * S * I - mu * S
dE <- beta * S * I - sigma * E - mu * E
dI <- sigma * E - gamma * I - mu * I
dR <- gamma * I - mu * R
# Return the rate of change
list(c(dS, dE, dI, dR))
})
}Solving the SEIR Model
# Time span for the simulation
times <- seq(0, 200, by = 1)
# Solve the SEIR model
seir_vital_out <- ode(
y = initial_state,
times = times,
func = seir_model_vital,
parms = parameters
)
# Convert to a data frame
seir_vital_out <- as.data.frame(seir_vital_out)
# Plot the results
library(ggplot2)
ggplot(seir_vital_out, aes(x = time)) +
geom_line(aes(y = S, color = "Susceptible")) +
geom_line(aes(y = E, color = "Exposed")) +
geom_line(aes(y = I, color = "Infected")) +
geom_line(aes(y = R, color = "Recovered")) +
labs(title = "SEIR Model with Natural Births and Deaths", x = "Time (days)", y = "Population Count") +
scale_color_manual(values = c("Susceptible" = "blue", "Exposed" = "orange", "Infected" = "red", "Recovered" = "green")) +
theme_minimal()Exercise 2
Step 1: Defining Initial Conditions and Parameters
# Define initial conditions
initial_state <- c(S = 990, I = 10)
# Define parameters
parameters <- c(beta = 0.1, # Transmission rate
alpha = 0.02) # Infection-induced rateStep 2: Writing the SI Model Function with Births/Deaths and Frequency-Dependent Transmission
# Define the SI model function with natural births/deaths and frequency-dependent transmission
si_model_freq <- function(time, state, parameters) {
with(as.list(c(state, parameters)), {
# Total population
N <- S + I
# Rate of change
dS <- - (beta * S * I / N)
dI <- (beta * S * I / N) - alpha * I
# Return the rate of change
list(c(dS, dI))
})
}Step 3: Solving the Model Using the ode
Function
# Load the deSolve package
if(!require(deSolve)) install.packages("deSolve")
library(deSolve)
# Time span for the simulation
times <- seq(0, 400, by = 1)
# Solve the SI model
si_freq_out <- ode(
y = initial_state,
times = times,
func = si_model_freq,
parms = parameters
)
# Convert the output to a data frame
si_freq_out <- as.data.frame(si_freq_out)Step 4: Plotting the Results Using
ggplot2
# Load the ggplot2 package
if(!require(ggplot2)) install.packages("ggplot2")
library(ggplot2)
# Plot the results
ggplot(si_freq_out, aes(x = time)) +
geom_line(aes(y = S, color = "Susceptible")) +
geom_line(aes(y = I, color = "Infected")) +
labs(title = "SI Model with Births/Deaths and Frequency-Dependent Transmission",
x = "Time (days)", y = "Population Count") +
scale_color_manual(values = c("Susceptible" = "blue", "Infected" = "red")) +
theme_minimal() +
theme(legend.title = element_blank())Exercise 3
Overall Impact of Varying \(\alpha\) on Disease Dynamics:
Higher \(\alpha\) Values: Increase the rate at which infected individuals die, thereby reducing the infection’s ability to spread. This results in a shorter outbreak with a lower peak of infected individuals and fewer recovered individuals.
Lower \(\alpha\) Values: Allow the disease to spread more extensively, leading to a higher peak of infected individuals and a prolonged epidemic duration.
Exercise 4
# Define the SIR model function for Frequency Dependent (FD)
sir_model_fd <- function(time, state, parameters) {
with(as.list(c(state, parameters)), {
# Calculate total population size
N <- S + I + R
# Rate of change with frequency-dependent transmission
dS <- mu * N - beta * S * I / N - mu * S
dI <- beta * S * I / N - gamma * I - (mu + alpha) * I
dR <- gamma * I - mu * R
# Return the rate of change
list(c(dS, dI, dR))
})
}The following team members contributed to this lesson:
This work is licensed under the Creative Commons Attribution Share Alike license.