forked from lilywang1988/eSIR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
168 lines (122 loc) · 9.81 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
title: "R package eSIR: extended state-space SIR epidemiological models"
author: "[Song Lab](http://www.umich.edu/~songlab/)"
date: "`r Sys.Date()`"
output: github_document
---
```{r setup, include=FALSE, echo=FALSE}
knitr::opts_chunk$set(collapse = TRUE,
comment = "#>",
fig.width=12, fig.height=8,
fig.path = "man/figures/README-")
```
Chinese version:[中文](https://github.com/lilywang1988/eSIR/blob/master/README_cn.md)
## Purpose
The outbreak of novel Corona Virus disease (a.k.a. COVID-19), originated in Wuhan, the capital of Hubei Province spreads quickly and affects many cities in China as well as many countries in the world. The Chinese government has enforced very stringent quarantine and inspection to prevent the worsening spread of COVID-19. Although various forms of forecast on the turning points of this epidemic within and outside Hubei Province have been published in the media, none of the prediction models has explicitly accounted for the time-varying quarantine protocols. We extended the classical SIR model for infectious disease by incorporating forms of medical isolation (in-home quarantine and hospitalization) in the underlying infectious disease dynamic system. Using the state-space model for both daily infected and hospitalized incidences and MCMC algorithms, we assess the effectiveness of quarantine protocols for confining COVID-19 spread in both Hubei Province and the other regions of China. Both predicted turning points and their credible bands may be obtained from the extended SIR under a given quarantine protocol. R software packages are also made publicly available for interested users.
The standard SIR model has three components: susceptible, infected, and removed (including the recovery and dead). In the following sections, we will introduce the other extended state-space SIR models and their implementation in the package. **The results provided below are based on relatively short chains.** According to our experience, this setting (`M=5e3` and `nburnin=2e3`) should provide acceptable results in terms of the trend and turning points estimation, the estimation of parameters and their credible intervals might not be accurate. Hence, if possible, we would recommend using `M=5e5` and `nburnin=2e5` to obtain stable MCMC chains via [`rjags`](https://cran.r-project.org/web/packages/rjags/index.html).
![Standard SIR](man/figures/model0.png)
![BDSSM SIR](man/figures/BDSSM.png)
![Standard SIR](man/figures/RK4.png)
![Standard SIR](man/figures/priors.png)
![Standard SIR](man/figures/algorithm.png)
## Preparation
[Download Binary Package](https://github.com/lilywang1988/eSIR/blob/master/install_binary)
To install and use this R package from Github, you will need to first install the R package `devtools`. Please uncomment the codes to install them. `eSIR` depends on three other packages, `rjags` (an interface to the JAGS library), `chron` and `gtools`, which could be installed with `eSIR` if not yet.
An error may occur if you have not yet installed JAGS-4.x.y.exe (for any x >= 0, y >=0). **Windows** users may download and install JAGS from [here](http://www.sourceforge.net/projects/mcmc-jags/files). **Mac** users may follow steps at [casallas/8411082](https://gist.github.com/casallas/8411082).
``` r
# install.packages("devtools")
# library(devtools)
#for information and covariance calculation; sample size computation using Hasegawa proposal
# install_github("lilywang1988/eSIR")
library(eSIR)
```
Our data are collected daily from [dxy.com](https://mama.dxy.com/outbreak/daily-of-nationwide-new?index=20200206&locationIds=999&from=todh5). Alternatively, we notice some convenient access to COVID-19 data from [GuangchuangYu/nCov2019](https://github.com/GuangchuangYu/nCov2019) and [qingyuanzhao/2019-nCov-Data](https://github.com/qingyuanzhao/2019-nCov-Data).
``` r
# Data of COVID-19 can be found in the following R packages:
# install_github("GuangchuangYu/nCov2019")
#library(nCov2019)
# install_github("qingyuanzhao/2019-nCov-Data")
#library(2019-nCov-Data)
```
In Ubuntu (18.04) Linux, please first update R to a version >= 3.6. You may need to install jags package as well by `sudo apt-get install jags` before install devtools by `install.packages("devtools")`.
## Model 1 using `tvt.eSIR()`: a SIR model with a time-varying transmission rate
By introducing a time-dependent $$\pi(t)\in [0,1]$$ function that modifies the transmission rate $$\beta$$, we can depict a series of time-varying changes caused by either external variations like government policies, protective measures and environment changes, or internal variations like mutations and evolutions of the pathogen.
The function can be either stepwise or exponential:
![pi functions](man/figures/pi_functions.png)
![Standard SIR](man/figures/model1.png)
```{r model1}
set.seed(20192020)
library(eSIR)
# Hubei province data Jan13 -> Feb 11
# cumulative number of infected
NI_complete <- c( 41,41,41,45,62,131,200,270,375,444,549, 729,
1052,1423,2714,3554,4903,5806,7153,9074,11177,
13522,16678,19665,22112,24953,27100,29631,31728,33366)
RI_complete <- c(1,1,7,10,14,20,25,31,34,45,55,71,94,121,152,213,
252,345,417,561,650,811,1017,1261,1485,1917,2260,
2725,3284,3754)
N=58.5e6
R <- RI_complete/N
Y <- NI_complete/N- R #Jan13->Feb 11
### Step function of pi(t)
change_time <- c("01/23/2020","02/04/2020","02/08/2020")
pi0<- c(1.0,0.9,0.5,0.1)
res.step <-tvt.eSIR(Y,R,begin_str="01/13/2020",death_in_R = 0.4,T_fin=200,
pi0=pi0,change_time=change_time,dic=T,casename="Hubei_step",
save_files = T, save_mcmc=F,save_plot_data = F,M=5e3,nburnin = 2e3)
res.step$plot_infection
res.step$plot_removed
res.step$spaghetti_plot
res.step$dic_val
### continuous exponential function of pi(t)
res.exp <- tvt.eSIR(Y,R,begin_str="01/13/2020",death_in_R = 0.4,
T_fin=200,exponential=TRUE,dic=F,lambda0=0.05,
casename="Hubei_exp",save_files = F,save_mcmc=F,
save_plot_data = F,M=5e3,nburnin = 2e3)
res.exp$plot_infection
res.exp$spaghetti_plot
#res.exp$plot_removed
### without pi(t), the standard state-space SIR model without intervention
res.nopi <- tvt.eSIR(Y,R,begin_str="01/13/2020",death_in_R = 0.4,T_fin=200, casename="Hubei_nopi",save_files = F,save_plot_data = F,
M=5e3,nburnin = 2e3)
res.nopi$plot_infection
res.nopi$spaghetti_plot
#res.nopi$plot_removed
```
## Model 2 using `qh.eSIR()`: SIR with time-varying quarantine, which follows a Dirac Delta function
By introducing a vector of `phi` and its corresponding changing points `change_time`, we introduced a quarantine process that is dependent on a dirac delta function $\phi_t\in [0,1]$. In other words, only at time points defined by `change_time`, we have certain porportions of the at-risk (susceptible) subjects moved to the quarantine stage. The difference of this model than the previous time-varying transmission one is that we do not allow the tranmission rate to change, but only let the proportion of susceptible subjects decrease.
![Standard SIR](man/figures/model2.png)
![phi](man/figures/phi_functions.png)
```{r model2}
set.seed(20192020)
NI_complete <- c( 41,41,41,45,62,131,200,270,375,444,549, 729,
1052,1423,2714,3554,4903,5806,7153,9074,11177,
13522,16678,19665,22112,24953,27100,29631,31728,33366)
RI_complete <- c(1,1,7,10,14,20,25,31,34,45,55,71,94,121,152,213,
252,345,417,561,650,811,1017,1261,1485,1917,2260,
2725,3284,3754)
N=58.5e6
R <- RI_complete/N
Y <- NI_complete/N- R #Jan13->Feb 11
change_time <- c("01/23/2020","02/04/2020","02/08/2020")
phi0 <- c(0.1,0.4,0.4)
res.q <- qh.eSIR (Y,R,begin_str="01/13/2020",death_in_R = 0.4,
phi0=phi0,change_time=change_time,casename="Hubei_q",
save_files = T,save_mcmc = F,save_plot_data = F,
M=5e3,nburnin = 2e3)
res.q$plot_infection
#res.q$plot_removed
#res.noq <- qh.eSIR (Y,R,begin_str="01/13/2020",death_in_R = 0.4,
# T_fin=200,casename="Hubei_noq",
# M=5e3,nburnin = 2e3)
#res.noq$plot_infection
```
You will obtain the following plot in addition to the traceplots and summary table if you set `save_file=T` in `qh.eSIR`. The blue vertical line denotes the beginning date, and the other three gray lines denote the three change points.
![Standard SIR](man/figures/Hubei_qthetaQ_plot.png)
## Outputs and summary table
To save all the plots (including trace plots) and summary tables, please set `save_files=T`, and if possible, provide a location by setting `file_add="YOUR/FAVORITE/FOLDER"`. Otherwise, the traceplots and other intermediate plots will not be saved, but you can still retrieve the forecast plots and summary table based on the return list, e.g., using `res.step$forecast_infection` and `res.step$out_table`. Moreover, if you are interested in plotting the figures on your own, you may set `save_mcmc=T` so that all the MCMC draws will be saved in a `.RData` file too.
For details, please explore our package directly. We have `.rd` files established, please use `help(tvt.eSIR)` or `?qh.eSIR` to find them.
## References
1. Song, P. X., Wang, L., Zhou, Y., He, J., Zhu, B., Wang, F., ... & Eisenberg, M. (2020). An epidemiological forecast model and software assessing interventions on COVID-19 epidemic in China. medRxiv.
2. Osthus, D., Hickmann, K. S., Caragea, P. C., Higdon, D., & Del Valle, S. Y. (2017). Forecasting seasonal influenza with a state-space SIR model. The annals of applied statistics, 11(1), 202.
3. Mkhatshwa, T., & Mummert, A. (2010). Modeling super-spreading events for infectious diseases: case study SARS. arXiv preprint arXiv:1007.0908.