├── .Rbuildignore
├── .gitignore
├── DESCRIPTION
├── LICENSE.md
├── NAMESPACE
├── R
├── eSAIR.R
├── eSIR.R
├── qh.eSIR.R
├── tvt.eSIR.R
├── tvt.eSIR2.R
└── utils.R
├── README.Rmd
├── README.md
├── README_cn.md
├── data
├── USA_state_N.rda
├── confirmed.rda
├── death.rda
└── recovered.rda
├── eSIR.Rproj
├── eSIR.pdf
├── install_pkg
├── eSIR_0.2.5.tgz
├── eSIR_0.2.6.tgz
├── eSIR_0.2.7.tgz
├── eSIR_0.2.8.tgz
├── eSIR_0.3.0.tar.gz
├── eSIR_0.3.0.tgz
├── eSIR_0.3.1.tar.gz
├── eSIR_0.3.1.tgz
├── eSIR_0.3.2.tar.gz
├── eSIR_0.3.2.tgz
├── eSIR_0.3.3.tar.gz
└── eSIR_0.3.3.tgz
├── man
├── eSAIR.Rd
├── figures
│ ├── BDSSM.png
│ ├── Hubei_qthetaQ_plot.png
│ ├── README-model 3-1.png
│ ├── README-model1-1.png
│ ├── README-model1-10.png
│ ├── README-model1-11.png
│ ├── README-model1-12.png
│ ├── README-model1-2.png
│ ├── README-model1-3.png
│ ├── README-model1-4.png
│ ├── README-model1-5.png
│ ├── README-model1-6.png
│ ├── README-model1-7.png
│ ├── README-model1-8.png
│ ├── README-model1-9.png
│ ├── README-model2-1.png
│ ├── README-model2-2.png
│ ├── RK4.png
│ ├── SAIR_ODE.png
│ ├── algorithm.png
│ ├── eSAIR_compartment.png
│ ├── model0.png
│ ├── model1.png
│ ├── model2.png
│ ├── phi.png
│ ├── phi_functions.png
│ ├── pi.png
│ ├── pi_exp.png
│ ├── pi_functions.png
│ └── priors.png
├── qh.eSIR.Rd
├── tvt.eSIR.Rd
└── tvt.eSIR2.Rd
└── meta
├── Hubei_exp2_plot_data.RData
├── Hubei_exp_plot_data.RData
├── Hubei_qR0_p.png
├── Hubei_q_Gelman_diag.txt
├── Hubei_q_forecast.png
├── Hubei_q_forecast2.png
├── Hubei_q_spaghetti.png
├── Hubei_q_summary.csv
├── Hubei_qbeta_p.png
├── Hubei_qderiv.png
├── Hubei_qgamma_p.png
├── Hubei_qk_p.png
├── Hubei_qlambdaR_p.png
├── Hubei_qlambdaY_p.png
├── Hubei_qthetaQ_p.png
├── Hubei_qthetaQ_plot.png
├── Hubei_qtheta_p.png
├── Hubei_step2_plot_data.RData
└── Hubei_step_plot_data.RData
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^.*\.Rproj$
2 | ^\.Rproj\.user$
3 | ^LICENSE.md$
4 | ^README.Rmd$
5 | ^README_cn.md$
6 | ^eSIR.pdf$
7 | ^install_binary$
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: eSIR
2 | Type: Package
3 | Title: Extended State-Space SIR Models
4 | Version: 0.4.1
5 | Authors@R: c(
6 | person("Lili", "Wang", email = "lilywang@umich.edu", role = c("aut")),
7 | person("Song Lab", role = "aut", comment = ""),
8 | person("Paul", "Egeler", email = "paul.egeler@spectrumhealth.org", role = "ctb", comment = "Spectrum Health Office of Research and Education"),
9 | person("Michael", "Kleinsasser", email = "biostat-cran-manager@umich.edu", role = c("cre"))
10 | )
11 | Description: An implementation of extended state-space SIR models developed by
12 | Song Lab at UM school of Public Health. There are several functions available
13 | by 1) including a time-varying transmission modifier, 2) adding a time-dependent
14 | quarantine compartment, 3) adding a time-dependent antibody-immunization compartment.
15 | License: CC BY 4.0
16 | Encoding: UTF-8
17 | Imports:
18 | coda (>= 0.19.3),
19 | chron (>= 2.3.54),
20 | data.table (>= 1.12.0),
21 | ggplot2 (>= 3.2.1),
22 | grDevices (>= 3.5.2),
23 | graphics (>= 3.5.2),
24 | gtools (>= 3.8.1),
25 | scales (>= 1.1.0),
26 | stats (>= 3.5.2),
27 | reshape2 (>= 1.4.3),
28 | rjags (>= 4.10),
29 | utils (>= 3.5.2)
30 | Depends: R (>= 3.5.2)
31 | RoxygenNote: 7.1.1
32 | LazyData: true
33 | Suggests:
34 | testthat (>= 3.0.0)
35 | Config/testthat/edition: 3
36 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Attribution 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More_considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution 4.0 International Public License
58 |
59 | By exercising the Licensed Rights (defined below), You accept and agree
60 | to be bound by the terms and conditions of this Creative Commons
61 | Attribution 4.0 International Public License ("Public License"). To the
62 | extent this Public License may be interpreted as a contract, You are
63 | granted the Licensed Rights in consideration of Your acceptance of
64 | these terms and conditions, and the Licensor grants You such rights in
65 | consideration of benefits the Licensor receives from making the
66 | Licensed Material available under these terms and conditions.
67 |
68 |
69 | Section 1 -- Definitions.
70 |
71 | a. Adapted Material means material subject to Copyright and Similar
72 | Rights that is derived from or based upon the Licensed Material
73 | and in which the Licensed Material is translated, altered,
74 | arranged, transformed, or otherwise modified in a manner requiring
75 | permission under the Copyright and Similar Rights held by the
76 | Licensor. For purposes of this Public License, where the Licensed
77 | Material is a musical work, performance, or sound recording,
78 | Adapted Material is always produced where the Licensed Material is
79 | synched in timed relation with a moving image.
80 |
81 | b. Adapter's License means the license You apply to Your Copyright
82 | and Similar Rights in Your contributions to Adapted Material in
83 | accordance with the terms and conditions of this Public License.
84 |
85 | c. Copyright and Similar Rights means copyright and/or similar rights
86 | closely related to copyright including, without limitation,
87 | performance, broadcast, sound recording, and Sui Generis Database
88 | Rights, without regard to how the rights are labeled or
89 | categorized. For purposes of this Public License, the rights
90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
91 | Rights.
92 |
93 | d. Effective Technological Measures means those measures that, in the
94 | absence of proper authority, may not be circumvented under laws
95 | fulfilling obligations under Article 11 of the WIPO Copyright
96 | Treaty adopted on December 20, 1996, and/or similar international
97 | agreements.
98 |
99 | e. Exceptions and Limitations means fair use, fair dealing, and/or
100 | any other exception or limitation to Copyright and Similar Rights
101 | that applies to Your use of the Licensed Material.
102 |
103 | f. Licensed Material means the artistic or literary work, database,
104 | or other material to which the Licensor applied this Public
105 | License.
106 |
107 | g. Licensed Rights means the rights granted to You subject to the
108 | terms and conditions of this Public License, which are limited to
109 | all Copyright and Similar Rights that apply to Your use of the
110 | Licensed Material and that the Licensor has authority to license.
111 |
112 | h. Licensor means the individual(s) or entity(ies) granting rights
113 | under this Public License.
114 |
115 | i. Share means to provide material to the public by any means or
116 | process that requires permission under the Licensed Rights, such
117 | as reproduction, public display, public performance, distribution,
118 | dissemination, communication, or importation, and to make material
119 | available to the public including in ways that members of the
120 | public may access the material from a place and at a time
121 | individually chosen by them.
122 |
123 | j. Sui Generis Database Rights means rights other than copyright
124 | resulting from Directive 96/9/EC of the European Parliament and of
125 | the Council of 11 March 1996 on the legal protection of databases,
126 | as amended and/or succeeded, as well as other essentially
127 | equivalent rights anywhere in the world.
128 |
129 | k. You means the individual or entity exercising the Licensed Rights
130 | under this Public License. Your has a corresponding meaning.
131 |
132 |
133 | Section 2 -- Scope.
134 |
135 | a. License grant.
136 |
137 | 1. Subject to the terms and conditions of this Public License,
138 | the Licensor hereby grants You a worldwide, royalty-free,
139 | non-sublicensable, non-exclusive, irrevocable license to
140 | exercise the Licensed Rights in the Licensed Material to:
141 |
142 | a. reproduce and Share the Licensed Material, in whole or
143 | in part; and
144 |
145 | b. produce, reproduce, and Share Adapted Material.
146 |
147 | 2. Exceptions and Limitations. For the avoidance of doubt, where
148 | Exceptions and Limitations apply to Your use, this Public
149 | License does not apply, and You do not need to comply with
150 | its terms and conditions.
151 |
152 | 3. Term. The term of this Public License is specified in Section
153 | 6(a).
154 |
155 | 4. Media and formats; technical modifications allowed. The
156 | Licensor authorizes You to exercise the Licensed Rights in
157 | all media and formats whether now known or hereafter created,
158 | and to make technical modifications necessary to do so. The
159 | Licensor waives and/or agrees not to assert any right or
160 | authority to forbid You from making technical modifications
161 | necessary to exercise the Licensed Rights, including
162 | technical modifications necessary to circumvent Effective
163 | Technological Measures. For purposes of this Public License,
164 | simply making modifications authorized by this Section 2(a)
165 | (4) never produces Adapted Material.
166 |
167 | 5. Downstream recipients.
168 |
169 | a. Offer from the Licensor -- Licensed Material. Every
170 | recipient of the Licensed Material automatically
171 | receives an offer from the Licensor to exercise the
172 | Licensed Rights under the terms and conditions of this
173 | Public License.
174 |
175 | b. No downstream restrictions. You may not offer or impose
176 | any additional or different terms or conditions on, or
177 | apply any Effective Technological Measures to, the
178 | Licensed Material if doing so restricts exercise of the
179 | Licensed Rights by any recipient of the Licensed
180 | Material.
181 |
182 | 6. No endorsement. Nothing in this Public License constitutes or
183 | may be construed as permission to assert or imply that You
184 | are, or that Your use of the Licensed Material is, connected
185 | with, or sponsored, endorsed, or granted official status by,
186 | the Licensor or others designated to receive attribution as
187 | provided in Section 3(a)(1)(A)(i).
188 |
189 | b. Other rights.
190 |
191 | 1. Moral rights, such as the right of integrity, are not
192 | licensed under this Public License, nor are publicity,
193 | privacy, and/or other similar personality rights; however, to
194 | the extent possible, the Licensor waives and/or agrees not to
195 | assert any such rights held by the Licensor to the limited
196 | extent necessary to allow You to exercise the Licensed
197 | Rights, but not otherwise.
198 |
199 | 2. Patent and trademark rights are not licensed under this
200 | Public License.
201 |
202 | 3. To the extent possible, the Licensor waives any right to
203 | collect royalties from You for the exercise of the Licensed
204 | Rights, whether directly or through a collecting society
205 | under any voluntary or waivable statutory or compulsory
206 | licensing scheme. In all other cases the Licensor expressly
207 | reserves any right to collect such royalties.
208 |
209 |
210 | Section 3 -- License Conditions.
211 |
212 | Your exercise of the Licensed Rights is expressly made subject to the
213 | following conditions.
214 |
215 | a. Attribution.
216 |
217 | 1. If You Share the Licensed Material (including in modified
218 | form), You must:
219 |
220 | a. retain the following if it is supplied by the Licensor
221 | with the Licensed Material:
222 |
223 | i. identification of the creator(s) of the Licensed
224 | Material and any others designated to receive
225 | attribution, in any reasonable manner requested by
226 | the Licensor (including by pseudonym if
227 | designated);
228 |
229 | ii. a copyright notice;
230 |
231 | iii. a notice that refers to this Public License;
232 |
233 | iv. a notice that refers to the disclaimer of
234 | warranties;
235 |
236 | v. a URI or hyperlink to the Licensed Material to the
237 | extent reasonably practicable;
238 |
239 | b. indicate if You modified the Licensed Material and
240 | retain an indication of any previous modifications; and
241 |
242 | c. indicate the Licensed Material is licensed under this
243 | Public License, and include the text of, or the URI or
244 | hyperlink to, this Public License.
245 |
246 | 2. You may satisfy the conditions in Section 3(a)(1) in any
247 | reasonable manner based on the medium, means, and context in
248 | which You Share the Licensed Material. For example, it may be
249 | reasonable to satisfy the conditions by providing a URI or
250 | hyperlink to a resource that includes the required
251 | information.
252 |
253 | 3. If requested by the Licensor, You must remove any of the
254 | information required by Section 3(a)(1)(A) to the extent
255 | reasonably practicable.
256 |
257 | 4. If You Share Adapted Material You produce, the Adapter's
258 | License You apply must not prevent recipients of the Adapted
259 | Material from complying with this Public License.
260 |
261 |
262 | Section 4 -- Sui Generis Database Rights.
263 |
264 | Where the Licensed Rights include Sui Generis Database Rights that
265 | apply to Your use of the Licensed Material:
266 |
267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
268 | to extract, reuse, reproduce, and Share all or a substantial
269 | portion of the contents of the database;
270 |
271 | b. if You include all or a substantial portion of the database
272 | contents in a database in which You have Sui Generis Database
273 | Rights, then the database in which You have Sui Generis Database
274 | Rights (but not its individual contents) is Adapted Material; and
275 |
276 | c. You must comply with the conditions in Section 3(a) if You Share
277 | all or a substantial portion of the contents of the database.
278 |
279 | For the avoidance of doubt, this Section 4 supplements and does not
280 | replace Your obligations under this Public License where the Licensed
281 | Rights include other Copyright and Similar Rights.
282 |
283 |
284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
285 |
286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
296 |
297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
306 |
307 | c. The disclaimer of warranties and limitation of liability provided
308 | above shall be interpreted in a manner that, to the extent
309 | possible, most closely approximates an absolute disclaimer and
310 | waiver of all liability.
311 |
312 |
313 | Section 6 -- Term and Termination.
314 |
315 | a. This Public License applies for the term of the Copyright and
316 | Similar Rights licensed here. However, if You fail to comply with
317 | this Public License, then Your rights under this Public License
318 | terminate automatically.
319 |
320 | b. Where Your right to use the Licensed Material has terminated under
321 | Section 6(a), it reinstates:
322 |
323 | 1. automatically as of the date the violation is cured, provided
324 | it is cured within 30 days of Your discovery of the
325 | violation; or
326 |
327 | 2. upon express reinstatement by the Licensor.
328 |
329 | For the avoidance of doubt, this Section 6(b) does not affect any
330 | right the Licensor may have to seek remedies for Your violations
331 | of this Public License.
332 |
333 | c. For the avoidance of doubt, the Licensor may also offer the
334 | Licensed Material under separate terms or conditions or stop
335 | distributing the Licensed Material at any time; however, doing so
336 | will not terminate this Public License.
337 |
338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
339 | License.
340 |
341 |
342 | Section 7 -- Other Terms and Conditions.
343 |
344 | a. The Licensor shall not be bound by any additional or different
345 | terms or conditions communicated by You unless expressly agreed.
346 |
347 | b. Any arrangements, understandings, or agreements regarding the
348 | Licensed Material not stated herein are separate from and
349 | independent of the terms and conditions of this Public License.
350 |
351 |
352 | Section 8 -- Interpretation.
353 |
354 | a. For the avoidance of doubt, this Public License does not, and
355 | shall not be interpreted to, reduce, limit, restrict, or impose
356 | conditions on any use of the Licensed Material that could lawfully
357 | be made without permission under this Public License.
358 |
359 | b. To the extent possible, if any provision of this Public License is
360 | deemed unenforceable, it shall be automatically reformed to the
361 | minimum extent necessary to make it enforceable. If the provision
362 | cannot be reformed, it shall be severed from this Public License
363 | without affecting the enforceability of the remaining terms and
364 | conditions.
365 |
366 | c. No term or condition of this Public License will be waived and no
367 | failure to comply consented to unless expressly agreed to by the
368 | Licensor.
369 |
370 | d. Nothing in this Public License constitutes or may be interpreted
371 | as a limitation upon, or waiver of, any privileges and immunities
372 | that apply to the Licensor or You, including from the legal
373 | processes of any jurisdiction or authority.
374 |
375 |
376 | =======================================================================
377 |
378 | Creative Commons is not a party to its public
379 | licenses. Notwithstanding, Creative Commons may elect to apply one of
380 | its public licenses to material it publishes and in those instances
381 | will be considered the “Licensor.” The text of the Creative Commons
382 | public licenses is dedicated to the public domain under the CC0 Public
383 | Domain Dedication. Except for the limited purpose of indicating that
384 | material is shared under a Creative Commons public license or as
385 | otherwise permitted by the Creative Commons policies published at
386 | creativecommons.org/policies, Creative Commons does not authorize the
387 | use of the trademark "Creative Commons" or any other trademark or logo
388 | of Creative Commons without its prior written consent including,
389 | without limitation, in connection with any unauthorized modifications
390 | to any of its public licenses or any other arrangements,
391 | understandings, or agreements concerning use of licensed material. For
392 | the avoidance of doubt, this paragraph does not form part of the
393 | public licenses.
394 |
395 | Creative Commons may be contacted at creativecommons.org.
396 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | export(eSAIR)
4 | export(qh.eSIR)
5 | export(tvt.eSIR)
6 | export(tvt.eSIR2)
7 | import(chron)
8 | import(coda)
9 | import(data.table)
10 | import(ggplot2)
11 | import(grDevices)
12 | import(graphics)
13 | import(gtools)
14 | import(rjags)
15 | import(scales)
16 | import(stats)
17 | import(utils)
18 | importFrom(coda,as.mcmc.list)
19 |
--------------------------------------------------------------------------------
/R/eSAIR.R:
--------------------------------------------------------------------------------
1 | # This is the source code for R package eSIR: extended-SIR
2 | # Added on May 10, 2020, and last edited on Oct 27, 2021
3 | # Correspondence : Peter X.K. Song, Ph.D. (pxsong@umich.edu)
4 | # Creator: Lili Wang, Ph.D. (lilywang@umich.edu)
5 | # An extend SIR with time-varying immunization among a subset of the population, which follows a Dirac Delta function
6 | #' Extended state-space SIR with a subset of the population showing antibody positivity
7 | #'
8 | #'
9 | #' In this function we allow it to characterize time-varying immunization among a subset of the population that have been tested positive in an antibody assessment. We expanded the SIR model by adding a time-varying antibody-positive proportion \eqn{\alpha_t}.
10 | #'
11 | #' @param Y the time series of daily observed infected compartment proportions.
12 | #' @param R the time series of daily observed removed compartment proportions, including death and recovered.
13 | #' @param alpha0 a vector of values of the dirac delta function \eqn{\alpha_t}. Each entry denotes the proportion that will be immunized at each change time point. Note that all the entries lie between 0 and 1, its default is \code{NULL}.
14 | #' @param change_time the change points over time corresponding to \code{alpha0}, to formulate the dirac delta function \eqn{\alpha_t}; its defalt value is \code{NULL}.
15 | #' @param begin_str the character of starting time, the default is "01/13/2020".
16 | #' @param T_fin the end of follow-up time after the beginning date \code{begin_str}, the default is 200.
17 | #' @param nchain the number of MCMC chains generated by \code{\link[rjags]{rjags}}, the default is 4.
18 | #' @param nadapt the iteration number of adaptation in the MCMC. We recommend using at least the default value 1e4 to obtained fully adapted chains.
19 | #' @param M the number of draws in each chain, with no thinning. The default is M=5e2 but suggest using 5e5.
20 | #' @param thn the thinning interval between mixing. The total number of draws thus would become \code{round(M/thn)*nchain}. The default is 10.
21 | #' @param nburnin the burn-in period. The default is 2e2 but suggest 2e5.
22 | #' @param dic logical, whether compute the DIC (deviance information criterion) for model selection.
23 | #' @param death_in_R the numeric value of average of cumulative deaths in the removed compartments. The default is 0.4 within Hubei and 0.02 outside Hubei.
24 | #' @param casename the string of the job's name. The default is "eSAIR".
25 | #' @param beta0 the hyperparameter of average transmission rate, the default is the one estimated from the SARS first-month outbreak (0.2586).
26 | #' @param gamma0 the hyperparameter of average removed rate, the default is the one estimated from the SARS first-month outbreak (0.0821).
27 | #' @param R0 the hyperparameter of the mean reproduction number R0. The default is thus the ratio of \code{beta0/gamma0}, which can be specified directly.
28 | #' @param gamma0_sd the standard deviation for the prior distrbution of the removed rate \eqn{\gamma}, the default is 0.1.
29 | #' @param R0_sd the standard deviation for the prior disbution of R0, the default is 1.
30 | #' @param file_add the string to denote the location of saving output files and tables.
31 | #'
32 | #' @param save_mcmc logical, whether save (\code{TRUE}) all the MCMC outputs or not (\code{FALSE}).The output file will be an \code{.RData} file named by the \eqn{casename}. We include arrays of prevalence values of the three compartments with their matrices of posterior draws up to the last date of the collected data as \code{theta_p[,,1]} and afterwards as \code{theta_pp[,,1]} for \eqn{\theta_t^S}, \code{theta_p[,,2]} and \code{theta_pp[,,2]} for \eqn{\theta_t^I}, and \code{theta_p[,,3]} and \code{theta_pp[,,3]} for \eqn{\theta_t^R}. The posterior draws of the prevalence process of the antibody-immunized compartment can be obtained via \code{thetaA_p} and \code{thetaA_pp}. Moreover, the input and predicted proportions \code{Y}, \code{Y_pp}, \code{R} and \code{R_pp} can also be retrieved. The prevalence and prediceted proportion matrices have rows for MCMC replicates, and columns for days. The MCMC posterior draws of other parameters including \code{beta}, \code{gamma}, \code{R0}, and variance controllers \code{k_p}, \code{lambdaY_p}, \code{lambdaR_p} are also available.
33 | #' @param save_plot_data logical, whether save the plotting data or not.
34 | #' @param save_files logical, whether to save plots to file.
35 | #' @param add_death logical, whether add the approximate death curve to the plot, default is false.
36 | #' @param eps a non-zero controller so that all the input \code{Y} and \code{R} values would be bounded above 0 (at least \code{eps}). Its default value is 1e-10
37 | #'
38 | #' @return
39 | #' \item{casename}{the predefined \code{casename}.}
40 | #' \item{incidence_mean}{mean cumulative incidence, the mean prevalence of cumulative confirmed cases at the end of the study.}
41 | #' \item{incidence_ci}{2.5\%, 50\%, and 97.5\% quantiles of the incidences.}
42 | #' \item{out_table}{summary tables including the posterior mean of the prevalance processes of the 3 states compartments (\eqn{\theta_t^S,\theta_t^I,\theta_t^R,\theta_t^H}) at last date of data collected ((\eqn{t^\prime}) decided by the lengths of your input data \code{Y} and \code{R}), and their respective credible inctervals (ci); the respective means and ci's of the reporduction number (R0), removed rate (\eqn{\gamma}), transmission rate (\eqn{\beta}).}
43 | #' \item{plot_infection}{plot of summarizing and forecasting for the infection compartment, in which the vertial blue line denotes the last date of data collected (\eqn{t^\prime}), the vertial darkgray line denotes the deacceleration point (first turning point) that the posterior mean first-derivative of infection prevalence \eqn{\dot{\theta}_t^I} achieves the maximum, the vertical purple line denotes the second turning point that the posterior mean first-derivative infection proportion \eqn{\dot{\theta}_t^I} equals zero, the darkgray line denotes the posterior mean of the infection prevalence \eqn{\theta_t^I} and the red line denotes its posterior median. }
44 | #' \item{plot_removed}{plot of summarizing and forecasting for the removed compartment with lines similar to those in the \code{plot_infection}. The vertical lines are identical, but the horizontal mean and median correspond to the posterior mean and median of the removed process \eqn{\theta_t^R}. An additional line indicates the estimated death prevalence from the input \code{death_in_R}.}
45 | #' \item{spaghetti_plot}{20 randomly selected MCMC draws of the first-order derivative of the posterior prevalence of infection, namely \eqn{\dot{\theta}_t^I}. The black curve is the posterior mean of the derivative, and the vertical lines mark times of turning points corresponding respectively to those shown in \code{plot_infection} and \code{plot_removed}. Moreover, the 95\% credible intervals of these turning points are also highlighted by semi-transparent rectangles. }
46 | #' \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
47 | #' \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
48 | #'
49 | #' \item{first_tp_ci}{fwith \code{first_tp_mean}, it reports the corresponding credible interval and median.}
50 | #' \item{second_tp_mean}{the date t at which \eqn{\theta_t^I=0}, calculated as the average of the stationary points of all of posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "pruple" lines in the plots of \code{plot_infection} and \code{plot_removed}. The latter indicate stationary t at which the first-order derivative of the averaged posterior of \eqn{\theta_t^I} equals zero.}
51 | #' \item{second_tp_ci}{with \code{second_tp_mean}, it reports the corresponding credible interval and median.}
52 | #' \item{dic_val}{the output of \code{dic.samples()} in \code{\link[rjags]{dic.samples}}, computing deviance information criterion for model comparison.}
53 | #' \item{gelman_diag_list}{ Since version 0.3.3, we incorporated Gelman And Rubin's Convergence Diagnostic using \code{\link[coda]{gelman.diag}}. We included both the statistics and their upper C.I. limits. Values substantially above 1 indicate lack of convergence. Error messages would be printed as they are. This would be only valid for multiple chains (e.g. nchain > 1). Note that for time dependent processes, we only compute the convergence of the last observation data (\code{T_prime}), though it shows to be \code{T_prime+1}, which is due to the day 0 for initialization.}
54 | #'
55 | #' @examples
56 | #' \dontrun{
57 | #' NI_complete <- c(
58 | #' 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
59 | #' 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
60 | #' 13522, 16678, 19665, 22112, 24953, 27100, 29631, 31728, 33366
61 | #' )
62 | #' RI_complete <- c(
63 | #' 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94,
64 | #' 121, 152, 213, 252, 345, 417, 561, 650, 811, 1017,
65 | #' 1261, 1485, 1917, 2260, 2725, 3284, 3754
66 | #' )
67 | #' N <- 58.5e6
68 | #' R <- RI_complete / N
69 | #' Y <- NI_complete / N - R # Jan13->Feb 11
70 | #' change_time <- c("02/08/2020")
71 | #' alpha0 <- c(0.2) # 20% of the susceptible population were found immunized
72 | #' res.antibody <- eSAIR(Y, R,
73 | #' begin_str = "01/13/2020", death_in_R = 0.4,
74 | #' alpha0 = alpha0, change_time = change_time,
75 | #' casename = "Hubei_antibody", save_files = T, save_mcmc = F,
76 | #' M = 5e2, nburnin = 2e2
77 | #' )
78 | #' res.antibody$plot_infection
79 | #' }
80 | #'
81 | #' change_time <- c("01/16/2020")
82 | #' alpha0 <- c(0.2)
83 | #' NI_complete2 <- c(41, 45)
84 | #' RI_complete2 <- c(1, 1)
85 | #' N2 <- 1E3
86 | #' res3 <- eSAIR(
87 | #' RI_complete2 / N2,
88 | #' NI_complete2 / N2,
89 | #' begin_str = "01/13/2020",
90 | #' T_fin = 4,
91 | #' alpha0 = alpha0,
92 | #' change_time = change_time,
93 | #' dic = FALSE,
94 | #' casename = "Hubei_q",
95 | #' save_files = FALSE,
96 | #' save_mcmc = FALSE,
97 | #' save_plot_data = FALSE,
98 | #' M = 50,
99 | #' nburnin = 1
100 | #' )
101 | #' closeAllConnections()
102 | #'
103 | #' @export
104 | eSAIR <- function(Y, R, alpha0 = NULL, change_time = NULL, begin_str = "01/13/2020", T_fin = 200, nchain = 4, nadapt = 1e4, M = 5e2, thn = 10, nburnin = 2e2, dic = FALSE, death_in_R = 0.02, casename = "eSAIR", beta0 = 0.2586, gamma0 = 0.0821, R0 = beta0 / gamma0, gamma0_sd = 0.1, R0_sd = 1, file_add = character(0), add_death = FALSE, save_files = FALSE, save_mcmc = FALSE, save_plot_data = FALSE, eps = 1e-10) {
105 | beta0 <- R0 * gamma0
106 | len <- round(M / thn) * nchain # number of MCMC draws in total
107 |
108 | T_prime <- length(Y)
109 | if (T_prime != length(R)) stop("Y and R should be matched.")
110 | if(T_prime >= T_fin) {
111 | warning("T_fin must be larger than input time series Y and R,",
112 | "we will automatically add 100 time units to it: T_fin = length(Y) + 10.")
113 | T_fin = T_prime + 10
114 | }
115 | Y <- pmax(Y, eps)
116 | R <- pmax(R, eps)
117 | if (add_death == T && death_in_R == 0.02) {
118 | message("use the default death_in_R which is equal to 0.02 to plot the death curve in the removed process forecast plot")
119 | }
120 | begin <- chron(dates. = begin_str)
121 | chron_ls <- chron(begin:(begin + T_fin))
122 | end <- chron(begin:(begin + T_fin))[T_fin]
123 | message(paste0("The follow-up is from ", begin, " to ", end, " and the last observed date is ", chron_ls[T_prime], ".")) # current data up to this date
124 | gamma_var <- gamma0_sd^2
125 | lognorm_gamma_parm <- lognorm.parm(gamma0, gamma_var)
126 | R0_var <- R0_sd^2
127 | lognorm_R0_parm <- lognorm.parm(R0, R0_var)
128 |
129 | message("Running for eSAIR")
130 |
131 | if (length(change_time) != length(alpha0)) {
132 | stop("We need the length of vector change_time to be the length of alpha0. ")
133 | }
134 | change_time_chorn <- chron(dates. = change_time)
135 | alpha_vec <- rep(0, T_fin)
136 | alpha_vec[as.numeric(change_time_chorn - begin)] <- alpha0
137 |
138 |
139 | ################ MCMC ##########
140 | gamma_H_vec <- rep(0, T_fin) # remove the Hospitalization for now
141 | ## gamma_H_vec[as.numeric(change_hospitalization-begin)] <- gamma_H
142 |
143 | ################ MCMC ##########
144 | model2.string <- paste0("
145 | model{
146 | for(t in 2:(T_prime+1)){
147 | Km[t-1,1] <- -beta*theta[t-1,1]*theta[t-1,2]
148 | Km[t-1,9] <- gamma*theta[t-1,2]
149 | Km[t-1,5] <- -Km[t-1,1]-Km[t-1,9]
150 | Km[t-1,2] <- -beta*(theta[t-1,1]+0.5*Km[t-1,1])*(theta[t-1,2]+0.5*Km[t-1,5])
151 | Km[t-1,10] <- gamma*(theta[t-1,2]+0.5*Km[t-1,5])
152 | Km[t-1,6] <- -Km[t-1,2]-Km[t-1,10]
153 | Km[t-1,3] <- -beta*(theta[t-1,1]+0.5*Km[t-1,2])*(theta[t-1,2]+0.5*Km[t-1,6])
154 | Km[t-1,11] <- gamma*(theta[t-1,2]+0.5*Km[t-1,6])
155 | Km[t-1,7] <- -Km[t-1,3]-Km[t-1,11]
156 | Km[t-1,4] <- -beta*(theta[t-1,1]+Km[t-1,3])*(theta[t-1,2]+Km[t-1,7])
157 | Km[t-1,12] <- gamma*(theta[t-1,2]+Km[t-1,7])
158 | Km[t-1,8] <- -Km[t-1,4]-Km[t-1,12]
159 | alpha_temp[t-1,1] <- max(theta[t-1,1]+(Km[t-1,1]+2*Km[t-1,2]+2*Km[t-1,3]+Km[t-1,4])/6-alpha_vec[t-1]*theta[t-1,1],0)
160 | alpha_temp[t-1,2] <- max(theta[t-1,2]+(Km[t-1,5]+2*Km[t-1,6]+2*Km[t-1,7]+Km[t-1,8])/6-gamma_H_vec[t-1]*theta[t-1,2],0)
161 | alpha_temp[t-1,3] <- theta[t-1,3]+(Km[t-1,9]+2*Km[t-1,10]+2*Km[t-1,11]+Km[t-1,12])/6
162 | theta_A[t] <- theta_A[t-1]+min(alpha_vec[t-1]*theta[t-1,1],theta[t-1,1]+(Km[t-1,1]+2*Km[t-1,2]+2*Km[t-1,3]+Km[t-1,4])/6)
163 | theta_H[t] <- theta_H[t-1]+min(gamma_H_vec[t-1]*theta[t-1,2],theta[t-1,2]+(Km[t-1,5]+2*Km[t-1,6]+2*Km[t-1,7]+Km[t-1,8])/6)
164 | v[t-1] <- (1-theta_A[t]-theta_H[t])
165 | alpha[t-1,1] <- (1-step(-v[t-1]))*alpha_temp[t-1,1]/v[t-1]
166 | alpha[t-1,2] <- (1-step(-v[t-1]))*alpha_temp[t-1,2]/v[t-1]
167 | alpha[t-1,3] <- (1-step(-v[t-1]))*alpha_temp[t-1,3]/v[t-1]
168 | theta_temp[t,1:3] ~ ddirch(k*alpha[t-1,1:3])
169 | theta[t,1:3] <- v[t-1]*theta_temp[t,1:3]
170 | Y[t-1] ~ dbeta(lambdaY*theta[t,2],lambdaY*(1-theta[t,2]))
171 | R[t-1] ~ dbeta(lambdaR*theta[t,3],lambdaR*(1-theta[t,3]))
172 | }
173 | theta_A[1] <- 0
174 | theta_H[1] <- 0
175 | theta0[1:3]<-c(", 1 - Y[1] - R[1], ",", Y[1], ",", R[1], ")
176 | theta[1,1:3] ~ ddirch(theta0[1:3])
177 | gamma ~ dlnorm(", lognorm_gamma_parm$mu, ",", 1 / lognorm_gamma_parm$var, ")
178 | R0 ~ dlnorm(", lognorm_R0_parm$mu, ",", 1 / lognorm_R0_parm$var, ")
179 | beta <- R0*gamma
180 | k ~ dgamma(2,0.0001)
181 | lambdaY ~ dgamma(2,0.0001)
182 | lambdaR ~ dgamma(2,0.0001)
183 | }
184 | ")
185 | model.spec <- textConnection(model2.string)
186 |
187 | posterior <- suppressWarnings(
188 | jags.model(
189 | model.spec,
190 | data = list(
191 | "Y" = Y,
192 | "R" = R,
193 | "T_prime" = T_prime,
194 | "alpha_vec" = alpha_vec,
195 | "gamma_H_vec" = gamma_H_vec
196 | ),
197 | n.chains = nchain,
198 | n.adapt = nadapt
199 | )
200 | )
201 |
202 | suppressWarnings(update(posterior, nburnin)) # burn-in
203 |
204 | jags_sample <- suppressWarnings(
205 | jags.samples(
206 | posterior,
207 | c("theta",
208 | "theta_H",
209 | "theta_A",
210 | "gamma",
211 | "R0",
212 | "beta",
213 | "Y",
214 | "lambdaY",
215 | "lambdaR",
216 | "k",
217 | "v"
218 | ),
219 | n.iter = M,
220 | thin = thn
221 | )
222 | )
223 |
224 | if (dic) {
225 | dic_val <- dic.samples(posterior, n.iter = M, thin = thn)
226 | # message(paste0("DIC is: ", dic_val))
227 | } else {
228 | dic_val <- NULL
229 | }
230 |
231 |
232 | if (save_files) {
233 | png(paste0(file_add, casename, "theta_p.png"), width = 700, height = 900)
234 | plot(as.mcmc.list(jags_sample$theta)[, (1:3) * (T_prime + 1)]) # posterior true porbabilities
235 | dev.off()
236 |
237 | png(paste0(file_add, casename, "thetaA_p.png"), width = 700, height = 900)
238 | plot(as.mcmc.list(jags_sample$theta_A)[, T_prime], main = "thetaA[T_prime]") # posterior true porbabilities
239 | dev.off()
240 |
241 |
242 | png(paste0(file_add, casename, "R0_p.png"), width = 700, height = 350)
243 | R0_p <- unlist(as.mcmc.list(jags_sample$R0))
244 | plot(as.mcmc.list(jags_sample$R0))
245 | dev.off()
246 | png(paste0(file_add, casename, "gamma_p.png"), width = 700, height = 350)
247 | gamma_p <- unlist(as.mcmc.list(jags_sample$gamma))
248 | plot(as.mcmc.list(jags_sample$gamma))
249 | dev.off()
250 |
251 | png(paste0(file_add, casename, "beta_p.png"), width = 700, height = 350)
252 | beta_p <- unlist(as.mcmc.list(jags_sample$beta))
253 | plot(as.mcmc.list(jags_sample$beta))
254 | dev.off()
255 |
256 |
257 | png(paste0(file_add, casename, "lambdaY_p.png"), width = 700, height = 350)
258 | lambdaY_p <- unlist(as.mcmc.list(jags_sample$lambdaY))
259 | plot(as.mcmc.list(jags_sample$lambdaY))
260 | dev.off()
261 |
262 | png(paste0(file_add, casename, "lambdaR_p.png"), width = 700, height = 350)
263 | lambdaR_p <- unlist(as.mcmc.list(jags_sample$lambdaR))
264 | plot(as.mcmc.list(jags_sample$lambdaR))
265 | dev.off()
266 |
267 | png(paste0(file_add, casename, "k_p.png"), width = 700, height = 350)
268 | k_p <- unlist(as.mcmc.list(jags_sample$k))
269 | plot(as.mcmc.list(jags_sample$k))
270 | dev.off()
271 | } else {
272 | R0_p <- unlist(as.mcmc.list(jags_sample$R0))
273 | gamma_p <- unlist(as.mcmc.list(jags_sample$gamma))
274 | beta_p <- unlist(as.mcmc.list(jags_sample$beta))
275 | lambdaY_p <- unlist(as.mcmc.list(jags_sample$lambdaY))
276 | lambdaR_p <- unlist(as.mcmc.list(jags_sample$lambdaR))
277 | k_p <- unlist(as.mcmc.list(jags_sample$k))
278 | }
279 |
280 |
281 | theta_p <- array(Reduce(rbind, as.mcmc.list(jags_sample$theta)), dim = c(len, T_prime + 1, 3))
282 | theta_p_mean <- apply(theta_p[, T_prime + 1, ], 2, mean)
283 | theta_p_ci <- as.vector(apply(theta_p[, T_prime + 1, ], 2, quantile, c(0.025, 0.5, 0.975)))
284 |
285 | thetaA_p <- matrix(Reduce(rbind, as.mcmc.list(jags_sample$theta_A)), nrow = len, ncol = T_prime + 1)
286 | thetaH_p <- matrix(Reduce(rbind, as.mcmc.list(jags_sample$theta_H)), nrow = len, ncol = T_prime + 1)
287 |
288 | thetaA_p_mean <- mean(thetaA_p[, T_prime + 1])
289 | thetaA_p_ci <- quantile(thetaA_p[, T_prime + 1], c(0.025, 0.5, 0.975))
290 |
291 | R0_p_mean <- mean(R0_p)
292 | R0_p_ci <- quantile(R0_p, c(0.025, 0.5, 0.975))
293 |
294 | gamma_p_mean <- mean(gamma_p)
295 | gamma_p_ci <- quantile(gamma_p, c(0.025, 0.5, 0.975))
296 |
297 | beta_p_mean <- mean(beta_p)
298 | beta_p_ci <- quantile(beta_p, c(0.025, 0.5, 0.975))
299 |
300 | lambdaY_p_mean <- mean(lambdaY_p)
301 | lambdaY_p_ci <- quantile(lambdaY_p, c(0.025, 0.5, 0.975))
302 |
303 | lambdaR_p_mean <- mean(lambdaR_p)
304 | lambdaR_p_ci <- quantile(lambdaR_p, c(0.025, 0.5, 0.975))
305 |
306 | k_p_mean <- mean(k_p)
307 | k_p_ci <- quantile(k_p, c(0.025, 0.5, 0.975))
308 |
309 | #### Forecast ####
310 | theta_pp <- array(0, dim = c(len, T_fin - T_prime, 3))
311 | thetaA_pp <- thetaH_pp <- matrix(0, nrow = len, ncol = T_fin - T_prime)
312 |
313 | Y_pp <- matrix(NA, nrow = len, ncol = T_fin - T_prime)
314 | R_pp <- matrix(NA, nrow = len, ncol = T_fin - T_prime)
315 | v_pp <- matrix(NA, nrow = len, ncol = T_fin - T_prime)
316 |
317 | for (l in 1:len) {
318 | thetalt1 <- theta_p[l, T_prime + 1, 1]
319 | thetalt2 <- theta_p[l, T_prime + 1, 2]
320 | thetalt3 <- theta_p[l, T_prime + 1, 3]
321 | thetaltH <- thetaH_p[l, T_prime + 1]
322 | thetaltA <- thetaA_p[l, T_prime + 1]
323 |
324 | betal <- c(beta_p)[l]
325 | gammal <- c(gamma_p)[l]
326 | kl <- c(k_p)[l]
327 | lambdaYl <- c(lambdaY_p)[l]
328 | lambdaRl <- c(lambdaR_p)[l]
329 | if (betal < 0 | gammal < 0 | thetalt1 < 0 | thetalt2 < 0 | thetalt3 < 0 | thetaltH < 0 | thetaltA < 0) next
330 | for (t in 1:(T_fin - T_prime)) {
331 | Km <- NULL
332 | theta_temp <- alpha_temp <- alpha <- NULL
333 | Km[1] <- -betal * thetalt1 * thetalt2
334 | Km[9] <- gammal * thetalt2
335 | Km[5] <- -Km[1] - Km[9]
336 |
337 | Km[2] <- -betal * (thetalt1 + 0.5 * Km[1]) * (thetalt2 + 0.5 * Km[5])
338 | Km[10] <- gammal * (thetalt2 + 0.5 * Km[5])
339 | Km[6] <- -Km[2] - Km[10]
340 |
341 | Km[3] <- -betal * (thetalt1 + 0.5 * Km[2]) * (thetalt2 + 0.5 * Km[6])
342 | Km[11] <- gammal * (thetalt2 + 0.5 * Km[6])
343 | Km[7] <- -Km[3] - Km[11]
344 |
345 | Km[4] <- -betal * (thetalt1 + Km[3]) * (thetalt2 + Km[7])
346 | Km[12] <- gammal * (thetalt2 + Km[7])
347 | Km[8] <- -Km[4] - Km[12]
348 | # if(is.na(thetat1)|is.na(thetat2)) stop("NA1")
349 | alpha_temp[1] <- max(thetalt1 + (Km[1] + 2 * Km[2] + 2 * Km[3] + Km[4]) / 6 - alpha_vec[t + T_prime] * thetalt1, 0)
350 | alpha_temp[2] <- max(thetalt2 + (Km[5] + 2 * Km[6] + 2 * Km[7] + Km[8]) / 6 - gamma_H_vec[t + T_prime] * thetalt2, 0)
351 | alpha_temp[3] <- max(thetalt3 + (Km[9] + 2 * Km[10] + 2 * Km[11] + Km[12]) / 6, 0)
352 |
353 | thetaA_pp[l, t] <- thetaltA <- thetaltA + min(alpha_vec[t + T_prime] * thetalt1, thetalt1 + (Km[1] + 2 * Km[2] + 2 * Km[3] + Km[4]) / 6)
354 | thetaH_pp[l, t] <- thetaltH <- thetaltH + min(gamma_H_vec[t + T_prime] * thetalt2, thetalt2 + (Km[5] + 2 * Km[6] + 2 * Km[7] + Km[8]) / 6)
355 |
356 |
357 |
358 | v_pp[l, t] <- 1 - thetaA_pp[l, t] - thetaH_pp[l, t]
359 |
360 | alpha[1] <- ifelse(v_pp[l, t] > 0, alpha_temp[1] / v_pp[l, t], 0)
361 | alpha[2] <- ifelse(v_pp[l, t] > 0, alpha_temp[2] / v_pp[l, t], 0)
362 | alpha[3] <- ifelse(v_pp[l, t] > 0, alpha_temp[3] / v_pp[l, t], 0)
363 |
364 | theta_temp <- rdirichlet(1, kl * alpha)
365 |
366 | thetalt1 <- theta_pp[l, t, 1] <- theta_temp[1] * v_pp[l, t]
367 | thetalt2 <- theta_pp[l, t, 2] <- theta_temp[2] * v_pp[l, t]
368 | thetalt3 <- theta_pp[l, t, 3] <- theta_temp[3] * v_pp[l, t]
369 | # if(is.na(thetat1)|is.na(thetat2)) stop("NA2")
370 | Y_pp[l, t] <- rbeta(1, lambdaYl * thetalt2, lambdaYl * (1 - thetalt2))
371 | if (is.na(Y_pp[l, t])) stop("NA")
372 | R_pp[l, t] <- rbeta(1, lambdaRl * thetalt3, lambdaRl * (1 - thetalt3))
373 | }
374 | }
375 | par(mfrow = c(1, 1))
376 | col2 <- gg_color_hue(2)
377 | Y_band <- data.frame(t(apply(Y_pp, 2, quantile, probs = c(0.025, 0.975), na.rm = T)))
378 | thetaI_band <- data.frame(t(apply(theta_p[, -1, 2], 2, quantile, probs = c(0.025, 0.975), na.rm = T)))
379 | Y_mean <- c(colMeans(Y_pp, na.rm = T))
380 | thetaI_mean <- c(colMeans(theta_p[, -1, 2], na.rm = T), colMeans(theta_pp[, , 2], na.rm = T))
381 | thetaI_median <- c(apply(theta_p[, -1, 2], 2, median, na.rm = T), apply(theta_pp[, , 2], 2, median, na.rm = T))
382 | colnames(Y_band) <- c("lower", "upper")
383 | colnames(thetaI_band) <- c("lower", "upper")
384 | data_pre <- data.frame(time = 1:T_prime, Y)
385 | data_post <- data.frame(time = 1:T_prime, thetaI_band)
386 | data_fore <- data.frame(time = (T_prime + 1):T_fin, Y_band, Y_mean)
387 |
388 | data_comp <- data.frame(time = 1:T_fin, rbind(thetaI_band, Y_band), phase = c(rep("pre", nrow(thetaI_band)), rep("post", nrow(Y_band))), mean = thetaI_mean, median = thetaI_median)
389 |
390 | data_poly <- data.frame(y = c(thetaI_band$upper, rev(thetaI_band$lower), Y_band$upper, rev(Y_band$lower)), x = c(1:T_prime, T_prime:1, (T_prime + 1):T_fin, T_fin:(T_prime + 1)), phase = c(rep("pre", T_prime * 2), rep("post", (T_fin - T_prime) * 2)), value = c(rep(col2[1], T_prime * 2), rep(col2[2], (T_fin - T_prime) * 2)))
391 |
392 | ## First-order derivative check
393 | thetaS_mat <- cbind(theta_p[, -1, 1], theta_pp[, , 1])
394 | thetaI_mat <- cbind(theta_p[, -1, 2], theta_pp[, , 2])
395 | thetaR_mat <- cbind(theta_p[, -1, 3], theta_pp[, , 3])
396 |
397 | dthetaI_mat_post <- (theta_pp[, , 1] * theta_pp[, , 2]) * replicate(T_fin - T_prime, c(beta_p)) - theta_pp[, , 2] * replicate(T_fin - T_prime, c(gamma_p)) - theta_pp[, , 1] * t(replicate(len, c(alpha_vec[(T_prime + 1):T_fin]))) - theta_pp[, , 2] * t(replicate(len, c(gamma_H_vec[(T_prime + 1):T_fin])))
398 | dthetaI_mat_pre <- t(apply(theta_p[, , 2], 1, function(v) {
399 | diff(smooth(v))
400 | }))
401 | dthetaI_mat <- cbind(dthetaI_mat_pre, dthetaI_mat_post)
402 |
403 | dthetaI <- colMeans(dthetaI_mat, na.rm = T)
404 | dthetaI_tp1 <- (1:T_fin)[which.max(dthetaI)] # first second order derivative=0
405 | dthetaI_tp2 <- (dthetaI_tp1:T_fin)[which.min(dthetaI[dthetaI_tp1:T_fin] > 0)] # first order derivative=0
406 |
407 | dthetaI_tp1_rd <- max(round(dthetaI_tp1), 1)
408 | if (dthetaI_tp1_rd > T_prime) {
409 | thetatI_tp1_vec <- thetaI_mat[, dthetaI_tp1_rd]
410 | thetaI_tp1_mean <- mean(thetatI_tp1_vec, na.rm = T)
411 | thetaI_tp1_ci <- quantile(thetatI_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
412 | Y_tp1_vec <- Y_pp[, dthetaI_tp1_rd - T_prime]
413 | Y_tp1_mean <- mean(Y_tp1_vec, na.rm = T)
414 | Y_tp1_ci <- quantile(Y_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
415 |
416 | thetatR_tp1_vec <- thetaR_mat[, dthetaI_tp1_rd]
417 | thetaR_tp1_mean <- mean(thetatR_tp1_vec, na.rm = T)
418 | thetaR_tp1_ci <- quantile(thetatR_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
419 | R_tp1_vec <- R_pp[, dthetaI_tp1_rd - T_prime]
420 | R_tp1_mean <- mean(R_tp1_vec, na.rm = T)
421 | R_tp1_ci <- quantile(R_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
422 | } else {
423 | thetatI_tp1_vec <- thetaI_mat[, dthetaI_tp1_rd]
424 | thetaI_tp1_mean <- mean(thetatI_tp1_vec, na.rm = T)
425 | thetaI_tp1_ci <- quantile(thetatI_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
426 | Y_tp1_vec <- NA
427 | Y_tp1_mean <- mean(Y_tp1_vec, na.rm = T)
428 | Y_tp1_ci <- quantile(Y_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
429 |
430 | thetatR_tp1_vec <- thetaR_mat[, dthetaI_tp1_rd]
431 | thetaR_tp1_mean <- mean(thetatR_tp1_vec, na.rm = T)
432 | thetaR_tp1_ci <- quantile(thetatR_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
433 | R_tp1_vec <- R_pp[, dthetaI_tp1_rd - T_prime]
434 | R_tp1_mean <- mean(R_tp1_vec, na.rm = T)
435 | R_tp1_ci <- quantile(R_tp1_vec, c(0.025, 0.5, 0.975), na.rm = T)
436 | }
437 | dthetaI_tp2_rd <- max(round(dthetaI_tp2), 1)
438 | if (dthetaI_tp1_rd == dthetaI_tp2_rd) {
439 | thetatI_tp2_vec <- NA
440 | thetaI_tp2_mean <- mean(thetatI_tp2_vec, na.rm = T)
441 | thetaI_tp2_ci <- quantile(thetatI_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
442 | Y_tp2_vec <- NA
443 | Y_tp2_mean <- mean(Y_tp2_vec, na.rm = T)
444 | Y_tp2_ci <- quantile(Y_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
445 |
446 | thetatR_tp2_vec <- NA
447 | thetaR_tp2_mean <- mean(thetatR_tp2_vec, na.rm = T)
448 | thetaR_tp2_ci <- quantile(thetatR_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
449 | R_tp2_vec <- NA
450 | R_tp2_mean <- mean(R_tp2_vec, na.rm = T)
451 | R_tp2_ci <- quantile(R_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
452 | } else if (dthetaI_tp2_rd > T_prime) {
453 | thetatI_tp2_vec <- thetaI_mat[, dthetaI_tp2_rd]
454 | thetaI_tp2_mean <- mean(thetatI_tp2_vec, na.rm = T)
455 | thetaI_tp2_ci <- quantile(thetatI_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
456 | Y_tp2_vec <- Y_pp[, dthetaI_tp2_rd - T_prime]
457 | Y_tp2_mean <- mean(Y_tp2_vec, na.rm = T)
458 | Y_tp2_ci <- quantile(Y_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
459 |
460 | thetatR_tp2_vec <- thetaR_mat[, dthetaI_tp2_rd]
461 | thetaR_tp2_mean <- mean(thetatR_tp2_vec, na.rm = T)
462 | thetaR_tp2_ci <- quantile(thetatR_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
463 | R_tp2_vec <- R_pp[, dthetaI_tp2_rd - T_prime]
464 | R_tp2_mean <- mean(R_tp2_vec, na.rm = T)
465 | R_tp2_ci <- quantile(R_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
466 | } else {
467 | thetatI_tp2_vec <- thetaI_mat[, dthetaI_tp2_rd]
468 | thetaI_tp2_mean <- mean(thetatI_tp2_vec, na.rm = T)
469 | thetaI_tp2_ci <- quantile(thetatI_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
470 | Y_tp2_vec <- NA
471 | Y_tp2_mean <- mean(Y_tp2_vec, na.rm = T)
472 | Y_tp2_ci <- quantile(Y_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
473 |
474 | thetatR_tp2_vec <- thetaR_mat[, dthetaI_tp2_rd]
475 | thetaR_tp2_mean <- mean(thetatR_tp2_vec, na.rm = T)
476 | thetaR_tp2_ci <- quantile(thetatR_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
477 | R_tp2_vec <- NA
478 | R_tp2_mean <- mean(R_tp2_vec, na.rm = T)
479 | R_tp2_ci <- quantile(R_tp2_vec, c(0.025, 0.5, 0.975), na.rm = T)
480 | }
481 | thetaR_max_vec <- thetaR_mat[, T_fin]
482 | thetaR_max_mean <- mean(thetaR_max_vec)
483 | thetaR_max_ci <- quantile(thetaR_max_vec, c(0.025, 0.5, 0.975), na.rm = T)
484 |
485 | cumInf_vec <- thetaR_mat[, T_fin] + thetaI_mat[, T_fin]
486 | cumInf_mean <- mean(cumInf_vec)
487 | cumInf_ci <- quantile(cumInf_vec, c(0.025, 0.5, 0.975), na.rm = T)
488 |
489 |
490 |
491 | dthetaI_tp1_date <- chron_ls[dthetaI_tp1]
492 | dthetaI_tp2_date <- chron_ls[dthetaI_tp2]
493 |
494 | incidence_vec <- thetaI_mat[, T_fin] + thetaR_mat[, T_fin]
495 | incidence_mean <- mean(incidence_vec, na.rm = T)
496 |
497 | incidence_ci <- quantile(incidence_vec, c(0.025, 0.5, 0.975), na.rm = T)
498 |
499 | first_tp_vec <- (1:T_fin)[apply(dthetaI_mat, 1, which.max)] # first second order derivative=0
500 |
501 | second_tp_vec <- sapply(1:len, function(l) {
502 | (first_tp_vec[l]:T_fin)[which.min(dthetaI_mat[l, first_tp_vec[l]:T_fin] > 0)]
503 | })
504 |
505 | end_p_vec <- sapply(1:len, function(l) {
506 | if (any(thetaI_mat[l, first_tp_vec[l]:T_fin] <= eps, na.rm = TRUE)) {
507 | (first_tp_vec[l]:T_fin)[which.max(thetaI_mat[l, first_tp_vec[l]:T_fin] <= eps)]
508 | } else {
509 | T_fin
510 | }
511 | })
512 |
513 |
514 | # first order derivative=0
515 | first_tp_mean <- mean(first_tp_vec, na.rm = T)
516 | second_tp_mean <- mean(second_tp_vec, na.rm = T)
517 | end_p_mean <- mean(end_p_vec, na.rm = T)
518 |
519 | first_tp_ci <- quantile(first_tp_vec, c(0.025, 0.5, 0.975), na.rm = T)
520 | second_tp_ci <- quantile(second_tp_vec, c(0.025, 0.5, 0.975), na.rm = T)
521 | end_p_ci <- quantile(end_p_vec, c(0.025, 0.5, 0.975), na.rm = T)
522 |
523 | first_tp_date_mean <- chron_ls[first_tp_mean]
524 | second_tp_date_mean <- chron_ls[second_tp_mean]
525 | end_p_date_mean <- chron_ls[end_p_mean]
526 |
527 | first_tp_date_ci <- chron_ls[first_tp_ci]
528 | second_tp_date_ci <- chron_ls[second_tp_ci]
529 | end_p_date_ci <- chron_ls[end_p_ci]
530 |
531 | names(first_tp_date_ci) <- c("2.5%", "50%", "97.5%")
532 | names(second_tp_date_ci) <- c("2.5%", "50%", "97.5%")
533 | names(end_p_date_ci) <- c("2.5%", "50%", "97.5%")
534 |
535 | if (save_files) {
536 | png(paste0(file_add, casename, "deriv.png"), width = 700, height = 350)
537 | plot(y = dthetaI, x = chron_ls, type = "l", ylab = "1st order derivative", main = "Infection prevalence process")
538 | abline(h = 0, col = 2)
539 | if (!is.null(change_time_chorn)) abline(v = change_time_chorn, col = "gray")
540 | abline(v = chron_ls[T_prime], col = "blue")
541 | legend("topright", legend = c("Last observation", "change point"), col = c("blue", "gray"), lty = 1, title = "", bty = "n")
542 | dev.off()
543 |
544 | png(paste0(file_add, casename, "thetaA_plot.png"), width = 700, height = 350)
545 | plot(y = colMeans(cbind(thetaA_p, thetaA_pp)), x = chron_ls, type = "l", xlab = "date", main = "Prevalence process for those immunized with antibody")
546 | if (!is.null(change_time_chorn)) abline(v = change_time_chorn, col = "gray")
547 | abline(v = chron_ls[T_prime], col = "blue")
548 | legend("topright", legend = c("Last observation", "change point"), col = c("blue", "gray"), lty = 1, title = "", bty = "n")
549 | dev.off()
550 | }
551 |
552 | ## Prepare the Spaghetti plot
553 | sample_dthetaI_mat <- cbind(dthetaI_mat[sample.int(len, 20, replace = F), ])
554 | colnames(sample_dthetaI_mat) <- c(as.character(chron_ls)[-1])
555 | sample_dthetaI_mat_long <- reshape2::melt(sample_dthetaI_mat)
556 | colnames(sample_dthetaI_mat_long) <- c("id", "date", "dthetaI")
557 | sample_dthetaI_mat_long$date <- (chron(as.character(sample_dthetaI_mat_long$date)))
558 |
559 | dthetaI_mean_data <- data.frame(dthetaI, date = chron_ls[-1])
560 | spaghetti_ht <- mean(range(sample_dthetaI_mat)) / 2
561 | spaghetti_plot <- ggplot() +
562 | theme_bw() +
563 | theme(
564 | plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
565 | plot.subtitle = element_text(hjust = 0.5, size = 12),
566 | axis.text.x = element_text(angle = 45, hjust = 1),
567 | axis.text = element_text(size = 15),
568 | axis.title = element_text(size = 14)
569 | ) +
570 | geom_line(data = sample_dthetaI_mat_long, aes(x = date, y = dthetaI, group = id, color = id)) +
571 | scale_color_gradientn(colours = rainbow(5, alpha = 0.5)) +
572 | labs(title = "spaghetti plot of infection prevalence process", x = "time", y = "1st order derivative") +
573 | geom_line(data = dthetaI_mean_data, aes(x = date, y = dthetaI), color = 1) +
574 | scale_x_continuous(
575 | labels = as.character(chron_ls)[seq(1, T_fin, 30)],
576 | breaks = as.numeric(chron_ls[-1][seq(1, T_fin, 30)])
577 | ) +
578 | annotate(geom = "text", label = as.character(chron(chron_ls[T_prime]), format = "mon day"), x = as.numeric(chron_ls[T_prime]) + 12, y = spaghetti_ht, color = "blue") +
579 | annotate(geom = "text", label = as.character(chron(dthetaI_tp1_date, format = "mon day")), x = as.numeric(dthetaI_tp1_date) + 12, y = spaghetti_ht * 1.25, color = "darkgreen") +
580 | geom_vline(xintercept = as.numeric(chron_ls[T_prime]), color = "blue", show.legend = TRUE) +
581 | geom_vline(xintercept = as.numeric(dthetaI_tp1_date), color = "darkgreen", show.legend = TRUE)
582 | # if(dthetaI_tp1>T_prime)
583 | spaghetti_plot <- spaghetti_plot +
584 | geom_rect(data = data.frame(xmin = as.numeric(first_tp_date_ci[1]), xmax = as.numeric(first_tp_date_ci[3]), ymin = -Inf, ymax = Inf, ci = "first tp"), aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), fill = "darkgreen", alpha = 0.15)
585 | # if(dthetaI_tp2>T_prime)
586 | spaghetti_plot <- spaghetti_plot +
587 | geom_rect(data = data.frame(xmin = as.numeric(second_tp_date_ci[1]), xmax = as.numeric(second_tp_date_ci[3], ci = "second tp"), ymin = -Inf, ymax = Inf), aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), fill = "purple", alpha = 0.15)
588 | if (dthetaI_tp2_date > dthetaI_tp1_date) {
589 | spaghetti_plot <- spaghetti_plot +
590 | geom_vline(xintercept = as.numeric(dthetaI_tp2_date), color = "purple", show.legend = TRUE) +
591 | annotate(geom = "text", label = as.character(chron(dthetaI_tp2_date, format = "mon day")), x = as.numeric(dthetaI_tp2_date) + 12, y = spaghetti_ht * 1.5, color = "purple")
592 | }
593 |
594 | if (save_files) ggsave(paste0(file_add, casename, "_spaghetti.png"), width = 12, height = 10)
595 | ##############
596 | y_text_ht <- max(rbind(thetaI_band, Y_band), na.rm = T) / 2
597 | plot1 <- ggplot(data = data_poly, aes(x = x, y = y)) +
598 | geom_polygon(alpha = 0.5, aes(fill = value, group = phase)) +
599 | labs(title = substitute(paste(casename, ": infection forecast with prior ", beta[0], "=", v1, ",", gamma[0], "=", v2, " and ", R[0], "=", v3), list(casename = casename, v1 = format(beta0, digits = 3), v2 = format(gamma0, digits = 3), v3 = format(R0, digits = 3))), subtitle = substitute(paste("Posterior ", beta[p], "=", v1, ",", gamma[p], "=", v2, " and ", R[0], "=", v3), list(v1 = format(beta_p_mean, digits = 3), v2 = format(gamma_p_mean, digits = 3), v3 = format(R0_p_mean, digits = 3))), x = "time", y = "P(Infected)") +
600 | geom_line(data = data_comp, aes(x = time, y = median), color = "red") +
601 | geom_vline(xintercept = T_prime, color = "blue", show.legend = TRUE) +
602 | geom_vline(xintercept = dthetaI_tp1, color = "darkgreen", show.legend = TRUE) +
603 | geom_line(data = data_comp, aes(x = time, y = mean), color = "darkgray") +
604 | geom_point(data = data_pre, aes(x = time, y = Y)) +
605 | theme_bw() +
606 | theme(
607 | plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
608 | plot.subtitle = element_text(hjust = 0.5, size = 12),
609 | axis.text.x = element_text(angle = 45, hjust = 1),
610 | axis.text = element_text(size = 15),
611 | axis.title = element_text(size = 14),
612 | legend.title = element_text(size = 15),
613 | legend.text = element_text(size = 12)
614 | ) +
615 | scale_x_continuous(
616 | labels = as.character(chron_ls)[seq(1, T_fin, 30)],
617 | breaks = seq(1, T_fin, 30)
618 | ) +
619 | scale_fill_discrete(
620 | name = "Posterior",
621 | labels = c(
622 | expression(paste(y[t[0] + 1:T]^I, " | ", y[1:t[0]]^I, ", ", y[1:t[0]]^R)),
623 | expression(paste(theta[1:t[0]]^I, " | ", y[1:t[0]]^I, ", ", y[1:t[0]]^R))
624 | )
625 | ) +
626 | annotate(geom = "text", label = as.character(chron(chron_ls[T_prime]), format = "mon day"), x = T_prime + 12, y = y_text_ht, color = "blue") +
627 | annotate(geom = "text", label = as.character(chron(dthetaI_tp1_date, format = "mon day")), x = dthetaI_tp1 + 12, y = y_text_ht * 1.25, color = "darkgreen")
628 | if (dthetaI_tp2 > dthetaI_tp1) {
629 | plot1 <- plot1 + geom_vline(xintercept = dthetaI_tp2, color = "purple", show.legend = TRUE) + annotate(geom = "text", label = as.character(chron(dthetaI_tp2_date, format = "mon day")), x = dthetaI_tp2 + 12, y = y_text_ht * 1.5, color = "purple")
630 | }
631 | # plot_list <- list(data_poly=data_poly,data_comp=data_comp,T_prime=T_prime,dthetaI_stationary2=dthetaI_stationary2,dthetaI_stationary1=dthetaI_stationary1,data_pre=data_pre,dthetaI_stationary2_date,dthetaI_stationary1_date,y_text_ht)
632 |
633 | if (save_files) ggsave(paste0(file_add, casename, "_forecast.png"), width = 12, height = 10)
634 |
635 | ### Removed
636 | R_band <- data.frame(t(apply(R_pp, 2, quantile, probs = c(0.025, 0.975), na.rm = T)))
637 | thetaR_band <- data.frame(t(apply(theta_p[, -1, 3], 2, quantile, probs = c(0.025, 0.975), na.rm = T)))
638 | R_mean <- c(colMeans(R_pp, na.rm = T))
639 | thetaR_mean <- c(colMeans(theta_p[, -1, 3], na.rm = T), colMeans(theta_pp[, , 3], na.rm = T))
640 | thetaR_med <- c(apply(theta_p[, -1, 3], 2, median, na.rm = T), apply(theta_pp[, , 3], 2, median, na.rm = T))
641 | colnames(R_band) <- c("lower", "upper")
642 | colnames(thetaR_band) <- c("lower", "upper")
643 | data_pre_R <- data.frame(time = 1:T_prime, R) # previous data
644 | data_post_R <- data.frame(time = 1:T_prime, thetaR_band) # posterior of theta^R
645 | data_fore_R <- data.frame(time = (T_prime + 1):T_fin, R_band, R_mean) # The forecast of R after T_prime
646 |
647 | data_comp_R <- data.frame(time = 1:T_fin, rbind(thetaR_band, R_band), phase = c(rep("pre", nrow(thetaR_band)), rep("post", nrow(R_band))), mean = thetaR_mean, median = thetaR_med, dead = thetaR_mean * death_in_R, dead_med = thetaR_med * death_in_R) # the filled area--polygon
648 |
649 | data_poly_R <- data.frame(y = c(thetaR_band$upper, rev(thetaR_band$lower), R_band$upper, rev(R_band$lower)), x = c(1:T_prime, T_prime:1, (T_prime + 1):T_fin, T_fin:(T_prime + 1)), phase = c(rep("pre", T_prime * 2), rep("post", (T_fin - T_prime) * 2)), value = c(rep(col2[1], T_prime * 2), rep(col2[2], (T_fin - T_prime) * 2)))
650 |
651 | r_text_ht <- max(rbind(thetaR_band, R_band), na.rm = T) / 2
652 | plot2 <- ggplot(data = data_poly_R, aes(x = x, y = y)) +
653 | geom_polygon(alpha = 0.5, aes(fill = value, group = phase)) +
654 | labs(
655 | title = substitute(
656 | paste(
657 | casename,
658 | ": removed forecast with prior ", beta[0], "=", v1, ",",
659 | gamma[0], "=", v2, " and ", R[0], "=", v3
660 | ),
661 | list(
662 | casename = casename, v1 = format(beta0, digits = 3),
663 | v2 = format(gamma0, digits = 3), v3 = format(R0, digits = 3)
664 | )
665 | ),
666 | subtitle = substitute(
667 | paste(
668 | "posterior: ", beta[p], "=", v1, ",",
669 | gamma[p], "=", v2, " and ", R[0], "=", v3
670 | ),
671 | list(
672 | v1 = format(beta_p_mean, digits = 3), v2 = format(gamma_p_mean, digits = 3),
673 | v3 = format(R0_p_mean, digits = 3)
674 | )
675 | ), x = "time", y = "P(Removed)"
676 | ) +
677 | geom_line(data = data_comp_R, aes(x = time, y = median), color = "red", linetype = 1) +
678 | geom_vline(xintercept = T_prime, color = "blue") +
679 | geom_vline(xintercept = dthetaI_tp1, color = "darkgreen") +
680 | geom_line(data = data_comp_R, aes(x = time, y = mean), color = "darkgray") +
681 | geom_point(data = data_pre_R, aes(x = time, y = R)) +
682 | theme_bw() +
683 | theme(
684 | plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
685 | plot.subtitle = element_text(hjust = 0.5, size = 12),
686 | axis.text.x = element_text(angle = 45, hjust = 1),
687 | axis.text = element_text(size = 15),
688 | axis.title = element_text(size = 14),
689 | legend.title = element_text(size = 15),
690 | legend.text = element_text(size = 12)
691 | ) +
692 | scale_x_continuous(labels = as.character(chron_ls)[seq(1, T_fin, 30)], breaks = seq(1, T_fin, 30)) +
693 | scale_fill_discrete(
694 | name = "Posterior",
695 | labels = c(
696 | expression(paste(y[t[0] + 1:T]^R, " | ", y[1:t[0]]^I, ", ", y[1:t[0]]^R)),
697 | expression(paste(theta[1:t[0]]^R, " | ", y[1:t[0]]^I, ", ", y[1:t[0]]^R))
698 | )
699 | ) +
700 | annotate(geom = "text", label = as.character(chron(chron_ls[T_prime]), format = "mon day"), x = T_prime + 12, y = r_text_ht, color = "blue") +
701 | annotate(geom = "text", label = as.character(chron(dthetaI_tp1_date, format = "mon day")), x = dthetaI_tp1 + 12, y = r_text_ht * 1.25, color = "darkgreen")
702 |
703 | if (dthetaI_tp2 > dthetaI_tp1) {
704 | plot2 <- plot2 + geom_vline(xintercept = dthetaI_tp2, color = "purple", show.legend = TRUE) + annotate(geom = "text", label = as.character(chron(dthetaI_tp2_date, format = "mon day")), x = dthetaI_tp2 + 12, y = r_text_ht * 1.5, color = "purple")
705 | }
706 | if (add_death) plot2 <- plot2 + geom_line(data = data_comp_R, aes(x = time, y = dead), color = "black", linetype = 1) + geom_line(data = data_comp_R, aes(x = time, y = dead_med), color = "black", linetype = 2)
707 | # plot2_list <- list(data_poly_R=data_poly_R,data_comp_R=data_comp_R,T_prime=T_prime,dthetaI_stationary2=dthetaI_stationary2,dthetaI_stationary1=dthetaI_stationary1,data_pre_R=data_pre_R,dthetaI_stationary2_date,dthetaI_stationary1_date)
708 |
709 |
710 |
711 | if (save_files) ggsave(paste0(file_add, casename, "_forecast2.png"), width = 12, height = 10)
712 |
713 | out_table <- matrix(c(theta_p_mean, theta_p_ci, thetaA_p_mean, thetaA_p_ci, R0_p_mean, R0_p_ci, gamma_p_mean, gamma_p_ci, beta_p_mean, beta_p_ci), nrow = 1)
714 |
715 | out_table1 <- data.frame(matrix(c(theta_p_mean, theta_p_ci, thetaA_p_mean, thetaA_p_ci, R0_p_mean, R0_p_ci, gamma_p_mean, gamma_p_ci, beta_p_mean, beta_p_ci, incidence_mean = incidence_mean, incidence_ci = incidence_ci, thetaI_tp1_mean = thetaI_tp1_mean, thetaI_tp1_ci = thetaI_tp1_ci, thetaR_tp1_mean = thetaR_tp1_mean, thetaR_tp1_ci = thetaR_tp1_ci, Y_tp1_mean = Y_tp1_mean, Y_tp1_ci = Y_tp1_ci, R_tp1_mean = R_tp1_mean, R_tp1_ci = R_tp1_ci, thetaI_tp2_mean = thetaI_tp2_mean, thetaI_tp2_ci = thetaI_tp2_ci, thetaR_tp2_mean = thetaR_tp2_mean, thetaR_tp2_ci = thetaR_tp2_ci, Y_tp2_mean = Y_tp2_mean, Y_tp2_ci = Y_tp2_ci, R_tp2_mean = R_tp2_mean, R_tp2_ci = R_tp2_ci, thetaR_max_mean, thetaR_max_ci, cumInf_mean = cumInf_mean, cumInf_ci = cumInf_ci), nrow = 1))
716 |
717 | out_table2 <- data.frame(matrix(c(dthetaI_tp1_date = as.character(dthetaI_tp1_date), first_tp_mean = as.character(first_tp_date_mean), first_tp_ci = as.character(first_tp_date_ci), dthetaI_tp2_date = as.character(dthetaI_tp2_date), second_tp_mean = as.character(second_tp_date_mean), second_tp_ci = as.character(second_tp_date_ci), end_p_date_mean = as.character(end_p_date_mean), end_p_date_ci = as.character(end_p_date_ci), begin_str = begin_str), nrow = 1))
718 |
719 | out_table <- cbind(out_table1, out_table2)
720 | # out_table<-matrix(c(theta_p_mean,theta_p_ci,R0_p_mean,R0_p_ci,gamma_p_mean,gamma_p_ci,beta_p_mean,beta_p_ci,k_p_mean,k_p_ci,lambdaY_p_mean,lambdaY_p_ci,lambdaR_p_mean,lambdaR_p_ci,as.character(first_order_change_date),as.character(second_order_change_date)),nrow=1)
721 |
722 |
723 |
724 | colnames(out_table) <- c("thetaS_last_obs_p_mean", "thetaI_last_obs_p_mean", "thetaR_last_obs_p_mean", "thetaS_last_obs_p_ci_low", "thetaS_last_obs_p_ci_med", "thetaS_last_obs_p_ci_up", "thetaI_last_obs_p_ci_low", "thetaI_last_obs_p_ci_med", "thetaI_last_obs_p_ci_up", "thetaR_last_obs_p_ci_low", "thetaR_last_obs_p_ci_med", "thetaR_last_obs_p_ci_up", "thetaA_last_obs_p_mean", "thetaA_last_obs_p_ci_low", "thetaA_last_obs_p_ci_med", "thetaA_last_obs_p_ci_up", "R0_p_mean", "R0_p_ci_low", "R0_p_ci_med", "R0_p_ci_up", "gamma_p_mean", "gamma_p_ci_low", "gamma_p_ci_med", "gamma_p_ci_up", "beta_p_mean", "beta_p_ci_low", "beta_p_ci_med", "beta_p_ci_up", "incidence_mean", "incidence_ci_low", "incidence_ci_median", "incidence_ci_up", "thetaI_tp1_mean", "thetaI_tp1_ci_low", "thetaI_tp1_ci_med", "thetaI_tp1_ci_up", "thetaR_tp1_mean", "thetaR_tp1_ci_low", "thetaR_tp1_ci_med", "thetaR_tp1_ci_up", "Y_tp1_mean", "Y_tp1_ci_low", "Y_tp1_ci_med", "Y_tp1_ci_up", "R_tp1_mean", "R_tp1_ci_low", "R_tp1_ci_med", "R_tp1_ci_up", "thetaI_tp2_mean", "thetaI_tp2_ci_low", "thetaI_tp2_ci_med", "thetaI_tp2_ci_up", "thetaR_tp2_mean", "thetaR_tp2_ci_low", "thetaR_tp2_ci_med", "thetaR_tp2_ci_up", "Y_tp2_mean", "Y_tp2_ci_low", "Y_tp2_ci_med", "Y_tp2_ci_up", "R_tp2_mean", "R_tp2_ci_low", "R_tp2_ci_med", "R_tp2_ci_up", "thetaR_max_mean", "thetaR_max_ci_low", "thetaR_max_ci_med", "thetaR_max_ci_up", "cumInf_mean", "cumInf_ci_low", "cumInf_ci_med", "cumInf_ci_up", "dthetaI_tp1_date", "first_tp_mean", "first_tp_ci_low", "first_tp_ci_med", "first_tp_ci_up", "dthetaI_tp2_date", "second_tp_mean", "second_tp_ci_low", "second_tp_ci_med", "second_tp_ci_up", "end_p_mean", "end_p_ci_low", "end_p_ci_med", "end_p_ci_up", "begin_str")
725 | # colnames(out_table)<-c("thetaS_p_mean","thetaI_p_mean","thetaR_p_mean","thetaS_p_ci_low","thetaS_p_ci_med","thetaS_p_ci_up","thetaI_p_ci_low","thetaI_p_ci_med","thetaI_p_ci_up","thetaR_p_ci_low","thetaR_p_ci_med","thetaR_p_ci_up","R0_p_mean","R0_p_ci_low","R0_p_ci_med","R0_p_ci_up","gamma_p_mean","gamma_p_ci_low","gamma_p_ci_med","gamma_p_ci_up","beta_p_mean","beta_p_ci_low","beta_p_ci_med","beta_p_ci_up","k_p_mean","k_p_ci_low","k_p_ci_med","k_p_ci_up","lambdaY_p_mean","lambdaY_p_ci_low","lambdaY_p_ci_med","lambdaY_p_ci_up","lambdaR_p_mean","lambdaR_p_ci_low","lambdaR_p_ci_med","lambdaR_p_ci_up","first_order_change_date","second_order_change_date")
726 |
727 | if (save_files) write.csv(out_table, file = paste0(file_add, casename, "_summary.csv"))
728 | if (save_mcmc) {
729 | save(theta_pp, thetaA_pp, Y_pp, R_pp, file = paste0(file_add, casename, "_forecast_MCMC.RData")) # @
730 | save(jags_sample, file = paste0(file_add, casename, "_rjags_MCMC.RData"))
731 | }
732 | if (save_plot_data) {
733 | other_plot <- list(T_prime = T_prime, T_fin = T_fin, chron_ls = chron_ls, dthetaI_tp1 = dthetaI_tp1, dthetaI_tp2 = dthetaI_tp2, dthetaI_tp1_date = dthetaI_tp1_date, dthetaI_tp2_date = dthetaI_tp2_date, beta_p_mean = beta_p_mean, gamma_p_mean = gamma_p_mean, R0_p_mean = R0_p_mean)
734 | spaghetti_plot_ls <- list(spaghetti_ht = spaghetti_ht, dthetaI_mean_data = dthetaI_mean_data, sample_dthetaI_mat_long = sample_dthetaI_mat_long, first_tp_date_ci = first_tp_date_ci, second_tp_date_ci = second_tp_date_ci)
735 | infection_plot_ls <- list(y_text_ht = y_text_ht, data_poly = data_poly, data_comp = data_comp, data_pre = data_pre)
736 | removed_plot_ls <- list(r_text_ht = r_text_ht, data_poly_R = data_poly_R, data_comp_R = data_comp_R, data_pre_R = data_pre_R)
737 | plot_data_ls <- list(casename = casename, other_plot = other_plot, spaghetti_plot_ls = spaghetti_plot_ls, infection_plot_ls = infection_plot_ls, removed_plot_ls = removed_plot_ls)
738 | save(plot_data_ls, file = paste0(file_add, casename, "_plot_data.RData"))
739 | }
740 |
741 | # Gelman-Rubin convergence diagnostics
742 | gelman_out_name <- c("R0", "gamma", "beta", "theta", "theta_A", "lambdaY", "lambdaR", "k")
743 | gelman_diag_list <- lapply(gelman_out_name, function(name) {
744 | if (name == "theta") {
745 | tryCatch(
746 | gelman.diag(as.mcmc.list(jags_sample[[name]])[, (1:3) * (T_prime + 1)],
747 | autoburnin = FALSE
748 | ),
749 | error = function(e) e
750 | )
751 | } else if (name == "theta_A") {
752 | list("theta_A: ", tryCatch(
753 | gelman.diag(as.mcmc.list(jags_sample[[name]])[, (T_prime + 1)],
754 | autoburnin = FALSE
755 | ),
756 | error = function(e) e
757 | ))
758 | } else {
759 | tryCatch(
760 | gelman.diag(as.mcmc.list(jags_sample[[name]]),
761 | autoburnin = FALSE
762 | ),
763 | error = function(e) e
764 | )
765 | }
766 | })
767 | if (save_files) {
768 | sink(paste0(file_add, casename, "_Gelman_diag.txt"))
769 | print(gelman_diag_list)
770 | sink()
771 | }
772 | res <- list(
773 | casename = casename,
774 | incidence_mean = incidence_mean,
775 | incidence_ci = incidence_ci,
776 | out_table = out_table,
777 | plot_infection = plot1,
778 | plot_removed = plot2,
779 | spaghetti_plot = spaghetti_plot,
780 | first_tp_mean = as.character(first_tp_date_mean),
781 | first_tp_ci = as.character(first_tp_date_ci),
782 | second_tp_mean = as.character(second_tp_date_mean),
783 | second_tp_ci = as.character(second_tp_date_ci),
784 | dic_val = dic_val,
785 | gelman_diag_list = gelman_diag_list
786 | )
787 | return(res)
788 | }
789 |
790 |
791 | if (FALSE) {
792 | NI_complete <- c(
793 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
794 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
795 | 13522, 16678, 19665, 22112, 24953, 27100, 29631, 31728, 33366
796 | )
797 | RI_complete <- c(
798 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94, 121, 152, 213,
799 | 252, 345, 417, 561, 650, 811, 1017, 1261, 1485, 1917, 2260,
800 | 2725, 3284, 3754
801 | )
802 | N <- 58.5e6
803 | R <- RI_complete / N
804 | Y <- NI_complete / N - R # Jan13->Feb 11
805 |
806 | change_time <- c("02/08/2020")
807 | alpha0 <- c(0.2) # 20% of the susceptible population were found immunized
808 | res.antibody <- eSAIR(Y, R,
809 | begin_str = "01/13/2020", death_in_R = 0.4,
810 | alpha0 = alpha0, change_time = change_time,
811 | casename = "Hubei_antibody", save_files = F, save_mcmc = F,
812 | M = 5e2, nburnin = 2e2
813 | )
814 | res.antibody$plot_infection
815 | res.antibody$gelman_diag_list
816 | }
817 |
--------------------------------------------------------------------------------
/R/eSIR.R:
--------------------------------------------------------------------------------
1 | #' @import rjags
2 | #' @import scales
3 | #' @import ggplot2
4 | #' @import chron
5 | #' @import gtools
6 | #' @import data.table
7 | #' @import stats
8 | #' @import grDevices
9 | #' @import graphics
10 | #' @import utils
11 | #' @import coda
12 | #' @importFrom coda as.mcmc.list
13 | NULL
14 |
--------------------------------------------------------------------------------
/R/utils.R:
--------------------------------------------------------------------------------
1 | gg_color_hue <- function(n) {
2 | hues = seq(15, 375, length = n + 1)
3 | hcl(h = hues, l = 65, c = 100)[1:n]
4 | }
5 |
6 | lognorm.parm <- function(mu0,var0){
7 | var <- log(var0 / mu0^2 + 1)
8 | mu <- log(mu0) - var / 2
9 | list(mu = mu, var = var)
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/README.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "R package eSIR: extended state-space SIR epidemiological models"
3 | author: "[Song Lab](http://www.umich.edu/~songlab/)"
4 | date: "`r Sys.Date()`"
5 | output: github_document
6 | ---
7 |
8 | ```{r setup, include=FALSE, echo=FALSE}
9 | knitr::opts_chunk$set(collapse = TRUE,
10 | comment = "#>",
11 | fig.width=12, fig.height=8,
12 | fig.path = "man/figures/README-",
13 | file.path = "man/files/README-")
14 |
15 | ```
16 |
17 | **Notice**:
18 |
19 | 1. We add new features in `tvt.eSIR()`. Now the new function `tvt.eSIR2()` adds `time_unit` which will allow users to change their time unit from 1 day to any arbitrary numbers of days.
20 |
21 |
22 | 2. Since version 0.3.1, we added the US data. The most recent update was on June 25th, 2021. We used data summarized from [JHU CSSE GitHub](https://github.com/CSSEGISandData/COVID-19) and [1Point3Acres](https://coronavirus.1point3acres.com). Only 41 states have complete recovery data. We will update the data every Thursday or Friday evening. Using following codes for the data:
23 | ```{r load data, eval = FALSE}
24 | data("confirmed") # From JHU CSSE
25 | data("death") # From JHU CSSE
26 | data("recovered") # partly from 1Point3Acres
27 | data("USA_state_N") #population in each state
28 |
29 | ```
30 |
31 | 3. Since version 0.3.3, we added Gelman-Rubin statistic for convergence check using [gelman.diag](https://www.rdocumentation.org/packages/coda/versions/0.19-3/topics/gelman.diag) from [`rjags`](https://cran.r-project.org/web/packages/rjags/index.html). Their values substantially larger than 1 imply a failure of convergence of the MCMC chains. Save it in a `.txt` file by setting `save_files = TRUE` or retrieve it via following R code (assuming that `res` is object returned from `tvt.eSIR` or `qh.eSIR`):
32 |
33 | ```r
34 | res$gelman_diag_list
35 | ```
36 |
37 |
38 | Chinese version:[中文](https://github.com/lilywang1988/eSIR/blob/master/README_cn.md)
39 |
40 | ## Purpose
41 |
42 | 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.
43 |
44 | 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).
45 |
46 | 
47 |
48 | 
49 |
50 | 
51 |
52 | 
53 |
54 | 
55 |
56 | ## Preparation
57 |
58 | [Download packages directly](https://github.com/lilywang1988/eSIR/blob/master/install_pkg)
59 |
60 | 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.
61 |
62 | 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).
63 |
64 |
65 | ``` r
66 | # install.packages("devtools")
67 | # library(devtools)
68 | # install_github("lilywang1988/eSIR")
69 | library(eSIR)
70 | ```
71 |
72 | 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).
73 |
74 | For data outside China, we use [JHU CSSE GitHub](https://github.com/CSSEGISandData/COVID-19) data. Another package [coronavirus](https://github.com/RamiKrispin/coronavirus) has its GitHub version udpated daily, which is also quite useful.
75 |
76 | ``` r
77 | # Data of COVID-19 can be found in the following R packages:
78 | # install_github("GuangchuangYu/nCov2019")
79 | #library(nCov2019)
80 | # install_github("qingyuanzhao/2019-nCov-Data")
81 | #library(2019-nCov-Data)
82 | ```
83 |
84 | 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")`. [This](https://stackoverflow.com/questions/31114991/installation-of-package-devtools-had-non-zero-exit-status-on-ubuntu) stackoverflow question perfectly solved the issue I encountered when
85 | installing `devtools` on ubuntu. You may follow this [gist](https://gist.github.com/lilywang1988/170fbf1bbea1a6c23bc43a0dc871a0ca) to resolve other possible issues when installing `eSIR` on the recent version of Ubuntu.
86 |
87 |
88 | ## Model 1 using `tvt.eSIR()`: a SIR model with a time-varying transmission rate
89 |
90 | 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.
91 |
92 | The function can be either stepwise or exponential:
93 |
94 | 
95 |
96 | 
97 |
98 | ```{r model1}
99 | set.seed(20192020)
100 | library(eSIR)
101 | # Hubei province data Jan13 -> Feb 11
102 | # Cumulative number of infected cases
103 | NI_complete <- c(
104 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
105 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
106 | 13522,16678,19665,22112,24953,27100,29631,31728,33366
107 | )
108 | # Cumulative number of removed cases
109 | RI_complete <- c(
110 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94,
111 | 121, 152, 213, 252, 345, 417, 561, 650, 811,
112 | 1017, 1261, 1485, 1917, 2260, 2725, 3284, 3754
113 | )
114 | N <- 58.5e6
115 | R <- RI_complete / N
116 | Y <- NI_complete / N - R #Jan13->Feb 11
117 |
118 | ### Step function of pi(t)
119 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
120 | pi0 <- c(1.0, 0.9, 0.5, 0.1)
121 | res.step <- tvt.eSIR(Y,
122 | R,
123 | begin_str = "01/13/2020",
124 | T_fin = 200,
125 | pi0 = pi0,
126 | change_time = change_time,
127 | dic = FALSE,
128 | casename = "Hubei_step",
129 | save_files = FALSE,
130 | save_mcmc = FALSE,
131 | save_plot_data = TRUE, # can plot them
132 | M = 5e3,
133 | nburnin = 2e3 # additional to M
134 | )
135 |
136 | res.step$plot_infection
137 | res.step$plot_removed
138 | res.step$spaghetti_plot
139 |
140 |
141 | # If we change the time unit to 5 days
142 | # Cumulative number of infected cases
143 | NI_complete2 <- NI_complete[seq(1, length(NI_complete), 5)]
144 | # Cumulative number of removed cases
145 | RI_complete2 <- RI_complete[seq(1, length(RI_complete), 5)]
146 | N2 <- 58.5e6
147 | R2 <- RI_complete2 / N2
148 | Y2 <- NI_complete2 / N2 - R2 #Jan13->Feb 11
149 | change_time2 <- c("01/23/2020", "02/04/2020", "02/08/2020")
150 | pi02 <- c(1.0, 0.9, 0.5, 0.1)
151 | res.step2 <- tvt.eSIR2(Y2,
152 | R2,
153 | begin_str = "01/13/2020",
154 | T_fin = 40,
155 | pi0 = pi02,
156 | change_time = change_time,
157 | dic = FALSE,
158 | casename = "Hubei_step2",
159 | save_files = FALSE,
160 | save_mcmc = FALSE,
161 | save_plot_data = TRUE,
162 | M = 5e3,
163 | nburnin = 2e3,
164 | time_unit = 5 #new feature!
165 | )
166 |
167 | res.step2$plot_infection
168 | res.step2$plot_removed
169 | res.step2$spaghetti_plot
170 | res.step2$dic_val
171 | #res.step$gelman_diag_list
172 | ### continuous exponential function of pi(t)
173 | res.exp <- tvt.eSIR(Y,
174 | R,
175 | begin_str = "01/13/2020",
176 | death_in_R = 0.4,
177 | T_fin = 200,
178 | exponential = TRUE,
179 | dic = FALSE,
180 | lambda0 = 0.05,
181 | casename = "Hubei_exp",
182 | save_files = FALSE,
183 | save_mcmc = FALSE,
184 | save_plot_data = TRUE,
185 | M = 5e3,
186 | nburnin = 2e3)
187 |
188 | res.exp$plot_infection
189 | res.exp$spaghetti_plot
190 | #res.exp$plot_removed
191 |
192 | # Again, if we change our time unit to 5 days
193 | res.exp2 <- tvt.eSIR2(Y2,
194 | R2,
195 | begin_str = "01/13/2020",
196 | death_in_R = 0.4,
197 | T_fin = 200,
198 | exponential = TRUE,
199 | dic=FALSE,
200 | lambda0 = 0.05,
201 | casename = "Hubei_exp2",
202 | save_files = FALSE,
203 | save_mcmc = FALSE,
204 | save_plot_data = TRUE,
205 | M = 5e3,
206 | nburnin = 2e3,
207 | time_unit = 5)
208 |
209 | res.exp2$plot_infection
210 | res.exp2$spaghetti_plot
211 |
212 | ### without pi(t), the standard state-space SIR model without intervention
213 | res.nopi <- tvt.eSIR(Y,
214 | R,
215 | begin_str = "01/13/2020",
216 | death_in_R = 0.4,
217 | T_fin = 200,
218 | casename = "Hubei_nopi",
219 | save_files = F,
220 | save_plot_data = F,
221 | M=5e3,nburnin = 2e3)
222 | res.nopi$plot_infection
223 | res.nopi$spaghetti_plot
224 | #res.nopi$plot_removed
225 | ```
226 |
227 |
228 | ## Model 2 using `qh.eSIR()`: SIR with time-varying quarantine, which follows a Dirac Delta function
229 |
230 | 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.
231 | 
232 |
233 | 
234 |
235 |
236 | ```{r model2}
237 | set.seed(20192020)
238 | # Cumulative number of infected cases
239 | NI_complete <- c(
240 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444,
241 | 549, 729, 1052, 1423, 2714, 3554, 4903, 5806,
242 | 7153, 9074, 11177, 13522, 16678, 19665, 22112,
243 | 24953, 27100, 29631, 31728, 33366)
244 | # Cumulative number of removed cases
245 | RI_complete <- c(
246 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55,
247 | 71, 94, 121, 152, 213, 252, 345, 417, 561,
248 | 650, 811, 1017, 1261, 1485, 1917, 2260,
249 | 2725, 3284, 3754)
250 | N <- 58.5e6
251 | R <- RI_complete / N
252 | Y <- NI_complete / N - R #Jan13->Feb 11
253 |
254 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
255 | phi0 <- c(0.1, 0.4, 0.4)
256 | res.q <- qh.eSIR(Y,
257 | R,
258 | begin_str = "01/13/2020",
259 | phi0 = phi0,
260 | change_time = change_time,
261 | casename = "Hubei_q",
262 | save_files = TRUE,
263 | save_mcmc = FALSE,
264 | save_plot_data = FALSE,
265 | M = 5e3,
266 | nburnin = 2e3)
267 | res.q$plot_infection
268 | ```
269 |
270 | 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.
271 |
272 | 
273 |
274 |
275 | ## Model 3 using `eSAIR`: SIR with time-varying subset of population immunized with antibody positivity
276 |
277 | To address the under-reporting issue associated with the available public databases and to build the self-immunization into the infection dynamics, we then further extend the previous eSIR model to an eSAIR model by adding an antibody (A) compartment. As is shown in the bottom thread of the following figure, this A compartment accounts for the probability of being self-immunized with antibodies to COVID-19, denoted by $\theta_t^A$; see equation as follows too, where $\alpha(t)$ is a function describing the proportion of people moving from the susceptible compartment to the antibody compartment over time. Compartment A helps circumvent limitations of data collection, especially embracing individuals who were infected but self-cured at home with no confirmation by viral RT-PCR diagnostic tests. This new eSAIR model characterizes the underlying population-level dynamics of the pandemic. The following system of ordinary differential equations defines collectively the continuous-time dynamics for the eSAIR model, which governs the law of movements among four compartments of Susceptible, Self-immunized, Infected and Removed.
278 |
279 | 
280 |
281 | 
282 |
283 | In the example below, we implemented this function onto New York state data assuming that by April 29, 20% of the population have been self-immunized with antibody positivity.
284 |
285 | ```{r model 3}
286 | # Cumulative number of infected cases
287 | NI_complete <- c(
288 | 1, 2, 11, 23, 31, 76, 106, 142, 150, 220, 327,
289 | 421, 613, 615, 967, 1578, 3038, 5704, 8403,
290 | 11727, 15800, 20884, 25681, 30841, 37877,
291 | 44876, 52410, 59648, 66663, 75833, 83948,
292 | 92506, 102987, 113833, 123160, 131815,
293 | 139875, 151061, 161779, 172348, 181026,
294 | 189033, 195749, 203020, 214454, 223691,
295 | 230597, 237474, 243382, 248416, 253519,
296 | 258222, 263460, 271590, 282143, 288045,
297 | 291996, 295106, 299691, 304372, 308314)
298 | # Cumulative number of removed cases
299 | RI_complete <- c(
300 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
301 | 20, 26, 38, 52, 200, 311, 468, 662,
302 | 893, 1144, 1547, 2144, 2931, 3900,
303 | 5133, 6201, 7657, 9483, 11536,
304 | 13915, 16276, 18781, 21110, 23424,
305 | 26469, 29784, 32899, 35785, 37730,
306 | 39207, 40703, 42164, 43488, 44723,
307 | 45887, 47473, 47686, 48769, 49572,
308 | 50221, 52161, 52917, 54115, 54613,
309 | 55473, 55816, 56809, 57265, 58525)
310 | N <- 8.399e6
311 | R <- RI_complete / N
312 | Y <- NI_complete / N - R
313 |
314 | change_time <- c("04/29/2020")
315 | alpha0 <- c(0.2) # 20% of the susceptible population were found immunized
316 | res.antibody <- eSAIR(Y,
317 | R,
318 | begin_str = "03/01/2020",
319 | alpha0 = alpha0,
320 | change_time = change_time,
321 | casename = "New_York_antibody",
322 | save_files = F,
323 | save_mcmc = F,
324 | M=5e2,
325 | nburnin = 2e2)
326 | res.antibody$plot_infection
327 |
328 |
329 | ```
330 |
331 |
332 |
333 | ## Outputs and summary table
334 |
335 | 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.
336 |
337 | For details, please explore our package directly. We have `.rd` files established, please use `help(tvt.eSIR)` or `?qh.eSIR` to find them.
338 |
339 | ## Acknowledgements
340 | This package is created and maintained by [Lili Wang](lilywang@umich.edu), contributed by [Fei Wang](https://github.com/feiwsteven), [Lu Tang](https://github.com/ClumsyBear), and [Paul Egeler](https://github.com/pegeler). We also thank [Kangping Yang](kangpiny@umich.edu) for helping us collect the recovery data from the web page.
341 |
342 |
343 | ## References
344 |
345 | 1. Wang, L., Zhou, Y., He, J., Zhu, B., Wang, F., Tang, L., ... & Song, P. X. (2020). An epidemiological forecast model and software assessing interventions on the COVID-19 epidemic in China. Journal of Data Science, 18(3), 409-432. [link](https://www.airitilibrary.com/Publication/alDetailedMesh?DocID=16838602-202007-202008240002-202008240002-409-432&sourceBrowseType=0)
346 |
347 | 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.
348 |
349 | 3. Gelman, A., & Rubin, D. B. (1992). Inference from iterative simulation using multiple sequences. Statistical science, 7(4), 457-472.
350 |
351 | -----------
352 | Shield: [![CC BY 4.0][cc-by-shield]][cc-by]
353 |
354 | This work is licensed under a [Creative Commons Attribution 4.0 International
355 | License][cc-by].
356 |
357 | [![CC BY 4.0][cc-by-image]][cc-by]
358 |
359 | [cc-by]: http://creativecommons.org/licenses/by/4.0/
360 | [cc-by-image]: https://i.creativecommons.org/l/by/4.0/88x31.png
361 | [cc-by-shield]: https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg
362 |
363 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | R package eSIR: extended state-space SIR epidemiological models
2 | ================
3 | [Song Lab](http://www.umich.edu/~songlab/)
4 | 2021-10-31
5 |
6 | **Notice**:
7 |
8 | 1. We add new features in `tvt.eSIR()`. Now the new function
9 | `tvt.eSIR2()` adds `time_unit` which will allow users to change their
10 | time unit from 1 day to any arbitrary numbers of days.
11 |
12 | 2. Since version 0.3.1, we added the US data. The most recent update
13 | was on June 25th, 2021. We used data summarized from [JHU CSSE
14 | GitHub](https://github.com/CSSEGISandData/COVID-19) and
15 | [1Point3Acres](https://coronavirus.1point3acres.com). Only 41 states
16 | have complete recovery data. We will update the data every Thursday
17 | or Friday evening. Using following codes for the data:
18 |
19 |
20 |
21 | ``` r
22 | data("confirmed") # From JHU CSSE
23 | data("death") # From JHU CSSE
24 | data("recovered") # partly from 1Point3Acres
25 | data("USA_state_N") #population in each state
26 | ```
27 |
28 | 3. Since version 0.3.3, we added Gelman-Rubin statistic for convergence
29 | check using
30 | [gelman.diag](https://www.rdocumentation.org/packages/coda/versions/0.19-3/topics/gelman.diag)
31 | from
32 | [`rjags`](https://cran.r-project.org/web/packages/rjags/index.html).
33 | Their values substantially larger than 1 imply a failure of
34 | convergence of the MCMC chains. Save it in a `.txt` file by setting
35 | `save_files = TRUE` or retrieve it via following R code (assuming
36 | that `res` is object returned from `tvt.eSIR` or `qh.eSIR`):
37 |
38 |
39 |
40 | ``` r
41 | res$gelman_diag_list
42 | ```
43 |
44 | Chinese
45 | version:[中文](https://github.com/lilywang1988/eSIR/blob/master/README_cn.md)
46 |
47 | ## Purpose
48 |
49 | The outbreak of novel Corona Virus disease (a.k.a. COVID-19), originated
50 | in Wuhan, the capital of Hubei Province spreads quickly and affects many
51 | cities in China as well as many countries in the world. The Chinese
52 | government has enforced very stringent quarantine and inspection to
53 | prevent the worsening spread of COVID-19. Although various forms of
54 | forecast on the turning points of this epidemic within and outside Hubei
55 | Province have been published in the media, none of the prediction models
56 | has explicitly accounted for the time-varying quarantine protocols. We
57 | extended the classical SIR model for infectious disease by incorporating
58 | forms of medical isolation (in-home quarantine and hospitalization) in
59 | the underlying infectious disease dynamic system. Using the state-space
60 | model for both daily infected and hospitalized incidences and MCMC
61 | algorithms, we assess the effectiveness of quarantine protocols for
62 | confining COVID-19 spread in both Hubei Province and the other regions
63 | of China. Both predicted turning points and their credible bands may be
64 | obtained from the extended SIR under a given quarantine protocol. R
65 | software packages are also made publicly available for interested users.
66 |
67 | The standard SIR model has three components: susceptible, infected, and
68 | removed (including the recovery and dead). In the following sections, we
69 | will introduce the other extended state-space SIR models and their
70 | implementation in the package. **The results provided below are based on
71 | relatively short chains.** According to our experience, this setting
72 | (`M=5e3` and `nburnin=2e3`) should provide acceptable results in terms
73 | of the trend and turning points estimation, the estimation of parameters
74 | and their credible intervals might not be accurate. Hence, if possible,
75 | we would recommend using `M=5e5` and `nburnin=2e5` to obtain stable MCMC
76 | chains via
77 | [`rjags`](https://cran.r-project.org/web/packages/rjags/index.html).
78 |
79 | 
80 |
81 | 
82 |
83 | 
84 |
85 | 
86 |
87 | 
88 |
89 | ## Preparation
90 |
91 | [Download packages
92 | directly](https://github.com/lilywang1988/eSIR/blob/master/install_pkg)
93 |
94 | To install and use this R package from Github, you will need to first
95 | install the R package `devtools`. Please uncomment the codes to install
96 | them. `eSIR` depends on three other packages, `rjags` (an interface to
97 | the JAGS library), `chron` and `gtools`, which could be installed with
98 | `eSIR` if not yet.
99 |
100 | An error may occur if you have not yet installed JAGS-4.x.y.exe (for any
101 | x \>= 0, y \>=0). **Windows** users may download and install JAGS from
102 | [here](http://www.sourceforge.net/projects/mcmc-jags/files). **Mac**
103 | users may follow steps at
104 | [casallas/8411082](https://gist.github.com/casallas/8411082).
105 |
106 | ``` r
107 | # install.packages("devtools")
108 | # library(devtools)
109 | # install_github("lilywang1988/eSIR")
110 | library(eSIR)
111 | ```
112 |
113 | Our data are collected daily from
114 | [dxy.com](https://mama.dxy.com/outbreak/daily-of-nationwide-new?index=20200206&locationIds=999&from=todh5).
115 | Alternatively, we notice some convenient access to COVID-19 data from
116 | [GuangchuangYu/nCov2019](https://github.com/GuangchuangYu/nCov2019).
117 |
118 | For data outside China, we use [JHU CSSE
119 | GitHub](https://github.com/CSSEGISandData/COVID-19) data. Another
120 | package [coronavirus](https://github.com/RamiKrispin/coronavirus) has
121 | its GitHub version udpated daily, which is also quite useful.
122 |
123 | ``` r
124 | # Data of COVID-19 can be found in the following R packages:
125 | # install_github("GuangchuangYu/nCov2019")
126 | #library(nCov2019)
127 | # install_github("qingyuanzhao/2019-nCov-Data")
128 | #library(2019-nCov-Data)
129 | ```
130 |
131 | In Ubuntu (18.04) Linux, please first update R to a version \>= 3.6. You
132 | may need to install jags package as well by `sudo apt-get install jags`
133 | before install devtools by `install.packages("devtools")`.
134 | [This](https://stackoverflow.com/questions/31114991/installation-of-package-devtools-had-non-zero-exit-status-on-ubuntu)
135 | stackoverflow question perfectly solved the issue I encountered when
136 | installing `devtools` on ubuntu. You may follow this
137 | [gist](https://gist.github.com/lilywang1988/170fbf1bbea1a6c23bc43a0dc871a0ca)
138 | to resolve other possible issues when installing `eSIR` on the recent
139 | version of Ubuntu.
140 |
141 | ## Model 1 using `tvt.eSIR()`: a SIR model with a time-varying transmission rate
142 |
143 | By introducing a time-dependent \[\pi(t)\in [0,1]\] function that
144 | modifies the transmission rate \[\beta\], we can depict a series of
145 | time-varying changes caused by either external variations like
146 | government policies, protective measures and environment changes, or
147 | internal variations like mutations and evolutions of the pathogen.
148 |
149 | The function can be either stepwise or exponential:
150 |
151 | 
152 |
153 | 
154 |
155 | ``` r
156 | set.seed(20192020)
157 | library(eSIR)
158 | # Hubei province data Jan13 -> Feb 11
159 | # Cumulative number of infected cases
160 | NI_complete <- c(
161 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
162 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
163 | 13522,16678,19665,22112,24953,27100,29631,31728,33366
164 | )
165 | # Cumulative number of removed cases
166 | RI_complete <- c(
167 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94,
168 | 121, 152, 213, 252, 345, 417, 561, 650, 811,
169 | 1017, 1261, 1485, 1917, 2260, 2725, 3284, 3754
170 | )
171 | N <- 58.5e6
172 | R <- RI_complete / N
173 | Y <- NI_complete / N - R #Jan13->Feb 11
174 |
175 | ### Step function of pi(t)
176 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
177 | pi0 <- c(1.0, 0.9, 0.5, 0.1)
178 | res.step <- tvt.eSIR(Y,
179 | R,
180 | begin_str = "01/13/2020",
181 | T_fin = 200,
182 | pi0 = pi0,
183 | change_time = change_time,
184 | dic = FALSE,
185 | casename = "Hubei_step",
186 | save_files = FALSE,
187 | save_mcmc = FALSE,
188 | save_plot_data = TRUE, # can plot them
189 | M = 5e3,
190 | nburnin = 2e3 # additional to M
191 | )
192 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
193 | #> Running for step-function pi(t)
194 | #> Compiling model graph
195 | #> Resolving undeclared variables
196 | #> Allocating nodes
197 | #> Graph information:
198 | #> Observed stochastic nodes: 60
199 | #> Unobserved stochastic nodes: 36
200 | #> Total graph size: 1875
201 | #>
202 | #> Initializing model
203 |
204 | res.step$plot_infection
205 | ```
206 |
207 | 
208 |
209 | ``` r
210 | res.step$plot_removed
211 | ```
212 |
213 | 
214 |
215 | ``` r
216 | res.step$spaghetti_plot
217 | ```
218 |
219 | 
220 |
221 | ``` r
222 |
223 |
224 | # If we change the time unit to 5 days
225 | # Cumulative number of infected cases
226 | NI_complete2 <- NI_complete[seq(1, length(NI_complete), 5)]
227 | # Cumulative number of removed cases
228 | RI_complete2 <- RI_complete[seq(1, length(RI_complete), 5)]
229 | N2 <- 58.5e6
230 | R2 <- RI_complete2 / N2
231 | Y2 <- NI_complete2 / N2 - R2 #Jan13->Feb 11
232 | change_time2 <- c("01/23/2020", "02/04/2020", "02/08/2020")
233 | pi02 <- c(1.0, 0.9, 0.5, 0.1)
234 | res.step2 <- tvt.eSIR2(Y2,
235 | R2,
236 | begin_str = "01/13/2020",
237 | T_fin = 40,
238 | pi0 = pi02,
239 | change_time = change_time,
240 | dic = FALSE,
241 | casename = "Hubei_step2",
242 | save_files = FALSE,
243 | save_mcmc = FALSE,
244 | save_plot_data = TRUE,
245 | M = 5e3,
246 | nburnin = 2e3,
247 | time_unit = 5 #new feature!
248 | )
249 | #> The follow-up is from 01/13/20 to 07/26/20 and the last observed date is 02/07/20.
250 | #> Running for step-function pi(t)
251 | #> Compiling model graph
252 | #> Resolving undeclared variables
253 | #> Allocating nodes
254 | #> Graph information:
255 | #> Observed stochastic nodes: 12
256 | #> Unobserved stochastic nodes: 12
257 | #> Total graph size: 395
258 | #>
259 | #> Initializing model
260 |
261 | res.step2$plot_infection
262 | ```
263 |
264 | 
265 |
266 | ``` r
267 | res.step2$plot_removed
268 | ```
269 |
270 | 
271 |
272 | ``` r
273 | res.step2$spaghetti_plot
274 | ```
275 |
276 | 
277 |
278 | ``` r
279 | res.step2$dic_val
280 | #> NULL
281 | #res.step$gelman_diag_list
282 | ### continuous exponential function of pi(t)
283 | res.exp <- tvt.eSIR(Y,
284 | R,
285 | begin_str = "01/13/2020",
286 | death_in_R = 0.4,
287 | T_fin = 200,
288 | exponential = TRUE,
289 | dic = FALSE,
290 | lambda0 = 0.05,
291 | casename = "Hubei_exp",
292 | save_files = FALSE,
293 | save_mcmc = FALSE,
294 | save_plot_data = TRUE,
295 | M = 5e3,
296 | nburnin = 2e3)
297 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
298 | #> Running for exponential-function pi(t)
299 | #> Compiling model graph
300 | #> Resolving undeclared variables
301 | #> Allocating nodes
302 | #> Graph information:
303 | #> Observed stochastic nodes: 60
304 | #> Unobserved stochastic nodes: 36
305 | #> Total graph size: 1875
306 | #>
307 | #> Initializing model
308 |
309 | res.exp$plot_infection
310 | ```
311 |
312 | 
313 |
314 | ``` r
315 | res.exp$spaghetti_plot
316 | ```
317 |
318 | 
319 |
320 | ``` r
321 | #res.exp$plot_removed
322 |
323 | # Again, if we change our time unit to 5 days
324 | res.exp2 <- tvt.eSIR2(Y2,
325 | R2,
326 | begin_str = "01/13/2020",
327 | death_in_R = 0.4,
328 | T_fin = 200,
329 | exponential = TRUE,
330 | dic=FALSE,
331 | lambda0 = 0.05,
332 | casename = "Hubei_exp2",
333 | save_files = FALSE,
334 | save_mcmc = FALSE,
335 | save_plot_data = TRUE,
336 | M = 5e3,
337 | nburnin = 2e3,
338 | time_unit = 5)
339 | #> The follow-up is from 01/13/20 to 10/04/22 and the last observed date is 02/07/20.
340 | #> Running for exponential-function pi(t)
341 | #> Compiling model graph
342 | #> Resolving undeclared variables
343 | #> Allocating nodes
344 | #> Graph information:
345 | #> Observed stochastic nodes: 12
346 | #> Unobserved stochastic nodes: 12
347 | #> Total graph size: 555
348 | #>
349 | #> Initializing model
350 |
351 | res.exp2$plot_infection
352 | ```
353 |
354 | 
355 |
356 | ``` r
357 | res.exp2$spaghetti_plot
358 | ```
359 |
360 | 
361 |
362 | ``` r
363 |
364 | ### without pi(t), the standard state-space SIR model without intervention
365 | res.nopi <- tvt.eSIR(Y,
366 | R,
367 | begin_str = "01/13/2020",
368 | death_in_R = 0.4,
369 | T_fin = 200,
370 | casename = "Hubei_nopi",
371 | save_files = F,
372 | save_plot_data = F,
373 | M=5e3,nburnin = 2e3)
374 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
375 | #> Running without pi(t)
376 | #> Compiling model graph
377 | #> Resolving undeclared variables
378 | #> Allocating nodes
379 | #> Graph information:
380 | #> Observed stochastic nodes: 60
381 | #> Unobserved stochastic nodes: 36
382 | #> Total graph size: 1875
383 | #>
384 | #> Initializing model
385 | res.nopi$plot_infection
386 | ```
387 |
388 | 
389 |
390 | ``` r
391 | res.nopi$spaghetti_plot
392 | ```
393 |
394 | 
395 |
396 | ``` r
397 | #res.nopi$plot_removed
398 | ```
399 |
400 | ## Model 2 using `qh.eSIR()`: SIR with time-varying quarantine, which follows a Dirac Delta function
401 |
402 | By introducing a vector of `phi` and its corresponding changing points
403 | `change_time`, we introduced a quarantine process that is dependent on a
404 | dirac delta function \(\phi_t\in [0,1]\). In other words, only at time
405 | points defined by `change_time`, we have certain porportions of the
406 | at-risk (susceptible) subjects moved to the quarantine stage. The
407 | difference of this model than the previous time-varying transmission one
408 | is that we do not allow the tranmission rate to change, but only let the
409 | proportion of susceptible subjects decrease. 
411 |
412 | 
413 |
414 | ``` r
415 | set.seed(20192020)
416 | # Cumulative number of infected cases
417 | NI_complete <- c(
418 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444,
419 | 549, 729, 1052, 1423, 2714, 3554, 4903, 5806,
420 | 7153, 9074, 11177, 13522, 16678, 19665, 22112,
421 | 24953, 27100, 29631, 31728, 33366)
422 | # Cumulative number of removed cases
423 | RI_complete <- c(
424 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55,
425 | 71, 94, 121, 152, 213, 252, 345, 417, 561,
426 | 650, 811, 1017, 1261, 1485, 1917, 2260,
427 | 2725, 3284, 3754)
428 | N <- 58.5e6
429 | R <- RI_complete / N
430 | Y <- NI_complete / N - R #Jan13->Feb 11
431 |
432 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
433 | phi0 <- c(0.1, 0.4, 0.4)
434 | res.q <- qh.eSIR(Y,
435 | R,
436 | begin_str = "01/13/2020",
437 | phi0 = phi0,
438 | change_time = change_time,
439 | casename = "Hubei_q",
440 | save_files = TRUE,
441 | save_mcmc = FALSE,
442 | save_plot_data = FALSE,
443 | M = 5e3,
444 | nburnin = 2e3)
445 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
446 | #> Running for qh.eSIR
447 | #> Compiling model graph
448 | #> Resolving undeclared variables
449 | #> Allocating nodes
450 | #> Graph information:
451 | #> Observed stochastic nodes: 60
452 | #> Unobserved stochastic nodes: 36
453 | #> Total graph size: 2736
454 | #>
455 | #> Initializing model
456 | res.q$plot_infection
457 | ```
458 |
459 | 
460 |
461 | You will obtain the following plot in addition to the traceplots and
462 | summary table if you set `save_file=T` in `qh.eSIR`. The blue vertical
463 | line denotes the beginning date, and the other three gray lines denote
464 | the three change points.
465 |
466 | 
467 |
468 | ## Model 3 using `eSAIR`: SIR with time-varying subset of population immunized with antibody positivity
469 |
470 | To address the under-reporting issue associated with the available
471 | public databases and to build the self-immunization into the infection
472 | dynamics, we then further extend the previous eSIR model to an eSAIR
473 | model by adding an antibody (A) compartment. As is shown in the bottom
474 | thread of the following figure, this A compartment accounts for the
475 | probability of being self-immunized with antibodies to COVID-19, denoted
476 | by \(\theta_t^A\); see equation as follows too, where \(\alpha(t)\) is a
477 | function describing the proportion of people moving from the susceptible
478 | compartment to the antibody compartment over time. Compartment A helps
479 | circumvent limitations of data collection, especially embracing
480 | individuals who were infected but self-cured at home with no
481 | confirmation by viral RT-PCR diagnostic tests. This new eSAIR model
482 | characterizes the underlying population-level dynamics of the pandemic.
483 | The following system of ordinary differential equations defines
484 | collectively the continuous-time dynamics for the eSAIR model, which
485 | governs the law of movements among four compartments of Susceptible,
486 | Self-immunized, Infected and Removed.
487 |
488 | 
489 |
490 | 
491 |
492 | In the example below, we implemented this function onto New York state
493 | data assuming that by April 29, 20% of the population have been
494 | self-immunized with antibody positivity.
495 |
496 | ``` r
497 | # Cumulative number of infected cases
498 | NI_complete <- c(
499 | 1, 2, 11, 23, 31, 76, 106, 142, 150, 220, 327,
500 | 421, 613, 615, 967, 1578, 3038, 5704, 8403,
501 | 11727, 15800, 20884, 25681, 30841, 37877,
502 | 44876, 52410, 59648, 66663, 75833, 83948,
503 | 92506, 102987, 113833, 123160, 131815,
504 | 139875, 151061, 161779, 172348, 181026,
505 | 189033, 195749, 203020, 214454, 223691,
506 | 230597, 237474, 243382, 248416, 253519,
507 | 258222, 263460, 271590, 282143, 288045,
508 | 291996, 295106, 299691, 304372, 308314)
509 | # Cumulative number of removed cases
510 | RI_complete <- c(
511 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
512 | 20, 26, 38, 52, 200, 311, 468, 662,
513 | 893, 1144, 1547, 2144, 2931, 3900,
514 | 5133, 6201, 7657, 9483, 11536,
515 | 13915, 16276, 18781, 21110, 23424,
516 | 26469, 29784, 32899, 35785, 37730,
517 | 39207, 40703, 42164, 43488, 44723,
518 | 45887, 47473, 47686, 48769, 49572,
519 | 50221, 52161, 52917, 54115, 54613,
520 | 55473, 55816, 56809, 57265, 58525)
521 | N <- 8.399e6
522 | R <- RI_complete / N
523 | Y <- NI_complete / N - R
524 |
525 | change_time <- c("04/29/2020")
526 | alpha0 <- c(0.2) # 20% of the susceptible population were found immunized
527 | res.antibody <- eSAIR(Y,
528 | R,
529 | begin_str = "03/01/2020",
530 | alpha0 = alpha0,
531 | change_time = change_time,
532 | casename = "New_York_antibody",
533 | save_files = F,
534 | save_mcmc = F,
535 | M=5e2,
536 | nburnin = 2e2)
537 | #> The follow-up is from 03/01/20 to 09/16/20 and the last observed date is 04/30/20.
538 | #> Running for eSAIR
539 | #> Compiling model graph
540 | #> Resolving undeclared variables
541 | #> Allocating nodes
542 | #> Graph information:
543 | #> Observed stochastic nodes: 122
544 | #> Unobserved stochastic nodes: 67
545 | #> Total graph size: 5123
546 | #>
547 | #> Initializing model
548 | #>
549 | #> NOTE: Stopping adaptation
550 | res.antibody$plot_infection
551 | ```
552 |
553 | 
554 |
555 | ## Outputs and summary table
556 |
557 | To save all the plots (including trace plots) and summary tables, please
558 | set `save_files=T`, and if possible, provide a location by setting
559 | `file_add="YOUR/FAVORITE/FOLDER"`. Otherwise, the traceplots and other
560 | intermediate plots will not be saved, but you can still retrieve the
561 | forecast plots and summary table based on the return list, e.g., using
562 | `res.step$forecast_infection` and `res.step$out_table`. Moreover, if you
563 | are interested in plotting the figures on your own, you may set
564 | `save_mcmc=T` so that all the MCMC draws will be saved in a `.RData`
565 | file too.
566 |
567 | For details, please explore our package directly. We have `.rd` files
568 | established, please use `help(tvt.eSIR)` or `?qh.eSIR` to find them.
569 |
570 | ## Acknowledgements
571 |
572 | This package is created and maintained by [Lili
573 | Wang](lilywang@umich.edu), contributed by [Fei
574 | Wang](https://github.com/feiwsteven), [Lu
575 | Tang](https://github.com/ClumsyBear), and [Paul
576 | Egeler](https://github.com/pegeler). We also thank [Kangping
577 | Yang](kangpiny@umich.edu) for helping us collect the recovery data from
578 | the web page.
579 |
580 | ## References
581 |
582 | 1. Wang, L., Zhou, Y., He, J., Zhu, B., Wang, F., Tang, L., ... & Song, P. X. (2020). An epidemiological forecast model and software assessing interventions on the COVID-19 epidemic in China. Journal of Data Science, 18(3), 409-432. [link](https://www.airitilibrary.com/Publication/alDetailedMesh?DocID=16838602-202007-202008240002-202008240002-409-432&sourceBrowseType=0)
583 |
584 | 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.
585 |
586 | 3. Gelman, A., & Rubin, D. B. (1992). Inference from iterative simulation using multiple sequences. Statistical science, 7(4), 457-472.
587 |
588 | -----
589 |
590 | Shield: [](http://creativecommons.org/licenses/by/4.0/)
591 |
592 | This work is licensed under a [Creative Commons Attribution 4.0
593 | International License](http://creativecommons.org/licenses/by/4.0/).
594 |
595 | [](http://creativecommons.org/licenses/by/4.0/)
596 |
--------------------------------------------------------------------------------
/README_cn.md:
--------------------------------------------------------------------------------
1 | R包eSIR:扩展的状态空间SIR流行病学模型
2 | ================
3 | [Song Lab](http://www.umich.edu/~songlab/)
4 | 2020-03-05
5 |
6 | 英文版本: [English](https://github.com/lilywang1988/eSIR/blob/master/README.md)
7 |
8 | 目的
9 | -------
10 |
11 | 起源于湖北省省会武汉市的新型冠状病毒病(又名COVID-19)的爆发迅速蔓延,并影响了中国许多城市以及世界许多国家。中国政府已经实施了非常严格的检疫和检查,以防止COVID-19的传播恶化。尽管在媒体上已经发布了关于湖北省内外流行病拐点的各种形式的预测,但是没有一个预测模型明确说明了时变隔离协议。通过将医学隔离形式(家庭隔离和住院)纳入基本的传染病动态系统,我们扩展了传染病的经典SIR模型。使用针对每日感染和住院发病率的状态空间模型以及MCMC算法,我们评估了隔离方案对限制湖北省和中国其他地区传播的COVID-19的有效性。在给定的隔离协议下,可以从扩展的SIR获取预测的转折点及其可信带。 R软件包也向感兴趣的用户公开提供。
12 |
13 | 标准SIR模型包含三个组件:易感,受感染和已删除(包括恢复和死亡)。在以下各节中,我们将在包中介绍其他扩展状态空间SIR模型及其实现。 **以下提供的结果基于相对较短的链。** 根据我们的经验,此设置 (`M=5e3` and `nburnin=2e3`) 应在趋势和转折点估计方面提供可接受的结果, 参数及其可信区间的估计值可能不准确。 因此,如果可能,我们建议使用“ M = 5e5”和“ nburnin = 2e5”来通过[`rjags`](https://cran.r-project.org/web/packages/rjags/index.html)以获得稳定的MCMC链.
14 |
15 | 
16 |
17 | 
18 |
19 | 
20 |
21 | 
22 |
23 | 
24 |
25 | 安装准备
26 | -----------
27 | [直接下载并安装](https://github.com/lilywang1988/eSIR/blob/master/install_binary)
28 |
29 | 如果要从Github安装和使用此R软件包,您需要首先安装R软件包`devtools`。 请取消注释代码以安装它们。 eSIR依赖于其他三个软件包:rjags(JAGS库的接口),chron和gtools,如果尚未安装,它们可以与eSIR一起安装。如果尚未安装JAGS-4.x.y.exe,可能会发生错误。(for any x >= 0, y >=0). **Windows** 用户可以从以下位置下载并安装JAGS [here](http://www.sourceforge.net/projects/mcmc-jags/files). **Mac** 用户可以按照以下步骤操作 [casallas/8411082](https://gist.github.com/casallas/8411082).
30 |
31 |
32 | ``` r
33 | # install.packages("devtools")
34 | # library(devtools)
35 | # install_github("lilywang1988/eSIR")
36 | library(eSIR)
37 | ```
38 |
39 | 我们的数据来自于丁香医生 [dxy.com](https://mama.dxy.com/outbreak/daily-of-nationwide-new?index=20200206&locationIds=999&from=todh5). 其他我们知道的数据源包括 [GuangchuangYu/nCov2019](https://github.com/GuangchuangYu/nCov2019) 和 [qingyuanzhao/2019-nCov-Data](https://github.com/qingyuanzhao/2019-nCov-Data).
40 |
41 | ``` r
42 | # Data of COVID-19 can be found in the following R packages:
43 | # install_github("GuangchuangYu/nCov2019")
44 | #library(nCov2019)
45 | # install_github("qingyuanzhao/2019-nCov-Data")
46 | #library(2019-nCov-Data)
47 | ```
48 | 在Ubuntu(18.04)Linux中,请先将R更新到一个版本 >= 3.6 的版本. 您可能还需要在通过`install.packages("devtools")`安装 devtools 之前安装jags软件包,方法是 `sudo apt-get install jags`。
49 |
50 | 模型1 `tvt.eSIR()`: 具有时变传输速率的SIR模型
51 | -----------------------------------------------------------------------------
52 |
53 | 我们引入一个可以影响 *β* 的时间函数 *π*(*t*)∈\[0, 1\],我们可以描述一系列时变变化,这些变化是由外部变化(例如政府政策,保护措施和环境变化)或内部变化(例如病原体的变异和进化)引起的。
54 |
55 | 该函数可以是逐步的或指数的:
56 |
57 | 
58 |
59 | 
60 |
61 | ``` r
62 | set.seed(20192020)
63 | library(eSIR)
64 | #> Loading required package: rjags
65 | #> Loading required package: coda
66 | #> Linked to JAGS 4.3.0
67 | #> Loaded modules: basemod,bugs
68 | #> Loading required package: scales
69 | #> Loading required package: ggplot2
70 | #> Loading required package: chron
71 | #> Loading required package: gtools
72 | #> Loading required package: data.table
73 | # Hubei province data Jan13 -> Feb 11
74 | # cumulative number of infected
75 | NI_complete <- c( 41,41,41,45,62,131,200,270,375,444,549, 729,
76 | 1052,1423,2714,3554,4903,5806,7153,9074,11177,
77 | 13522,16678,19665,22112,24953,27100,29631,31728,33366)
78 | RI_complete <- c(1,1,7,10,14,20,25,31,34,45,55,71,94,121,152,213,
79 | 252,345,417,561,650,811,1017,1261,1485,1917,2260,
80 | 2725,3284,3754)
81 | N=58.5e6
82 | R <- RI_complete/N
83 | Y <- NI_complete/N- R #Jan13->Feb 11
84 | ### Step function of pi(t)
85 | change_time <- c("01/23/2020","02/04/2020","02/08/2020")
86 | pi0<- c(1.0,0.9,0.5,0.1)
87 | res.step <-tvt.eSIR(Y,R,begin_str="01/13/2020",death_in_R = 0.4,T_fin=200,
88 | pi0=pi0,change_time=change_time,dic=T,casename="Hubei_step",
89 | save_files = T, save_mcmc=F,save_plot_data = F,M=5e3,nburnin = 2e3)
90 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
91 | #> Running for step-function pi(t)
92 | #> Compiling model graph
93 | #> Resolving undeclared variables
94 | #> Allocating nodes
95 | #> Graph information:
96 | #> Observed stochastic nodes: 60
97 | #> Unobserved stochastic nodes: 37
98 | #> Total graph size: 1873
99 | #>
100 | #> Initializing model
101 | res.step$plot_infection
102 | ```
103 |
104 | 
105 |
106 | ``` r
107 | res.step$plot_removed
108 | ```
109 |
110 | 
111 |
112 | ``` r
113 | res.step$spaghetti_plot
114 | ```
115 |
116 | 
117 |
118 | ``` r
119 | res.step$dic_val
120 | #> Mean deviance: -1262
121 | #> penalty 37.98
122 | #> Penalized deviance: -1224
123 |
124 | ### continuous exponential function of pi(t)
125 | res.exp <- tvt.eSIR(Y,R,begin_str="01/13/2020",death_in_R = 0.4,
126 | T_fin=200,exponential=TRUE,dic=F,lambda0=0.05,
127 | casename="Hubei_exp",save_files = F,save_mcmc=F,
128 | save_plot_data = F,M=5e3,nburnin = 2e3)
129 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
130 | #> Running for exponential-function pi(t)
131 | #> Compiling model graph
132 | #> Resolving undeclared variables
133 | #> Allocating nodes
134 | #> Graph information:
135 | #> Observed stochastic nodes: 60
136 | #> Unobserved stochastic nodes: 37
137 | #> Total graph size: 1873
138 | #>
139 | #> Initializing model
140 | res.exp$plot_infection
141 | ```
142 |
143 | 
144 |
145 | ``` r
146 | res.exp$spaghetti_plot
147 | ```
148 |
149 | 
150 |
151 | ``` r
152 | #res.exp$plot_removed
153 |
154 | ### without pi(t), the standard state-space SIR model without intervention
155 | 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,
156 | M=5e3,nburnin = 2e3)
157 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
158 | #> Running without pi(t)
159 | #> Compiling model graph
160 | #> Resolving undeclared variables
161 | #> Allocating nodes
162 | #> Graph information:
163 | #> Observed stochastic nodes: 60
164 | #> Unobserved stochastic nodes: 37
165 | #> Total graph size: 1873
166 | #>
167 | #> Initializing model
168 | res.nopi$plot_infection
169 | ```
170 |
171 | 
172 |
173 | ``` r
174 | res.nopi$spaghetti_plot
175 | ```
176 |
177 | 
178 |
179 | ``` r
180 | #res.nopi$plot_removed
181 | ```
182 |
183 | 模型2 `qh.eSIR()`: 具有随时间变化的隔离的SIR,遵循Dirac Delta函数
184 | -------------------------------------------------------------------------------------------------
185 | 通过引入向量`phi`及其对应的变化点`change_time`,我们引入了依赖于Dirac delta函数 *ϕ**t* ∈ \[0, 1\]。换句话说,仅在`change_time`定义的时间点,我们才将某些风险(易感)对象的某些部分移至隔离阶段。 该模型与以前的时变传输模型的不同之处在于,我们不允许传输率发生变化,而只是让易感对象的比例降低。
186 |
187 | 
188 |
189 | 
190 |
191 | ``` r
192 | set.seed(20192020)
193 | NI_complete <- c( 41,41,41,45,62,131,200,270,375,444,549, 729,
194 | 1052,1423,2714,3554,4903,5806,7153,9074,11177,
195 | 13522,16678,19665,22112,24953,27100,29631,31728,33366)
196 | RI_complete <- c(1,1,7,10,14,20,25,31,34,45,55,71,94,121,152,213,
197 | 252,345,417,561,650,811,1017,1261,1485,1917,2260,
198 | 2725,3284,3754)
199 | N=58.5e6
200 | R <- RI_complete/N
201 | Y <- NI_complete/N- R #Jan13->Feb 11
202 |
203 | change_time <- c("01/23/2020","02/04/2020","02/08/2020")
204 | phi0 <- c(0.1,0.4,0.4)
205 | res.q <- qh.eSIR (Y,R,begin_str="01/13/2020",death_in_R = 0.4,
206 | phi0=phi0,change_time=change_time,casename="Hubei_q",
207 | save_files = T,save_mcmc = F,save_plot_data = F,
208 | M=5e3,nburnin = 2e3)
209 | #> The follow-up is from 01/13/20 to 07/30/20 and the last observed date is 02/11/20.
210 | #> Running for qh.eSIR
211 | #> Compiling model graph
212 | #> Resolving undeclared variables
213 | #> Allocating nodes
214 | #> Graph information:
215 | #> Observed stochastic nodes: 60
216 | #> Unobserved stochastic nodes: 37
217 | #> Total graph size: 2676
218 | #>
219 | #> Initializing model
220 | res.q$plot_infection
221 | ```
222 |
223 | 
224 |
225 | ``` r
226 | #res.q$plot_removed
227 |
228 | #res.noq <- qh.eSIR (Y,R,begin_str="01/13/2020",death_in_R = 0.4,
229 | # T_fin=200,casename="Hubei_noq",
230 | # M=5e3,nburnin = 2e3)
231 | #res.noq$plot_infection
232 | ```
233 | 如果在`qh.eSIR`中设置`save_file = T`,除了traceplots和summary表之外,还将获得以下图表。 蓝色垂直线表示开始日期,而其他三个灰色线表示三个更改点。
234 |
235 | 
236 |
237 | 结果和汇总表
238 | -------------------------
239 | 要保存所有图(包括轨迹图)和汇总表,请设置`save_files = T`,并在可能的情况下通过设置`file_add="YOUR/FAVORITE/FOLDER"`提供位置。否则,轨迹图和其他中间图将不会保存,但是您仍然可以使用`res.step$forecast_infection`和`res.step$out_table`来找到它们。 此外,如果您有兴趣自己绘制图形,可以设置`save_mcmc = T`,以便所有MCMC图形也都保存在`.RData`文件中。
240 |
241 | 有关详细信息,请直接浏览我们的软件包。我们有准备完整的`.rd`文件,请使用`?(tvt.eSIR)`或`help(qh.eSIR)`查找它们。
242 |
243 | 参考文献
244 | ----------
245 |
246 | 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.
247 |
248 | 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.
249 |
250 | 3. Mkhatshwa, T., & Mummert, A. (2010). Modeling super-spreading events for infectious diseases: case study SARS. arXiv preprint arXiv:1007.0908.
251 |
--------------------------------------------------------------------------------
/data/USA_state_N.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/data/USA_state_N.rda
--------------------------------------------------------------------------------
/data/confirmed.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/data/confirmed.rda
--------------------------------------------------------------------------------
/data/death.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/data/death.rda
--------------------------------------------------------------------------------
/data/recovered.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/data/recovered.rda
--------------------------------------------------------------------------------
/eSIR.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: Default
4 | SaveWorkspace: Default
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 2
10 | Encoding: UTF-8
11 |
12 | RnwWeave: Sweave
13 | LaTeX: pdfLaTeX
14 |
15 | AutoAppendNewline: Yes
16 | StripTrailingWhitespace: Yes
17 |
18 | BuildType: Package
19 | PackageUseDevtools: Yes
20 | PackageInstallArgs: --no-multiarch --with-keep.source
21 | PackageRoxygenize: rd,collate,namespace
22 |
--------------------------------------------------------------------------------
/eSIR.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/eSIR.pdf
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.2.5.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.2.5.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.2.6.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.2.6.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.2.7.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.2.7.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.2.8.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.2.8.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.0.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.0.tar.gz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.0.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.0.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.1.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.1.tar.gz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.1.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.1.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.2.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.2.tar.gz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.2.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.2.tgz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.3.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.3.tar.gz
--------------------------------------------------------------------------------
/install_pkg/eSIR_0.3.3.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/install_pkg/eSIR_0.3.3.tgz
--------------------------------------------------------------------------------
/man/eSAIR.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/eSAIR.R
3 | \name{eSAIR}
4 | \alias{eSAIR}
5 | \title{Extended state-space SIR with a subset of the population showing antibody positivity}
6 | \usage{
7 | eSAIR(
8 | Y,
9 | R,
10 | alpha0 = NULL,
11 | change_time = NULL,
12 | begin_str = "01/13/2020",
13 | T_fin = 200,
14 | nchain = 4,
15 | nadapt = 10000,
16 | M = 500,
17 | thn = 10,
18 | nburnin = 200,
19 | dic = FALSE,
20 | death_in_R = 0.02,
21 | casename = "eSAIR",
22 | beta0 = 0.2586,
23 | gamma0 = 0.0821,
24 | R0 = beta0/gamma0,
25 | gamma0_sd = 0.1,
26 | R0_sd = 1,
27 | file_add = character(0),
28 | add_death = FALSE,
29 | save_files = FALSE,
30 | save_mcmc = FALSE,
31 | save_plot_data = FALSE,
32 | eps = 1e-10
33 | )
34 | }
35 | \arguments{
36 | \item{Y}{the time series of daily observed infected compartment proportions.}
37 |
38 | \item{R}{the time series of daily observed removed compartment proportions, including death and recovered.}
39 |
40 | \item{alpha0}{a vector of values of the dirac delta function \eqn{\alpha_t}. Each entry denotes the proportion that will be immunized at each change time point. Note that all the entries lie between 0 and 1, its default is \code{NULL}.}
41 |
42 | \item{change_time}{the change points over time corresponding to \code{alpha0}, to formulate the dirac delta function \eqn{\alpha_t}; its defalt value is \code{NULL}.}
43 |
44 | \item{begin_str}{the character of starting time, the default is "01/13/2020".}
45 |
46 | \item{T_fin}{the end of follow-up time after the beginning date \code{begin_str}, the default is 200.}
47 |
48 | \item{nchain}{the number of MCMC chains generated by \code{\link[rjags]{rjags}}, the default is 4.}
49 |
50 | \item{nadapt}{the iteration number of adaptation in the MCMC. We recommend using at least the default value 1e4 to obtained fully adapted chains.}
51 |
52 | \item{M}{the number of draws in each chain, with no thinning. The default is M=5e2 but suggest using 5e5.}
53 |
54 | \item{thn}{the thinning interval between mixing. The total number of draws thus would become \code{round(M/thn)*nchain}. The default is 10.}
55 |
56 | \item{nburnin}{the burn-in period. The default is 2e2 but suggest 2e5.}
57 |
58 | \item{dic}{logical, whether compute the DIC (deviance information criterion) for model selection.}
59 |
60 | \item{death_in_R}{the numeric value of average of cumulative deaths in the removed compartments. The default is 0.4 within Hubei and 0.02 outside Hubei.}
61 |
62 | \item{casename}{the string of the job's name. The default is "eSAIR".}
63 |
64 | \item{beta0}{the hyperparameter of average transmission rate, the default is the one estimated from the SARS first-month outbreak (0.2586).}
65 |
66 | \item{gamma0}{the hyperparameter of average removed rate, the default is the one estimated from the SARS first-month outbreak (0.0821).}
67 |
68 | \item{R0}{the hyperparameter of the mean reproduction number R0. The default is thus the ratio of \code{beta0/gamma0}, which can be specified directly.}
69 |
70 | \item{gamma0_sd}{the standard deviation for the prior distrbution of the removed rate \eqn{\gamma}, the default is 0.1.}
71 |
72 | \item{R0_sd}{the standard deviation for the prior disbution of R0, the default is 1.}
73 |
74 | \item{file_add}{the string to denote the location of saving output files and tables.}
75 |
76 | \item{add_death}{logical, whether add the approximate death curve to the plot, default is false.}
77 |
78 | \item{save_files}{logical, whether to save plots to file.}
79 |
80 | \item{save_mcmc}{logical, whether save (\code{TRUE}) all the MCMC outputs or not (\code{FALSE}).The output file will be an \code{.RData} file named by the \eqn{casename}. We include arrays of prevalence values of the three compartments with their matrices of posterior draws up to the last date of the collected data as \code{theta_p[,,1]} and afterwards as \code{theta_pp[,,1]} for \eqn{\theta_t^S}, \code{theta_p[,,2]} and \code{theta_pp[,,2]} for \eqn{\theta_t^I}, and \code{theta_p[,,3]} and \code{theta_pp[,,3]} for \eqn{\theta_t^R}. The posterior draws of the prevalence process of the antibody-immunized compartment can be obtained via \code{thetaA_p} and \code{thetaA_pp}. Moreover, the input and predicted proportions \code{Y}, \code{Y_pp}, \code{R} and \code{R_pp} can also be retrieved. The prevalence and prediceted proportion matrices have rows for MCMC replicates, and columns for days. The MCMC posterior draws of other parameters including \code{beta}, \code{gamma}, \code{R0}, and variance controllers \code{k_p}, \code{lambdaY_p}, \code{lambdaR_p} are also available.}
81 |
82 | \item{save_plot_data}{logical, whether save the plotting data or not.}
83 |
84 | \item{eps}{a non-zero controller so that all the input \code{Y} and \code{R} values would be bounded above 0 (at least \code{eps}). Its default value is 1e-10}
85 | }
86 | \value{
87 | \item{casename}{the predefined \code{casename}.}
88 | \item{incidence_mean}{mean cumulative incidence, the mean prevalence of cumulative confirmed cases at the end of the study.}
89 | \item{incidence_ci}{2.5\%, 50\%, and 97.5\% quantiles of the incidences.}
90 | \item{out_table}{summary tables including the posterior mean of the prevalance processes of the 3 states compartments (\eqn{\theta_t^S,\theta_t^I,\theta_t^R,\theta_t^H}) at last date of data collected ((\eqn{t^\prime}) decided by the lengths of your input data \code{Y} and \code{R}), and their respective credible inctervals (ci); the respective means and ci's of the reporduction number (R0), removed rate (\eqn{\gamma}), transmission rate (\eqn{\beta}).}
91 | \item{plot_infection}{plot of summarizing and forecasting for the infection compartment, in which the vertial blue line denotes the last date of data collected (\eqn{t^\prime}), the vertial darkgray line denotes the deacceleration point (first turning point) that the posterior mean first-derivative of infection prevalence \eqn{\dot{\theta}_t^I} achieves the maximum, the vertical purple line denotes the second turning point that the posterior mean first-derivative infection proportion \eqn{\dot{\theta}_t^I} equals zero, the darkgray line denotes the posterior mean of the infection prevalence \eqn{\theta_t^I} and the red line denotes its posterior median. }
92 | \item{plot_removed}{plot of summarizing and forecasting for the removed compartment with lines similar to those in the \code{plot_infection}. The vertical lines are identical, but the horizontal mean and median correspond to the posterior mean and median of the removed process \eqn{\theta_t^R}. An additional line indicates the estimated death prevalence from the input \code{death_in_R}.}
93 | \item{spaghetti_plot}{20 randomly selected MCMC draws of the first-order derivative of the posterior prevalence of infection, namely \eqn{\dot{\theta}_t^I}. The black curve is the posterior mean of the derivative, and the vertical lines mark times of turning points corresponding respectively to those shown in \code{plot_infection} and \code{plot_removed}. Moreover, the 95\% credible intervals of these turning points are also highlighted by semi-transparent rectangles. }
94 | \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
95 | \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
96 |
97 | \item{first_tp_ci}{fwith \code{first_tp_mean}, it reports the corresponding credible interval and median.}
98 | \item{second_tp_mean}{the date t at which \eqn{\theta_t^I=0}, calculated as the average of the stationary points of all of posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "pruple" lines in the plots of \code{plot_infection} and \code{plot_removed}. The latter indicate stationary t at which the first-order derivative of the averaged posterior of \eqn{\theta_t^I} equals zero.}
99 | \item{second_tp_ci}{with \code{second_tp_mean}, it reports the corresponding credible interval and median.}
100 | \item{dic_val}{the output of \code{dic.samples()} in \code{\link[rjags]{dic.samples}}, computing deviance information criterion for model comparison.}
101 | \item{gelman_diag_list}{ Since version 0.3.3, we incorporated Gelman And Rubin's Convergence Diagnostic using \code{\link[coda]{gelman.diag}}. We included both the statistics and their upper C.I. limits. Values substantially above 1 indicate lack of convergence. Error messages would be printed as they are. This would be only valid for multiple chains (e.g. nchain > 1). Note that for time dependent processes, we only compute the convergence of the last observation data (\code{T_prime}), though it shows to be \code{T_prime+1}, which is due to the day 0 for initialization.}
102 | }
103 | \description{
104 | In this function we allow it to characterize time-varying immunization among a subset of the population that have been tested positive in an antibody assessment. We expanded the SIR model by adding a time-varying antibody-positive proportion \eqn{\alpha_t}.
105 | }
106 | \examples{
107 | \dontrun{
108 | NI_complete <- c(
109 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
110 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
111 | 13522, 16678, 19665, 22112, 24953, 27100, 29631, 31728, 33366
112 | )
113 | RI_complete <- c(
114 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94,
115 | 121, 152, 213, 252, 345, 417, 561, 650, 811, 1017,
116 | 1261, 1485, 1917, 2260, 2725, 3284, 3754
117 | )
118 | N <- 58.5e6
119 | R <- RI_complete / N
120 | Y <- NI_complete / N - R # Jan13->Feb 11
121 | change_time <- c("02/08/2020")
122 | alpha0 <- c(0.2) # 20\% of the susceptible population were found immunized
123 | res.antibody <- eSAIR(Y, R,
124 | begin_str = "01/13/2020", death_in_R = 0.4,
125 | alpha0 = alpha0, change_time = change_time,
126 | casename = "Hubei_antibody", save_files = T, save_mcmc = F,
127 | M = 5e2, nburnin = 2e2
128 | )
129 | res.antibody$plot_infection
130 | }
131 |
132 | change_time <- c("01/16/2020")
133 | alpha0 <- c(0.2)
134 | NI_complete2 <- c(41, 45)
135 | RI_complete2 <- c(1, 1)
136 | N2 <- 1E3
137 | res3 <- eSAIR(
138 | RI_complete2 / N2,
139 | NI_complete2 / N2,
140 | begin_str = "01/13/2020",
141 | T_fin = 4,
142 | alpha0 = alpha0,
143 | change_time = change_time,
144 | dic = FALSE,
145 | casename = "Hubei_q",
146 | save_files = FALSE,
147 | save_mcmc = FALSE,
148 | save_plot_data = FALSE,
149 | M = 50,
150 | nburnin = 1
151 | )
152 | closeAllConnections()
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/man/figures/BDSSM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/BDSSM.png
--------------------------------------------------------------------------------
/man/figures/Hubei_qthetaQ_plot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/Hubei_qthetaQ_plot.png
--------------------------------------------------------------------------------
/man/figures/README-model 3-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model 3-1.png
--------------------------------------------------------------------------------
/man/figures/README-model1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-1.png
--------------------------------------------------------------------------------
/man/figures/README-model1-10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-10.png
--------------------------------------------------------------------------------
/man/figures/README-model1-11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-11.png
--------------------------------------------------------------------------------
/man/figures/README-model1-12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-12.png
--------------------------------------------------------------------------------
/man/figures/README-model1-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-2.png
--------------------------------------------------------------------------------
/man/figures/README-model1-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-3.png
--------------------------------------------------------------------------------
/man/figures/README-model1-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-4.png
--------------------------------------------------------------------------------
/man/figures/README-model1-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-5.png
--------------------------------------------------------------------------------
/man/figures/README-model1-6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-6.png
--------------------------------------------------------------------------------
/man/figures/README-model1-7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-7.png
--------------------------------------------------------------------------------
/man/figures/README-model1-8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-8.png
--------------------------------------------------------------------------------
/man/figures/README-model1-9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model1-9.png
--------------------------------------------------------------------------------
/man/figures/README-model2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model2-1.png
--------------------------------------------------------------------------------
/man/figures/README-model2-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/README-model2-2.png
--------------------------------------------------------------------------------
/man/figures/RK4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/RK4.png
--------------------------------------------------------------------------------
/man/figures/SAIR_ODE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/SAIR_ODE.png
--------------------------------------------------------------------------------
/man/figures/algorithm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/algorithm.png
--------------------------------------------------------------------------------
/man/figures/eSAIR_compartment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/eSAIR_compartment.png
--------------------------------------------------------------------------------
/man/figures/model0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/model0.png
--------------------------------------------------------------------------------
/man/figures/model1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/model1.png
--------------------------------------------------------------------------------
/man/figures/model2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/model2.png
--------------------------------------------------------------------------------
/man/figures/phi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/phi.png
--------------------------------------------------------------------------------
/man/figures/phi_functions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/phi_functions.png
--------------------------------------------------------------------------------
/man/figures/pi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/pi.png
--------------------------------------------------------------------------------
/man/figures/pi_exp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/pi_exp.png
--------------------------------------------------------------------------------
/man/figures/pi_functions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/pi_functions.png
--------------------------------------------------------------------------------
/man/figures/priors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/man/figures/priors.png
--------------------------------------------------------------------------------
/man/qh.eSIR.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/qh.eSIR.R
3 | \name{qh.eSIR}
4 | \alias{qh.eSIR}
5 | \title{Extended state-space SIR with quarantine}
6 | \usage{
7 | qh.eSIR(
8 | Y,
9 | R,
10 | phi0 = NULL,
11 | change_time = NULL,
12 | begin_str = "01/13/2020",
13 | T_fin = 200,
14 | nchain = 4,
15 | nadapt = 10000,
16 | M = 500,
17 | thn = 10,
18 | nburnin = 200,
19 | dic = FALSE,
20 | death_in_R = 0.02,
21 | casename = "qh.eSIR",
22 | beta0 = 0.2586,
23 | gamma0 = 0.0821,
24 | R0 = beta0/gamma0,
25 | gamma0_sd = 0.1,
26 | R0_sd = 1,
27 | file_add = character(0),
28 | add_death = FALSE,
29 | save_files = FALSE,
30 | save_mcmc = FALSE,
31 | save_plot_data = FALSE,
32 | eps = 1e-10
33 | )
34 | }
35 | \arguments{
36 | \item{Y}{the time series of daily observed infected compartment proportions.}
37 |
38 | \item{R}{the time series of daily observed removed compartment proportions, including death and recovered.}
39 |
40 | \item{phi0}{a vector of values of the dirac delta function \eqn{\phi_t}. Each entry denotes the proportion that will be qurantined at each change time point. Note that all the entries lie between 0 and 1, its default is \code{NULL}.}
41 |
42 | \item{change_time}{the change points over time corresponding to \code{phi0}, to formulate the dirac delta function \eqn{\phi_t}; its defalt value is \code{NULL}.}
43 |
44 | \item{begin_str}{the character of starting time, the default is "01/13/2020".}
45 |
46 | \item{T_fin}{the end of follow-up time after the beginning date \code{begin_str}, the default is 200.}
47 |
48 | \item{nchain}{the number of MCMC chains generated by \code{\link[rjags]{rjags}}, the default is 4.}
49 |
50 | \item{nadapt}{the iteration number of adaptation in the MCMC. We recommend using at least the default value 1e4 to obtained fully adapted chains.}
51 |
52 | \item{M}{the number of draws in each chain, with no thinning. The default is M=5e2 but suggest using 5e5.}
53 |
54 | \item{thn}{the thinning interval between mixing. The total number of draws thus would become \code{round(M/thn)*nchain}. The default is 10.}
55 |
56 | \item{nburnin}{the burn-in period. The default is 2e2 but suggest 2e5.}
57 |
58 | \item{dic}{logical, whether compute the DIC (deviance information criterion) for model selection.}
59 |
60 | \item{death_in_R}{the numeric value of average of cumulative deaths in the removed compartments. The default is 0.4 within Hubei and 0.02 outside Hubei.}
61 |
62 | \item{casename}{the string of the job's name. The default is "qh.eSIR".}
63 |
64 | \item{beta0}{the hyperparameter of average transmission rate, the default is the one estimated from the SARS first-month outbreak (0.2586).}
65 |
66 | \item{gamma0}{the hyperparameter of average removed rate, the default is the one estimated from the SARS first-month outbreak (0.0821).}
67 |
68 | \item{R0}{the hyperparameter of the mean reproduction number R0. The default is thus the ratio of \code{beta0/gamma0}, which can be specified directly.}
69 |
70 | \item{gamma0_sd}{the standard deviation for the prior distrbution of the removed rate \eqn{\gamma}, the default is 0.1.}
71 |
72 | \item{R0_sd}{the standard deviation for the prior disbution of R0, the default is 1.}
73 |
74 | \item{file_add}{the string to denote the location of saving output files and tables.}
75 |
76 | \item{add_death}{logical, whether add the approximate death curve to the plot, default is false.}
77 |
78 | \item{save_files}{logical, whether to save plots to file.}
79 |
80 | \item{save_mcmc}{logical, whether save (\code{TRUE}) all the MCMC outputs or not (\code{FALSE}).The output file will be an \code{.RData} file named by the \eqn{casename}. We include arrays of prevalence values of the three compartments with their matrices of posterior draws up to the last date of the collected data as \code{theta_p[,,1]} and afterwards as \code{theta_pp[,,1]} for \eqn{\theta_t^S}, \code{theta_p[,,2]} and \code{theta_pp[,,2]} for \eqn{\theta_t^I}, and \code{theta_p[,,3]} and \code{theta_pp[,,3]} for \eqn{\theta_t^R}. The posterior draws of the prevalence process of the quarantine compartment can be obtained via \code{thetaQ_p} and \code{thetaQ_pp}. Moreover, the input and predicted proportions \code{Y}, \code{Y_pp}, \code{R} and \code{R_pp} can also be retrieved. The prevalence and prediceted proportion matrices have rows for MCMC replicates, and columns for days. The MCMC posterior draws of other parameters including \code{beta}, \code{gamma}, \code{R0}, and variance controllers \code{k_p}, \code{lambdaY_p}, \code{lambdaR_p} are also available.}
81 |
82 | \item{save_plot_data}{logical, whether save the plotting data or not.}
83 |
84 | \item{eps}{a non-zero controller so that all the input \code{Y} and \code{R} values would be bounded above 0 (at least \code{eps}). Its default value is 1e-10}
85 | }
86 | \value{
87 | \item{casename}{the predefined \code{casename}.}
88 | \item{incidence_mean}{mean cumulative incidence, the mean prevalence of cumulative confirmed cases at the end of the study.}
89 | \item{incidence_ci}{2.5\%, 50\%, and 97.5\% quantiles of the incidences.}
90 | \item{out_table}{summary tables including the posterior mean of the prevalence processes of the 3 states compartments (\eqn{\theta_t^S,\theta_t^I,\theta_t^R,\theta_t^H}) at last date of data collected ((\eqn{t^\prime}) decided by the lengths of your input data \code{Y} and \code{R}), and their respective credible intervals (ci); the respective means and ci's of the reproduction number (R0), removed rate (\eqn{\gamma}), transmission rate (\eqn{\beta}).}
91 | \item{plot_infection}{plot of summarizing and forecasting for the infection compartment, in which the vertical blue line denotes the last date of data collected (\eqn{t^\prime}), the vertical darkgray line denotes the deacceleration point (first turning point) that the posterior mean first-derivative of infection prevalence \eqn{\dot{\theta}_t^I} achieves the maximum, the vertical purple line denotes the second turning point that the posterior mean first-derivative infection proportion \eqn{\dot{\theta}_t^I} equals zero, the darkgray line denotes the posterior mean of the infection prevalence \eqn{\theta_t^I} and the red line denotes its posterior median. }
92 | \item{plot_removed}{plot of summarizing and forecasting for the removed compartment with lines similar to those in the \code{plot_infection}. The vertical lines are identical, but the horizontal mean and median correspond to the posterior mean and median of the removed process \eqn{\theta_t^R}. An additional line indicates the estimated death prevalence from the input \code{death_in_R}.}
93 | \item{spaghetti_plot}{20 randomly selected MCMC draws of the first-order derivative of the posterior prevalence of infection, namely \eqn{\dot{\theta}_t^I}. The black curve is the posterior mean of the derivative, and the vertical lines mark times of turning points corresponding respectively to those shown in \code{plot_infection} and \code{plot_removed}. Moreover, the 95\% credible intervals of these turning points are also highlighted by semi-transparent rectangles. }
94 | \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
95 | \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
96 |
97 | \item{first_tp_ci}{fwith \code{first_tp_mean}, it reports the corresponding credible interval and median.}
98 | \item{second_tp_mean}{the date t at which \eqn{\theta_t^I=0}, calculated as the average of the stationary points of all of posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "pruple" lines in the plots of \code{plot_infection} and \code{plot_removed}. The latter indicate stationary t at which the first-order derivative of the averaged posterior of \eqn{\theta_t^I} equals zero.}
99 | \item{second_tp_ci}{with \code{second_tp_mean}, it reports the corresponding credible interval and median.}
100 | \item{dic_val}{the output of \code{dic.samples()} in \code{\link[rjags]{dic.samples}}, computing deviance information criterion for model comparison.}
101 | \item{gelman_diag_list}{ Since version 0.3.3, we incorporated Gelman And Rubin's Convergence Diagnostic using \code{\link[coda]{gelman.diag}}. We included both the statistics and their upper C.I. limits. Values substantially above 1 indicate lack of convergence. Error messages would be printed as they are. This would be only valid for multiple chains (e.g. nchain > 1). Note that for time dependent processes, we only compute the convergence of the last observation data (\code{T_prime}), though it shows to be \code{T_prime+1}, which is due to the day 0 for initialization.}
102 | }
103 | \description{
104 | Fit an extended state-space SIR model being reduced by in-home hospitalization.
105 | }
106 | \details{
107 | In this function we allow it to characterize time-varying proportions of susceptible due to government-enforced stringent in-home isolation. We expanded the SIR model by adding a quarantine compartment with a time-varying rate of quarantine \eqn{\phi_t}, the chance of a susceptible person being willing to take in-home isolation at time t.
108 | }
109 | \examples{
110 | \dontrun{
111 | NI_complete <- c(
112 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
113 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
114 | 13522, 16678, 19665, 22112, 24953, 27100, 29631, 31728, 33366
115 | )
116 | RI_complete <- c(
117 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94, 121, 152, 213,
118 | 252, 345, 417, 561, 650, 811, 1017, 1261, 1485, 1917, 2260,
119 | 2725, 3284, 3754
120 | )
121 | N <- 58.5e6
122 | R <- RI_complete / N
123 | Y <- NI_complete / N - R # Jan13->Feb 11
124 |
125 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
126 | phi0 <- c(0.1, 0.4, 0.4)
127 | res.q <- qh.eSIR(Y, R,
128 | begin_str = "01/13/2020", death_in_R = 0.4,
129 | phi0 = phi0, change_time = change_time,
130 | casename = "Hubei_q", save_files = T, save_mcmc = F,
131 | M = 5e2, nburnin = 2e2
132 | )
133 | res.q$plot_infection
134 | # res.q$plot_removed
135 |
136 | res.noq <- qh.eSIR(Y, R,
137 | begin_str = "01/13/2020", death_in_R = 0.4,
138 | T_fin = 200, casename = "Hubei_noq",
139 | M = 5e2, nburnin = 2e2
140 | )
141 | res.noq$plot_infection
142 | }
143 |
144 | change_time <- c("01/16/2020")
145 | phi0 <- c(0.1)
146 | NI_complete2 <- c(41, 45)
147 | RI_complete2 <- c(1, 1)
148 | N2 <- 1E3
149 | res2 <- qh.eSIR(
150 | RI_complete2 / N2,
151 | NI_complete2 / N2,
152 | begin_str = "01/13/2020",
153 | T_fin = 4,
154 | phi0 = phi0,
155 | change_time = change_time,
156 | dic = FALSE,
157 | casename = "Hubei_q",
158 | save_files = FALSE,
159 | save_mcmc = FALSE,
160 | save_plot_data = FALSE,
161 | M = 50,
162 | nburnin = 1
163 | )
164 | closeAllConnections()
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/man/tvt.eSIR.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tvt.eSIR.R
3 | \name{tvt.eSIR}
4 | \alias{tvt.eSIR}
5 | \title{Fit extended state-space SIR model with time-varying transmission rates}
6 | \usage{
7 | tvt.eSIR(
8 | Y,
9 | R,
10 | pi0 = NULL,
11 | change_time = NULL,
12 | exponential = FALSE,
13 | lambda0 = NULL,
14 | begin_str = "01/13/2020",
15 | T_fin = 200,
16 | nchain = 4,
17 | nadapt = 10000,
18 | M = 500,
19 | thn = 10,
20 | nburnin = 200,
21 | dic = FALSE,
22 | death_in_R = 0.02,
23 | beta0 = 0.2586,
24 | gamma0 = 0.0821,
25 | R0 = beta0/gamma0,
26 | gamma0_sd = 0.1,
27 | R0_sd = 1,
28 | casename = "tvt.eSIR",
29 | file_add = character(0),
30 | add_death = FALSE,
31 | save_files = FALSE,
32 | save_mcmc = FALSE,
33 | save_plot_data = FALSE,
34 | eps = 1e-10
35 | )
36 | }
37 | \arguments{
38 | \item{Y}{the time series of daily observed infected compartment proportions.}
39 |
40 | \item{R}{the time series of daily observed removed compartment proportions, including death and recovered.}
41 |
42 | \item{pi0}{the time-dependent transmission rate modifier \eqn{\pi(t)} between 0 and 1.}
43 |
44 | \item{change_time}{the change points over time for step function pi, defalt value is \code{NULL}.}
45 |
46 | \item{exponential}{logical, whether \eqn{\pi(t)} is exponential \eqn{\exp(-\lambda_0t)} or not; the default is \code{FALSE}.}
47 |
48 | \item{lambda0}{the rate of decline in the exponential survival function in \eqn{\exp(-\lambda_0t)}.}
49 |
50 | \item{begin_str}{the character of starting time, the default is "01/13/2020".}
51 |
52 | \item{T_fin}{the end of follow-up time after the beginning date \code{begin_str}, the default is 200.}
53 |
54 | \item{nchain}{the number of MCMC chains generated by \code{\link[rjags]{rjags}}, the default is 4.}
55 |
56 | \item{nadapt}{the iteration number of adaptation in the MCMC. We recommend using at least the default value 1e4 to obtained fully adapted chains.}
57 |
58 | \item{M}{the number of draws in each chain, with no thinning. The default is M=5e2 but suggest using 5e5.}
59 |
60 | \item{thn}{the thinning interval between mixing. The total number of draws thus would become \code{round(M/thn)*nchain}. The default is 10.}
61 |
62 | \item{nburnin}{the burn-in period. The default is 2e2 but suggest 2e5.}
63 |
64 | \item{dic}{logical, whether compute the DIC (deviance information criterion) for model selection.}
65 |
66 | \item{death_in_R}{the numeric value of average of cumulative deaths in the removed compartments. The default is 0.4 within Hubei and 0.02 outside Hubei.}
67 |
68 | \item{beta0}{the hyperparameter of average transmission rate, the default is the one estimated from the SARS first-month outbreak (0.2586).}
69 |
70 | \item{gamma0}{the hyperparameter of average removed rate, the default is the one estimated from the SARS first-month outbreak (0.0821).}
71 |
72 | \item{R0}{the hyperparameter of the mean reproduction number R0. The default is thus the ratio of \code{beta0/gamma0}, which can be specified directly.}
73 |
74 | \item{gamma0_sd}{the standard deviation for the prior distrbution of the removed rate \eqn{\gamma}, the default is 0.1.}
75 |
76 | \item{R0_sd}{the standard deviation for the prior disbution of R0, the default is 1.}
77 |
78 | \item{casename}{the string of the job's name. The default is "tvt.eSIR".}
79 |
80 | \item{file_add}{the string to denote the location of saving output files and tables.}
81 |
82 | \item{add_death}{logical, whether add the approximate death curve to the plot, default is false.}
83 |
84 | \item{save_files}{logical, whether to save plots to file.}
85 |
86 | \item{save_mcmc}{logical, whether save (\code{TRUE}) all the MCMC outputs or not (\code{FALSE}).The output file will be an \code{.RData} file named by the \eqn{casename}. We include arrays of prevalence values of the three compartments with their matrices of posterior draws up to the last date of the collected data as \code{theta_p[,,1]} and afterwards as \code{theta_pp[,,1]} for \eqn{\theta_t^S}, \code{theta_p[,,2]} and \code{theta_pp[,,2]} for \eqn{\theta_t^I}, and \code{theta_p[,,3]} and \code{theta_pp[,,3]} for \eqn{\theta_t^R}. Moreover, the input and predicted proportions \code{Y}, \code{Y_pp}, \code{R} and \code{R_pp} can also be retrieved. The prevalence and predicted proportion matrices have rows for MCMC replicates, and columns for days. The MCMC posterior draws of other parameters including \code{beta_p}, \code{gamma_p}, \code{R0_p}, and variance controllers \code{k_p}, \code{lambdaY_p}, \code{lambdaR_p} are also available.}
87 |
88 | \item{save_plot_data}{logical, whether save the plotting data or not.}
89 |
90 | \item{eps}{a non-zero controller so that all the input \code{Y} and \code{R} values would be bounded above 0 (at least \code{eps}). Its default value is 1e-10}
91 | }
92 | \value{
93 | \item{casename}{the predefined \code{casename}.}
94 | \item{incidence_mean}{mean cumulative incidence, the mean prevalence of cumulative confirmed cases at the end of the study.}
95 | \item{incidence_ci}{2.5\%, 50\%, and 97.5\% quantiles of the incidences.}
96 | \item{out_table}{summary tables including the posterior mean of the prevalance processes of the 3 states compartments (\eqn{\theta_t^S,\theta_t^I,\theta_t^R}) at last date of data collected ((\eqn{t^\prime}) decided by the lengths of your input data \code{Y} and \code{R}), and their respective credible inctervals (ci); the respective means and ci's of the reporduction number (R0), removed rate (\eqn{\gamma}), transmission rate (\eqn{\beta}).}
97 | \item{plot_infection}{plot of summarizing and forecasting for the infection compartment, in which the vertial blue line denotes the last date of data collected (\eqn{t^\prime}), the vertial darkgray line denotes the deacceleration point (first turning point) that the posterior mean first-derivative of infection prevalence \eqn{\dot{\theta}_t^I} achieves the maximum, the vertical purple line denotes the second turning point that the posterior mean first-derivative infection proportion \eqn{\dot{\theta}_t^I} equals zero, the darkgray line denotes the posterior mean of the infection prevalence \eqn{\theta_t^I} and the red line denotes its posterior median. }
98 | \item{plot_removed}{plot of summarizing and forecasting for the removed compartment with lines similar to those in the \code{plot_infection}. The vertical lines are identical, but the horizontal mean and median correspond to the posterior mean and median of the removed process \eqn{\theta_t^R}. An additional line indicates the estimated death prevalence from the input \code{death_in_R}.}
99 | \item{spaghetti_plot}{20 randomly selected MCMC draws of the first-order derivative of the posterior prevalence of infection, namely \eqn{\dot{\theta}_t^I}. The black curve is the posterior mean of the derivative, and the vertical lines mark times of turning points corresponding respectively to those shown in \code{plot_infection} and \code{plot_removed}. Moreover, the 95\% credible intervals of these turning points are also highlighted by semi-transparent rectangles. }
100 | \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0}, calculated as the average of the time points with maximum posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "darkgreen" lines in the two plots \code{plot_infection} and \code{plot_removed}, which indicate the stationary point such that the first-order derivative of the averaged posterior of \eqn{\theta_t^I} reaches its maximum.}
101 |
102 | \item{first_tp_ci}{fwith \code{first_tp_mean}, it reports the corresponding credible interval and median.}
103 | \item{second_tp_mean}{the date t at which \eqn{\theta_t^I=0}, calculated as the average of the stationary points of all of posterior first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from the one labeled by the "pruple" lines in the plots of \code{plot_infection} and \code{plot_removed}. The latter indicate stationary t at which the first-order derivative of the averaged posterior of \eqn{\theta_t^I} equals zero.}
104 | \item{second_tp_ci}{with \code{second_tp_mean}, it reports the corresponding credible interval and median.}
105 | \item{dic_val}{the output of \code{dic.samples()} in \code{\link[rjags]{dic.samples}}, computing deviance information criterion for model comparison.}
106 | \item{gelman_diag_list}{ Since version 0.3.3, we incorporated Gelman And Rubin's Convergence Diagnostic using \code{\link[coda]{gelman.diag}}. We included both the statistics and their upper C.I. limits. Values substantially above 1 indicate lack of convergence. Error messages would be printed as they are. This would be only valid for multiple chains (e.g. nchain > 1). Note that for time dependent processes, we only compute the convergence of the last observation data (\code{T_prime}), though it shows to be \code{T_prime+1}, which is due to the day 0 for initialization.}
107 | }
108 | \description{
109 | Fit extended state-space SIR model with pre-specified changes in the transmission rate, either stepwise or continuous, accommodating time-varying quarantine protocols.
110 | }
111 | \details{
112 | We fit a state-space model with extended SIR, in which a time-varying transmission rate modifier \eqn{\pi(t)} (between 0 and 1) is introduced to model. This allows us to accommodate quarantine protocol changes and ignored resources of hospitalization. The form of reducing rate may be a step-function with jumps at times of big policy changes or a smooth exponential survival function \eqn{\exp(-\lambda_0t)}. The parameters of the function and change points, if any, should be predefined.
113 | }
114 | \examples{
115 | \dontrun{
116 | NI_complete <- c(
117 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
118 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
119 | 13522, 16678, 19665, 22112, 24953, 27100, 29631, 31728, 33366
120 | )
121 | RI_complete <- c(
122 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94, 121, 152, 213,
123 | 252, 345, 417, 561, 650, 811, 1017, 1261, 1485, 1917, 2260,
124 | 2725, 3284, 3754
125 | )
126 | N <- 58.5e6
127 | R <- RI_complete / N
128 | Y <- NI_complete / N - R # Jan13->Feb 11
129 | ### Step function of pi(t)
130 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
131 | pi0 <- c(1.0, 0.9, 0.5, 0.1)
132 | res.step <- tvt.eSIR(Y, R,
133 | begin_str = "01/13/2020", death_in_R = 0.4,
134 | T_fin = 200, pi0 = pi0, change_time = change_time, dic = T,
135 | casename = "Hubei_step", save_files = T,
136 | save_mcmc = F, M = 5e2, nburnin = 2e2
137 | )
138 | res.step$plot_infection
139 | res.step$plot_removed
140 | res.step$dic_val
141 |
142 | ### continuous exponential function of pi(t)
143 | res.exp <- tvt.eSIR(Y, R,
144 | begin_str = "01/13/2020", death_in_R = 0.4,
145 | T_fin = 200, exponential = TRUE, dic = F, lambda0 = 0.05,
146 | casename = "Hubei_exp", save_files = F, save_mcmc = F,
147 | M = 5e2, nburnin = 2e2
148 | )
149 | res.exp$plot_infection
150 | # res.exp$plot_removed
151 |
152 | ### without pi(t), the standard state-space SIR model without intervention
153 | res.nopi <- tvt.eSIR(Y, R,
154 | begin_str = "01/13/2020", death_in_R = 0.4,
155 | T_fin = 200, casename = "Hubei_nopi", save_files = F,
156 | M = 5e2, nburnin = 2e2
157 | )
158 | res.nopi$plot_infection
159 | # res.nopi$plot_removed
160 | }
161 |
162 | change_time <- c("01/18/2020")
163 | pi0<- c(1.0, 0.9)
164 | NI_complete2 <- c(41, 45, 62, 131)
165 | RI_complete2 <- c(1, 1, 7, 10)
166 | N2 <- 1E3
167 | res1 <- tvt.eSIR(
168 | RI_complete2 / N2,
169 | (NI_complete2 - RI_complete2) / N2,
170 | begin_str = "01/10/2020",
171 | T_fin =10,
172 | pi0 = pi0,
173 | change_time = change_time,
174 | dic = FALSE,
175 | casename = "Hubei_step",
176 | save_files = FALSE,
177 | save_mcmc = FALSE,
178 | save_plot_data = FALSE,
179 | M = 50,
180 | nburnin = 1
181 | )
182 | closeAllConnections()
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/man/tvt.eSIR2.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tvt.eSIR2.R
3 | \name{tvt.eSIR2}
4 | \alias{tvt.eSIR2}
5 | \title{Fit extended state-space SIR model with time-varying transmission rates}
6 | \usage{
7 | tvt.eSIR2(
8 | Y,
9 | R,
10 | pi0 = NULL,
11 | change_time = NULL,
12 | exponential = FALSE,
13 | lambda0 = NULL,
14 | begin_str = "01/13/2020",
15 | T_fin = 200,
16 | nchain = 4,
17 | nadapt = 10000,
18 | M = 500,
19 | thn = 10,
20 | nburnin = 200,
21 | dic = FALSE,
22 | death_in_R = 0.02,
23 | beta0 = 0.2586,
24 | gamma0 = 0.0821,
25 | R0 = beta0/gamma0,
26 | gamma0_sd = 0.1,
27 | R0_sd = 1,
28 | casename = "tvt.eSIR2",
29 | file_add = character(0),
30 | add_death = FALSE,
31 | save_files = FALSE,
32 | save_mcmc = FALSE,
33 | save_plot_data = FALSE,
34 | eps = 1e-10,
35 | time_unit = 1
36 | )
37 | }
38 | \arguments{
39 | \item{Y}{the time series of daily observed infected compartment proportions.}
40 |
41 | \item{R}{the time series of daily observed removed compartment proportions,
42 | including death and recovered.}
43 |
44 | \item{pi0}{the time-dependent transmission rate modifier \eqn{\pi(t)} between
45 | 0 and 1.}
46 |
47 | \item{change_time}{the change points over time for step function pi, defalt
48 | value is \code{NULL}.}
49 |
50 | \item{exponential}{logical, whether \eqn{\pi(t)} is exponential
51 | \eqn{\exp(-\lambda_0t)} or not; the default is \code{FALSE}.}
52 |
53 | \item{lambda0}{the rate of decline in the exponential survival function in
54 | \eqn{\exp(-\lambda_0t)}.}
55 |
56 | \item{begin_str}{the character of starting time, the default is "01/13/2020".}
57 |
58 | \item{T_fin}{the end of follow-up time after the beginning date
59 | \code{begin_str}, the default is 200. This value must be longer than the
60 | length of your input observed time series data.}
61 |
62 | \item{nchain}{the number of MCMC chains generated by
63 | \code{\link[rjags]{rjags}}, the default is 4.}
64 |
65 | \item{nadapt}{the iteration number of adaptation in the MCMC. We recommend
66 | using at least the default value 1e4 to obtained fully adapted chains.}
67 |
68 | \item{M}{the number of draws in each chain, with no thinning. The default is
69 | M=5e2 but suggest using 5e5.}
70 |
71 | \item{thn}{the thinning interval between mixing. The total number of draws
72 | thus would become \code{round(M/thn)*nchain}. The default is 10.}
73 |
74 | \item{nburnin}{the burn-in period. The default is 2e2 but suggest 2e5.}
75 |
76 | \item{dic}{logical, whether compute the DIC (deviance information criterion)
77 | for model selection.}
78 |
79 | \item{death_in_R}{the numeric value of average of cumulative deaths in the
80 | removed compartments. The default is 0.4 within Hubei and 0.02 outside Hubei.}
81 |
82 | \item{beta0}{the hyperparameter of average transmission rate, the default is
83 | the one estimated from the SARS first-month outbreak (0.2586).}
84 |
85 | \item{gamma0}{the hyperparameter of average removed rate, the default is the
86 | one estimated from the SARS first-month outbreak (0.0821).}
87 |
88 | \item{R0}{the hyperparameter of the mean reproduction number R0. The default
89 | is thus the ratio of \code{beta0/gamma0}, which can be specified directly.}
90 |
91 | \item{gamma0_sd}{the standard deviation for the prior distrbution of the
92 | removed rate \eqn{\gamma}, the default is 0.1.}
93 |
94 | \item{R0_sd}{the standard deviation for the prior disbution of R0, the
95 | default is 1.}
96 |
97 | \item{casename}{the string of the job's name. The default is "tvt.eSIR2".}
98 |
99 | \item{file_add}{the string to denote the location of saving output files and
100 | tables.}
101 |
102 | \item{add_death}{logical, whether add the approximate death curve to the
103 | plot, default is false.}
104 |
105 | \item{save_files}{logical, whether to save plots to file.}
106 |
107 | \item{save_mcmc}{logical, whether save (\code{TRUE}) all the MCMC outputs or
108 | not (\code{FALSE}).The output file will be an \code{.RData} file named by the
109 | \eqn{casename}. We include arrays of prevalence values of the three
110 | compartments with their matrices of posterior draws up to the last date of
111 | the collected data as \code{theta_p[,,1]} and afterwards as
112 | \code{theta_pp[,,1]} for \eqn{\theta_t^S}, \code{theta_p[,,2]} and
113 | \code{theta_pp[,,2]} for \eqn{\theta_t^I}, and \code{theta_p[,,3]} and
114 | \code{theta_pp[,,3]} for \eqn{\theta_t^R}. Moreover, the input and
115 | predicted proportions \code{Y}, \code{Y_pp}, \code{R} and \code{R_pp} can
116 | also be retrieved. The prevalence and predicted proportion matrices have
117 | rows for MCMC replicates, and columns for days. The MCMC posterior draws of
118 | other parameters including \code{beta_p}, \code{gamma_p}, \code{R0_p}, and
119 | variance controllers \code{k_p}, \code{lambdaY_p}, \code{lambdaR_p} are
120 | also available.}
121 |
122 | \item{save_plot_data}{logical, whether save the plotting data or not.}
123 |
124 | \item{eps}{a non-zero controller so that all the input \code{Y} and \code{R}
125 | values would be bounded above 0 (at least \code{eps}). Its default value is
126 | 1e-10}
127 |
128 | \item{time_unit}{numeric, newly added argument, which can be changed to an
129 | integer (ceiling) of the input to indicate the time unit for each data
130 | point. The default is one-day, i.e., we let each input time series data
131 | correspond to each day. If this value is set to be 7, each data point
132 | represents one-week's aggregated data.}
133 | }
134 | \value{
135 | \item{casename}{the predefined \code{casename}.}
136 | \item{incidence_mean}{mean cumulative incidence, the mean prevalence of
137 | cumulative confirmed cases at the end of the study.}
138 | \item{incidence_ci}{2.5\%, 50\%, and 97.5\% quantiles of the incidences.}
139 | \item{out_table}{summary tables including the posterior mean of the
140 | prevalence processes of the 3 states compartments (\eqn{\theta_t^S,
141 | \theta_t^I,\theta_t^R}) at last date of data collected ((\eqn{t^\prime})
142 | decided by the lengths of your input data \code{Y} and \code{R}), and their
143 | respective credible intervals (ci); the respective means and ci's of the
144 | reproduction number (R0), removed rate (\eqn{\gamma}), transmission rate
145 | (\eqn{\beta}).}
146 | \item{plot_infection}{plot of summarizing and forecasting for the infection
147 | compartment, in which the vertical blue line denotes the last date of data
148 | collected (\eqn{t^\prime}), the vertial darkgray line denotes the
149 | deacceleration point (first turning point) that the posterior mean
150 | first-derivative of infection prevalence \eqn{\dot{\theta}_t^I} achieves the
151 | maximum, the vertical purple line denotes the second turning point that
152 | the posterior mean first-derivative infection proportion
153 | \eqn{\dot{\theta}_t^I} equals zero, the darkgray line denotes the
154 | posterior mean of the infection prevalence \eqn{\theta_t^I} and the red
155 | line denotes its posterior median. }
156 | \item{plot_removed}{plot of summarizing and forecasting for the removed
157 | compartment with lines similar to those in the \code{plot_infection}. The
158 | vertical lines are identical, but the horizontal mean and median correspond
159 | to the posterior mean and median of the removed process \eqn{\theta_t^R}.
160 | An additional line indicates the estimated death prevalence from the input
161 | \code{death_in_R}.}
162 | \item{spaghetti_plot}{20 randomly selected MCMC draws of the first-order
163 | derivative of the posterior prevalence of infection, namely
164 | \eqn{\dot{\theta}_t^I}. The black curve is the posterior mean of the
165 | derivative, and the vertical lines mark times of turning points corresponding
166 | respectively to those shown in \code{plot_infection} and
167 | \code{plot_removed}. Moreover, the 95\% credible intervals of these turning
168 | points are also highlighted by semi-transparent rectangles. }
169 | \item{first_tp_mean}{the date t at which \eqn{\ddot{\theta}_t^I=0},
170 | calculated as the average of the time points with maximum posterior
171 | first-order derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly
172 | different from the one labeled by the "darkgreen" lines in the two plots
173 | \code{plot_infection} and \code{plot_removed}, which indicate the stationary
174 | point such that the first-order derivative of the averaged posterior of
175 | \eqn{\theta_t^I} reaches its maximum.}
176 |
177 | \item{first_tp_ci}{fwith \code{first_tp_mean}, it reports the corresponding
178 | credible interval and median.}
179 | \item{second_tp_mean}{the date t at which \eqn{\theta_t^I=0}, calculated as
180 | the average of the stationary points of all of posterior first-order
181 | derivatives \eqn{\dot{\theta}_t^I}; this value may be slightly different from
182 | the one labeled by the "pruple" lines in the plots of \code{plot_infection}
183 | and \code{plot_removed}. The latter indicate stationary t at which the
184 | first-order derivative of the averaged posterior of \eqn{\theta_t^I} equals
185 | zero.}
186 | \item{second_tp_ci}{with \code{second_tp_mean}, it reports the corresponding
187 | credible interval and median.}
188 | \item{dic_val}{the output of \code{dic.samples()} in \code{\link[rjags]{di
189 | c.samples}}, computing deviance information criterion for model comparison.}
190 | \item{gelman_diag_list}{ Since version 0.3.3, we incorporated Gelman And
191 | Rubin's Convergence Diagnostic using \code{\link[coda]{gelman.diag}}. We
192 | included both the statistics and their upper C.I. limits. Values
193 | substantially above 1 indicate lack of convergence. Error messages would be
194 | printed as they are. This would be only valid for multiple chains
195 | (e.g. nchain > 1). Note that for time dependent processes, we only compute
196 | the convergence of the last observation data (\code{T_prime}), though it
197 | shows to be \code{T_prime+1}, which is due to the day 0 for initialization.}
198 | }
199 | \description{
200 | Fit extended state-space SIR model with pre-specified changes in the
201 | transmission rate, either stepwise or continuous, accommodating time-varying
202 | quarantine protocols.
203 | }
204 | \details{
205 | We fit a state-space model with extended SIR, in which a time-varying
206 | transmission rate modifier \eqn{\pi(t)} (between 0 and 1) is introduced to
207 | the model. This allows us to accommodate quarantine protocol changes and
208 | ignored resources of hospitalization. The form of reducing rate may be a step
209 | -function with jumps at times of big policy changes or a smooth exponential
210 | survival function \eqn{\exp(-\lambda_0t)}. The parameters of the function and
211 | change points, if any, should be predefined.
212 | }
213 | \examples{
214 | \dontrun{
215 | NI_complete <- c(
216 | 41, 41, 41, 45, 62, 131, 200, 270, 375, 444, 549, 729,
217 | 1052, 1423, 2714, 3554, 4903, 5806, 7153, 9074, 11177,
218 | 13522, 16678, 19665, 22112, 24953, 27100, 29631, 31728, 33366
219 | )
220 | RI_complete <- c(
221 | 1, 1, 7, 10, 14, 20, 25, 31, 34, 45, 55, 71, 94, 121, 152, 213,
222 | 252, 345, 417, 561, 650, 811, 1017, 1261, 1485, 1917, 2260,
223 | 2725, 3284, 3754
224 | )
225 | N <- 58.5e6
226 | R <- RI_complete / N
227 | Y <- NI_complete / N - R # Jan13->Feb 11
228 | ### Step function of pi(t)
229 | change_time <- c("01/23/2020", "02/04/2020", "02/08/2020")
230 | pi0 <- c(1.0, 0.9, 0.5, 0.1)
231 | res.step <- tvt.eSIR(Y, R,
232 | begin_str = "01/13/2020", death_in_R = 0.4,
233 | T_fin = 200, pi0 = pi0, change_time = change_time, dic = T,
234 | casename = "Hubei_step", save_files = T,
235 | save_mcmc = F, M = 5e2, nburnin = 2e2
236 | )
237 | res.step$plot_infection
238 | res.step$plot_removed
239 | res.step$dic_val
240 |
241 | ### continuous exponential function of pi(t)
242 | res.exp <- tvt.eSIR(Y, R,
243 | begin_str = "01/13/2020", death_in_R = 0.4,
244 | T_fin = 200, exponential = TRUE, dic = F, lambda0 = 0.05,
245 | casename = "Hubei_exp", save_files = F, save_mcmc = F,
246 | M = 5e2, nburnin = 2e2
247 | )
248 | res.exp$plot_infection
249 | # res.exp$plot_removed
250 |
251 | ### without pi(t), the standard state-space SIR model without intervention
252 | res.nopi <- tvt.eSIR(Y, R,
253 | begin_str = "01/13/2020", death_in_R = 0.4,
254 | T_fin = 200, casename = "Hubei_nopi", save_files = F,
255 | M = 5e2, nburnin = 2e2
256 | )
257 | res.nopi$plot_infection
258 | # res.nopi$plot_removed
259 | }
260 |
261 | change_time <- c("01/18/2020")
262 | pi0<- c(1.0, 0.9)
263 | NI_complete2 <- c(41, 45, 62, 131)
264 | RI_complete2 <- c(1, 1, 7, 10)
265 | N2 <- 1E3
266 | res1 <- tvt.eSIR(
267 | Y = RI_complete2 / N2,
268 | R = (NI_complete2 - RI_complete2) / N2,
269 | begin_str = "01/10/2020",
270 | T_fin =10,
271 | pi0 = pi0,
272 | change_time = change_time,
273 | dic = FALSE,
274 | casename = "Hubei_step",
275 | save_files = FALSE,
276 | save_mcmc = FALSE,
277 | save_plot_data = FALSE,
278 | M = 50,
279 | nburnin = 1
280 | )
281 | closeAllConnections()
282 |
283 | }
284 |
--------------------------------------------------------------------------------
/meta/Hubei_exp2_plot_data.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_exp2_plot_data.RData
--------------------------------------------------------------------------------
/meta/Hubei_exp_plot_data.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_exp_plot_data.RData
--------------------------------------------------------------------------------
/meta/Hubei_qR0_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qR0_p.png
--------------------------------------------------------------------------------
/meta/Hubei_q_Gelman_diag.txt:
--------------------------------------------------------------------------------
1 | [[1]]
2 | Potential scale reduction factors:
3 |
4 | Point est. Upper C.I.
5 | R0 1 1.01
6 |
7 |
8 | [[2]]
9 | Potential scale reduction factors:
10 |
11 | Point est. Upper C.I.
12 | gamma 1.03 1.1
13 |
14 |
15 | [[3]]
16 | Potential scale reduction factors:
17 |
18 | Point est. Upper C.I.
19 | beta 1.02 1.06
20 |
21 |
22 | [[4]]
23 | Potential scale reduction factors:
24 |
25 | Point est. Upper C.I.
26 | theta[31,1] 1.02 1.05
27 | theta[31,2] 1.01 1.02
28 | theta[31,3] 1.07 1.21
29 |
30 | Multivariate psrf
31 |
32 | 1.07
33 |
34 | [[5]]
35 | [[5]][[1]]
36 | [1] "theta_Q: "
37 |
38 | [[5]][[2]]
39 | Potential scale reduction factors:
40 |
41 | Point est. Upper C.I.
42 | [1,] 1.01 1.02
43 |
44 |
45 |
46 | [[6]]
47 | Potential scale reduction factors:
48 |
49 | Point est. Upper C.I.
50 | lambdaY 1 1.01
51 |
52 |
53 | [[7]]
54 | Potential scale reduction factors:
55 |
56 | Point est. Upper C.I.
57 | lambdaR 1.05 1.15
58 |
59 |
60 | [[8]]
61 | Potential scale reduction factors:
62 |
63 | Point est. Upper C.I.
64 | k 1 1.01
65 |
66 |
67 |
--------------------------------------------------------------------------------
/meta/Hubei_q_forecast.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_q_forecast.png
--------------------------------------------------------------------------------
/meta/Hubei_q_forecast2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_q_forecast2.png
--------------------------------------------------------------------------------
/meta/Hubei_q_spaghetti.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_q_spaghetti.png
--------------------------------------------------------------------------------
/meta/Hubei_q_summary.csv:
--------------------------------------------------------------------------------
1 | "","thetaS_last_obs_p_mean","thetaI_last_obs_p_mean","thetaR_last_obs_p_mean","thetaS_last_obs_p_ci_low","thetaS_last_obs_p_ci_med","thetaS_last_obs_p_ci_up","thetaI_last_obs_p_ci_low","thetaI_last_obs_p_ci_med","thetaI_last_obs_p_ci_up","thetaR_last_obs_p_ci_low","thetaR_last_obs_p_ci_med","thetaR_last_obs_p_ci_up","thetaQ_last_obs_p_mean","thetaQ_last_obs_p_ci_low","thetaQ_last_obs_p_ci_med","thetaQ_last_obs_p_ci_up","R0_p_mean","R0_p_ci_low","R0_p_ci_med","R0_p_ci_up","gamma_p_mean","gamma_p_ci_low","gamma_p_ci_med","gamma_p_ci_up","beta_p_mean","beta_p_ci_low","beta_p_ci_med","beta_p_ci_up","incidence_mean","incidence_ci_low","incidence_ci_median","incidence_ci_up","thetaI_tp1_mean","thetaI_tp1_ci_low","thetaI_tp1_ci_med","thetaI_tp1_ci_up","thetaR_tp1_mean","thetaR_tp1_ci_low","thetaR_tp1_ci_med","thetaR_tp1_ci_up","Y_tp1_mean","Y_tp1_ci_low","Y_tp1_ci_med","Y_tp1_ci_up","R_tp1_mean","R_tp1_ci_low","R_tp1_ci_med","R_tp1_ci_up","thetaI_tp2_mean","thetaI_tp2_ci_low","thetaI_tp2_ci_med","thetaI_tp2_ci_up","thetaR_tp2_mean","thetaR_tp2_ci_low","thetaR_tp2_ci_med","thetaR_tp2_ci_up","Y_tp2_mean","Y_tp2_ci_low","Y_tp2_ci_med","Y_tp2_ci_up","R_tp2_mean","R_tp2_ci_low","R_tp2_ci_med","R_tp2_ci_up","thetaR_max_mean","thetaR_max_ci_low","thetaR_max_ci_med","thetaR_max_ci_up","cumInf_mean","cumInf_ci_low","cumInf_ci_med","cumInf_ci_up","dthetaI_tp1_date","first_tp_mean","first_tp_ci_low","first_tp_ci_med","first_tp_ci_up","dthetaI_tp2_date","second_tp_mean","second_tp_ci_low","second_tp_ci_med","second_tp_ci_up","end_p_mean","end_p_ci_low","end_p_ci_med","end_p_ci_up","begin_str"
2 | "1",0.323627771049937,0.00048412953022848,9.33687777970314e-05,0.323506071364232,0.323629123726933,0.323739488025614,0.000388071773970557,0.000482170489415861,0.000585849689548004,5.33024511325252e-05,9.02471915039028e-05,0.000154016448304686,0.675794730642037,0.675762458664842,0.67579530192589,0.67582423706666,5.18168601474047,2.91307620472872,5.05856659825961,8.08592906095152,0.0421183406497194,0.0215224214455869,0.0414839453561701,0.0666072028825417,0.21501227998365,0.0873853318701543,0.213793025930806,0.348034070626229,0.0970818512508066,0.00152576342450661,0.068127550840699,0.276164917486482,0.0117804544072757,0.000156143360209102,0.00510860709186228,0.0624548836649834,0.015260893007178,0.000823057411667987,0.00775592134691071,0.0723201222776665,0.0117794906327375,0.000143514714527152,0.00516690638923647,0.0621990640754181,0.0152520882621404,0.000800845292931698,0.007752134020149,0.0724843965016514,0.0217850748146996,6.14609022327624e-05,0.0162576743227043,0.0671185591187055,0.0650021704133047,0.00129986603831937,0.0363537558411177,0.23115614426055,0.0218017026015689,5.3085226274563e-05,0.016400139436306,0.0671094368982572,0.0649973934302202,0.0012827357109261,0.0363289593876416,0.232364254571909,0.0756010904498098,0.00135312994379369,0.0460072384716454,0.246550868418568,0.0970818512508066,0.00152576342450661,0.068127550840699,0.276164917486482,"05/15/20","05/13/20","02/01/20","06/01/20","07/30/20","07/18/20","05/25/20","02/03/20","06/27/20","07/30/20","07/29/20","07/30/20","07/30/20","07/30/20","01/13/2020"
3 |
--------------------------------------------------------------------------------
/meta/Hubei_qbeta_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qbeta_p.png
--------------------------------------------------------------------------------
/meta/Hubei_qderiv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qderiv.png
--------------------------------------------------------------------------------
/meta/Hubei_qgamma_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qgamma_p.png
--------------------------------------------------------------------------------
/meta/Hubei_qk_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qk_p.png
--------------------------------------------------------------------------------
/meta/Hubei_qlambdaR_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qlambdaR_p.png
--------------------------------------------------------------------------------
/meta/Hubei_qlambdaY_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qlambdaY_p.png
--------------------------------------------------------------------------------
/meta/Hubei_qthetaQ_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qthetaQ_p.png
--------------------------------------------------------------------------------
/meta/Hubei_qthetaQ_plot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qthetaQ_plot.png
--------------------------------------------------------------------------------
/meta/Hubei_qtheta_p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_qtheta_p.png
--------------------------------------------------------------------------------
/meta/Hubei_step2_plot_data.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_step2_plot_data.RData
--------------------------------------------------------------------------------
/meta/Hubei_step_plot_data.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lilywang1988/eSIR/2a1f0c36afd0d77b55642102780d852d2354fe46/meta/Hubei_step_plot_data.RData
--------------------------------------------------------------------------------