This package solves the SEIR model for the spread of a virus. In the example, the parameters of Wang et al. (2020) are used for the case of Wuhan, China. The model is available in Matlab on Peter Forsyth webpage https://cs.uwaterloo.ca/~paforsyt/SEIR.html. In fact, the R package is based on the work of Peter. You are invited to read his page for more details about the model. The system of differencial equations is: ˙S(t)=−β(t)S(t)I(t)N˙E(t)=β(t)S(t)I(t)N−σE(t)˙I(t)=σE(t)−γI(t)+cR(t)I(t)N˙R(t)=γI(t)−cR(t)I(t)N where β(t)=γRZero(t) and RZero(t) is the number of individuals infected by an infectious person, γ is 1 over the recovery period (in days), and σ is 1 over the latent period (days). It is a function of time because the transmission if function of the social distancing policy in place.
The package is available on R-Forge (https://r-forge.r-project.org/) and can be installed by typing the following command in R:
install.packages("SEIR", repos="http://R-Forge.R-project.org")
The main function is solveSEIR. It creates an object of class ``seir’’. The main arguments are (See Peter’s Matlab code for the source):
In this document, we use the default parameter used by Peter Forsyth. The important factor is RZero(t), which is determined by the arguments tyee an r0. The default type is ``LIN’’ and the default r0 is:
matrix(c(0, 20, 70,
84, 90, 3, 2.6, 1.9, 1, 0.5), ncol = 2)
## [,1] [,2]
## [1,] 0 3.0
## [2,] 20 2.6
## [3,] 70 1.9
## [4,] 84 1.0
## [5,] 90 0.5
It means that the value of RZero(t) changes at t=20, 70, 84 and 90 (days). The type argument determines how it changes. By default it looks like the following:
Therefore, RZero(t) is a linear interpolation between the different values. The other option is to have a constant RZero(t) between periods as in the following graph.
The first RZero(t) is the default option. If we run the function with all default values we obtain (the print method summarizes the result):
Sol <- solveSEIR()
Sol
## SEIR model for the spread of a virus
## ************************************
## Initial condition
## Total Cases (thousands): 0.8400
## Active Cases (thousands): 0.8400
## Condition after 180 Days
## Total Cases (thousands): 121.4800
## Active Cases (thousands): 4.1200
The object contains the following elements:
names(Sol)
## [1] "y" "t" "h" "RZero" "Pop"
The element y is an nT×4 matrix, where nT is the number of grid points (the closest integer of T/h), with the ith row being the solution {S(ti),E(ti),I(ti),R(ti)}. The element t is the time grid and RZero is an nT vector with the ith element being RZero(ti). The “[” method can be used to get the solution at different points in time:
Sol[c(10,50,100,150)]
## S E I R
## 10 10998599 659.1349 1097.600 484.1839
## 50 10977389 4795.2626 9218.391 9437.0239
## 100 10903111 4199.9912 24144.378 69384.5890
## 150 10883650 1193.8311 7305.064 108691.5642
It is possible to use those elements to plot the solution, but the easiest ways is to use the plot method. The plot method gives you options to plot any of the curve:
plot(Sol, "acase")
plot(Sol, "tcase")
plot(Sol, "both")
plot(Sol, "rzero")
You can also plot them one by one:
plot(Sol, "E")
plot(Sol, "I")
As a last example, we can reproduce the second wave case produced by Peter Forsyth on his website. Suppose RZero stays at 0.5 for 30 days and then the government start relaxing the social distancing restrictions. The following is what he proposes:
zbreaks <- matrix(c(0, 20, 70, 84, 90, 120, 240, 360,
3, 2.6, 1.9, 1, 0.5, 0.5, 1.75, 0.5), ncol = 2)
Sol <- solveSEIR(T=450, r0=zbreaks)
plot(Sol, "rzero")
The new solution is:
plot(Sol, "acase")
plot(Sol, "both")
You can also run the R-app. It offers an interactive way to see the effect of modifying the parameters on the solution. To run the app you need the package shiny. After installing the packages shiny, download the file app.R and type the following in R:
runApp('app.R')
The following window should open in your browser with the option of modifying the parameters of the model.
Wang, H., Z. Wang, Y Dong, R. Chang, C. Xu, X. Yu, S. Zhang, et al. 2020. “Phase-Adjusted Estimation of the Number of Coronavirus Disease 2019 Cases in Wuhan, China.” Cell Discov 6 (10). https://doi.org/10.1038/s41421-020-0148-0.