<!DOCTYPE html> <!-- Generated by pkgdown: do not edit by hand --><html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Introduction to sirplus (V2) • sirplus</title> <!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/cosmo/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"> <script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"> <!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"> <script src="../pkgdown.js"></script><meta property="og:title" content="Introduction to sirplus (V2)"> <meta property="og:description" content="sirplus"> <!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body data-spy="scroll" data-target="#toc"> <div class="container template-article"> <header><div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <span class="navbar-brand"> <a class="navbar-link" href="../index.html">sirplus</a> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0</span> </span> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li> <a href="../index.html"> <span class="fas fa fas fa-home fa-lg"></span> </a> </li> <li> <a href="../reference/index.html">Reference</a> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> Articles <span class="caret"></span> </a> <ul class="dropdown-menu" role="menu"> <li> <a href="../articles/sirplus_intro_v2.html">Introduction to sirplus (V2)</a> </li> </ul> </li> <li> <a href="../news/index.html">Changelog</a> </li> </ul> <ul class="nav navbar-nav navbar-right"></ul> </div> <!--/.nav-collapse --> </div> <!--/.container --> </div> <!--/.navbar --> </header><div class="row"> <div class="col-md-9 contents"> <div class="page-header toc-ignore"> <h1 data-toc-skip>Introduction to sirplus (V2)</h1> <h4 class="date">Last updated: 12 April 2020</h4> <div class="hidden name"><code>sirplus_intro_v2.Rmd</code></div> </div> <p><img src="sirplus-logo-small.png"></p> <p>The sirplus package makes it easy to generate stochastic individual compartment models (ICMs) to simulate contagious disease spread using compartments not available in standard SIR packages. This method and most of the code was originally written by Tim Churches (see his <a href="https://timchurches.github.io/blog/posts/2020-03-18-modelling-the-effects-of-public-health-interventions-on-covid-19-transmission-part-2/">blog post</a>). The sirplus package was developed by the Bioinformatics & Cellular Genomics team at St. Vincent’s Institute of Medical Research in order to help St. Vincents’ Hospital model the COVID-19 pandemic.</p> <p>The compartments available in this package include:</p> <table class="table"> <colgroup> <col width="13%"> <col width="86%"> </colgroup> <thead><tr class="header"> <th>Compartment</th> <th>Functional definition</th> </tr></thead> <tbody> <tr class="odd"> <td><strong>S</strong></td> <td>Susceptible individuals</td> </tr> <tr class="even"> <td><strong>E</strong></td> <td>Exposed <strong>and</strong> infected, not yet symptomatic but potentially infectious</td> </tr> <tr class="odd"> <td><strong>I</strong></td> <td>Infected, symptomatic <strong>and</strong> infectious</td> </tr> <tr class="even"> <td><strong>Q</strong></td> <td>Infectious, but (self-)isolated</td> </tr> <tr class="odd"> <td><strong>H</strong></td> <td>Requiring hospitalisation (would normally be hospitalised if capacity available)</td> </tr> <tr class="even"> <td><strong>R</strong></td> <td>Recovered, immune from further infection</td> </tr> <tr class="odd"> <td><strong>F</strong></td> <td>Case fatality (death due to infection, not other causes)</td> </tr> </tbody> </table> <p>The diagram below shows the model structure and how the parameters and compartments associate with each other. See Tim Churches’s <a href="https://timchurches.github.io/blog/posts/2020-03-18-modelling-the-effects-of-public-health-interventions-on-covid-19-transmission-part-2/">blog post</a> for more details.</p> <p><img src="model_diagram.png"></p> <table class="table"> <colgroup> <col width="13%"> <col width="16%"> <col width="69%"> </colgroup> <thead><tr class="header"> <th>trasnitions</th> <th>Description</th> <th>Parameters (with default values)</th> </tr></thead> <tbody> <tr class="odd"> <td><strong>inf</strong></td> <td>Infection due to contact</td> <td> <code>act.rate.*</code> and <code>inf.prob.*</code>, where <code><a href="https://rdrr.io/r/base/Arithmetic.html">*</a></code> = <code>i</code>, <code>e</code>, <code>q</code> </td> </tr> <tr class="even"> <td><strong>prog</strong></td> <td>Progress from asymptomatic to symptomatic</td> <td> <code>prog.rand = FALSE</code>, <code>prog.rate</code>, <code>prog.dist.scale = 5</code>, <code>prog.dist.shape = 1.5</code> </td> </tr> <tr class="odd"> <td><strong>quar</strong></td> <td>From infectious to quarantine</td> <td> <code>quar.rand = TRUE</code>, <code>quar.rate = 1/30</code> </td> </tr> <tr class="even"> <td><strong>hosp</strong></td> <td>From infected (both before and during quarantine) to require hospitalisation</td> <td> <code>quar.rand = TRUE</code>, <code>quar.rate = 1/30</code> </td> </tr> <tr class="odd"> <td><strong>rec</strong></td> <td>From infected to recovered without hospitalization</td> <td> <code>rec.rand = FALSE</code>, <code>prog.dist.scale = 35</code>, <code>prog.dist.shape = 1.5</code> </td> </tr> <tr class="even"> <td><strong>arec</strong></td> <td>Exposed individuals recovered before symptomatic</td> <td> <code>arec.rand = TRUE</code>, <code>arec.rate = 0.05</code> </td> </tr> <tr class="odd"> <td><strong>disch</strong></td> <td>recovery after hospitalization</td> <td> <code>disch.rand = TRUE</code>, <code>disch.rate = 1/15</code> </td> </tr> <tr class="even"> <td><strong>fat</strong></td> <td>Fatality</td> <td> <code>fat.rate.base = 1/50</code>, <code>hosp.cap = 40</code>, <code>fat.rate.overcap = 1/25</code>, <code>fat.tcoeff = 0.5</code> </td> </tr> </tbody> </table> <div class="sourceCode" id="cb1"><html><body><pre class="r"><span class="co">#library(sirplus)</span> <span class="kw pkg">devtools</span><span class="kw ns">::</span><span class="fu"><a href="https://devtools.r-lib.org//reference/load_all.html">load_all</a></span>(<span class="st">"."</span>) <span class="co">## Loading sirplus</span></pre></body></html></div> <div id="simulate-and-inspect-a-baseline-sirplus-model" class="section level2"> <h2 class="hasAnchor"> <a href="#simulate-and-inspect-a-baseline-sirplus-model" class="anchor"></a>Simulate and inspect a baseline sirplus model</h2> <div id="set-parameters" class="section level3"> <h3 class="hasAnchor"> <a href="#set-parameters" class="anchor"></a>Set parameters</h3> <p>Here we will simulate the epidemiological data for a made-up population with 1000 susceptible individuals (S), 50 that are infected but not in the hospital or in self-quarantine (I; maybe people that are infected/symptomatic but not tested/ aware), 10 confirmed cases that have self-isolated (Q), and 1 confirmed case that has been hospitalized (H). We call this the baseline model because it uses default parameters for disease spread (i.e. no additional interventions).</p> <div class="sourceCode" id="cb2"><html><body><pre class="r"><span class="no">s.num</span> <span class="kw"><-</span> <span class="fl">2000</span> <span class="co"># number susceptible</span> <span class="no">i.num</span> <span class="kw"><-</span> <span class="fl">15</span> <span class="co"># number infected </span> <span class="no">q.num</span> <span class="kw"><-</span> <span class="fl">5</span> <span class="co"># number in self-isolation</span> <span class="no">h.num</span> <span class="kw"><-</span> <span class="fl">1</span> <span class="co"># number in the hospital</span> <span class="no">nsteps</span> <span class="kw"><-</span> <span class="fl">90</span> <span class="co"># number of steps (e.g. days) to simulate</span> <span class="no">control</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/control_seiqhrf.html">control_seiqhrf</a></span>(<span class="kw">nsteps</span> <span class="kw">=</span> <span class="no">nsteps</span>) <span class="no">param</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/param_seiqhrf.html">param_seiqhrf</a></span>() <span class="no">init</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/init_seiqhrf.html">init_seiqhrf</a></span>(<span class="kw">s.num</span> <span class="kw">=</span> <span class="no">s.num</span>, <span class="kw">i.num</span> <span class="kw">=</span> <span class="no">i.num</span>, <span class="kw">q.num</span> <span class="kw">=</span> <span class="no">q.num</span>, <span class="kw">h.num</span> <span class="kw">=</span> <span class="no">h.num</span>) <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="no">init</span>) <span class="co">## SEIQHRF Initial Conditions</span> <span class="co">## ===========================</span> <span class="co">## </span> <span class="co">## User specified control parameters:</span> <span class="co">## ---------------------------</span> <span class="co">## s.num = 2000</span> <span class="co">## i.num = 15</span> <span class="co">## q.num = 5</span> <span class="co">## h.num = 1</span> <span class="co">## </span> <span class="co">## Default control parameters:</span> <span class="co">## ---------------------------</span> <span class="co">## e.num = 0</span> <span class="co">## r.num = 0</span> <span class="co">## f.num = 0</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="no">control</span>) <span class="co">## SEIQHRF Control Settings</span> <span class="co">## ===========================</span> <span class="co">## </span> <span class="co">## User specified control parameters:</span> <span class="co">## ---------------------------</span> <span class="co">## nsteps = 90</span> <span class="co">## </span> <span class="co">## Default control parameters:</span> <span class="co">## ---------------------------</span> <span class="co">## type = SEIQHRF</span> <span class="co">## nsims = 8</span> <span class="co">## prog.rand = FALSE</span> <span class="co">## quar.rand = TRUE</span> <span class="co">## hosp.rand = TRUE</span> <span class="co">## disch.rand = TRUE</span> <span class="co">## rec.rand = FALSE</span> <span class="co">## arec.rand = TRUE</span> <span class="co">## fat.rand = TRUE</span> <span class="co">## a.rand = TRUE</span> <span class="co">## d.rand = TRUE</span> <span class="co">## verbose = FALSE</span> <span class="co">## verbose.int = 0</span> <span class="co">## skip.check = FALSE</span> <span class="co">## ncores = 4</span> <span class="co">## bi.mods = initialize.FUN infection.FUN recovery.FUN departures.FUN arrivals.FUN </span> <span class="co">## get_prev.FUN</span> <span class="co">## Base Modules: initialize.FUN infection.FUN recovery.FUN departures.FUN </span> <span class="co">## arrivals.FUN get_prev.FUN</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="no">param</span>) <span class="co">## SEIQHRF Parameters</span> <span class="co">## ===========================</span> <span class="co">## </span> <span class="co">## User specified control parameters:</span> <span class="co">## ---------------------------</span> <span class="co">## </span> <span class="co">## Default control parameters:</span> <span class="co">## ---------------------------</span> <span class="co">## inf.prob.e = 0.02</span> <span class="co">## act.rate.e = 10</span> <span class="co">## inf.prob.i = 0.05</span> <span class="co">## act.rate.i = 10</span> <span class="co">## inf.prob.q = 0.02</span> <span class="co">## act.rate.q = 2.5</span> <span class="co">## prog.rate = 0.1</span> <span class="co">## quar.rate = 0.03333333</span> <span class="co">## hosp.rate = 0.01</span> <span class="co">## disch.rate = 0.06666667</span> <span class="co">## rec.rate = 0.071</span> <span class="co">## arec.rate = 0.05</span> <span class="co">## prog.dist.scale = 5</span> <span class="co">## prog.dist.shape = 1.5</span> <span class="co">## quar.dist.scale = 1</span> <span class="co">## quar.dist.shape = 1</span> <span class="co">## hosp.dist.scale = 1</span> <span class="co">## hosp.dist.shape = 1</span> <span class="co">## disch.dist.scale = 1</span> <span class="co">## disch.dist.shape = 1</span> <span class="co">## rec.dist.scale = 35</span> <span class="co">## rec.dist.shape = 1.5</span> <span class="co">## arec.dist.scale = 35</span> <span class="co">## arec.dist.shape = 1.5</span> <span class="co">## fat.rate.base = 0.02</span> <span class="co">## hosp.cap = 40</span> <span class="co">## fat.rate.overcap = 0.04</span> <span class="co">## fat.tcoeff = 0.5</span> <span class="co">## a.rate = 2.876712e-05</span> <span class="co">## a.prop.e = 0.01</span> <span class="co">## a.prop.i = 0.001</span> <span class="co">## a.prop.q = 0.01</span> <span class="co">## ds.rate = 1.917808e-05</span> <span class="co">## de.rate = 1.917808e-05</span> <span class="co">## di.rate = 1.917808e-05</span> <span class="co">## dq.rate = 1.917808e-05</span> <span class="co">## dh.rate = 5.479452e-05</span> <span class="co">## dr.rate = 1.917808e-05</span> <span class="co">## act.rate = 1</span> <span class="co">## groups = 1</span></pre></body></html></div> </div> <div id="simulate-baseline" class="section level3"> <h3 class="hasAnchor"> <a href="#simulate-baseline" class="anchor"></a>Simulate baseline</h3> <p>This will produce an seiqhrf object.</p> <div class="sourceCode" id="cb3"><html><body><pre class="r"><span class="no">baseline_sim</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/seiqhrf.html">seiqhrf</a></span>(<span class="no">init</span>, <span class="no">control</span>, <span class="no">param</span>) <span class="no">baseline_sim</span> <span class="co">## SEIQHRF Model Simulation</span> <span class="co">## =======================</span> <span class="co">## Model class: seiqhrf</span> <span class="co">## </span> <span class="co">## Simulation Summary</span> <span class="co">## -----------------------</span> <span class="co">## Model type: SEIQHRF</span> <span class="co">## Number of simulations: 8</span> <span class="co">## Number of time steps: 90</span> <span class="co">## </span> <span class="co">## Model Output (variable names)</span> <span class="co">## -----------------------</span> <span class="co">## s.num i.num num se.flow is.flow iq.flow iq2h.flow hf.flow </span> <span class="co">## ds.flow de.flow di.flow dq.flow dh.flow dr.flow a.flow </span> <span class="co">## a.e.flow a.i.flow a.q.flow e.num r.num q.num h.num f.num</span></pre></body></html></div> </div> <div id="extract-summary-of-the-simulation" class="section level3"> <h3 class="hasAnchor"> <a href="#extract-summary-of-the-simulation" class="anchor"></a>Extract summary of the simulation</h3> <div class="sourceCode" id="cb4"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/summary.html">summary</a></span>(<span class="no">baseline_sim</span>) <span class="co">## Peaks of SEIQHRF Model Simulation: </span> <span class="co">## ===============================</span> <span class="co">## Max Time</span> <span class="co">## s.num 2000.00 1</span> <span class="co">## e.num 340.50 21</span> <span class="co">## i.num 532.25 26</span> <span class="co">## q.num 110.25 29</span> <span class="co">## h.num 58.88 35</span> <span class="co">## r.num 1928.88 90</span> <span class="co">## f.num 3.62 78</span> <span class="fu"><a href="https://rdrr.io/r/utils/ls_str.html">ls.str</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/summary.html">summary</a></span>(<span class="no">baseline_sim</span>)) <span class="co">## e.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] NaN 9 19.2 27.2 36.5 ...</span> <span class="co">## $ sd : Named num [1:90] NA 3.34 6.5 7.25 6.72 ...</span> <span class="co">## $ CI : num [1:90, 1:2] NaN 2.46 6.52 13.05 23.33 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] NA 4.53 11.7 17.52 28 ...</span> <span class="co">## f.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] NaN 0 0 0 0 0 0 0 0 0 ...</span> <span class="co">## $ sd : Named num [1:90] NA 0 0 0 0 0 0 0 0 0 ...</span> <span class="co">## $ CI : num [1:90, 1:2] NaN 0 0 0 0 0 0 0 0 0 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] NA 0 0 0 0 0 0 0 0 0 ...</span> <span class="co">## h.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] NaN 1.25 1.12 1 1.38 ...</span> <span class="co">## $ sd : Named num [1:90] NA 0.707 1.126 1.069 1.061 ...</span> <span class="co">## $ CI : num [1:90, 1:2] NaN -0.136 -1.082 -1.095 -0.704 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] NA 1 0 0 0.175 0 1 1 1 1 ...</span> <span class="co">## i.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] 15 14.8 14.9 16.4 19.9 ...</span> <span class="co">## $ sd : Named num [1:90] 0 0.707 1.246 1.061 2.997 ...</span> <span class="co">## $ CI : num [1:90, 1:2] 15 13.4 12.4 14.3 14 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] 15 13.4 13.2 15 17.2 ...</span> <span class="co">## q.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] NaN 5 5.38 6.5 7.75 ...</span> <span class="co">## $ sd : Named num [1:90] NA 0 0.916 0.535 1.035 ...</span> <span class="co">## $ CI : num [1:90, 1:2] NaN 5 3.58 5.45 5.72 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] NA 5 4.17 6 6.17 ...</span> <span class="co">## r.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] NaN 0.5 1.75 3 5.12 ...</span> <span class="co">## $ sd : Named num [1:90] NA 0.535 1.581 2.138 1.458 ...</span> <span class="co">## $ CI : num [1:90, 1:2] NaN -0.548 -1.349 -1.191 2.268 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] NA 0 0 0 4 ...</span> <span class="co">## s.num : List of 4</span> <span class="co">## $ mean : Named num [1:90] 2000 1990 1979 1967 1950 ...</span> <span class="co">## $ sd : Named num [1:90] 0 3.16 6.25 7.38 8.26 ...</span> <span class="co">## $ CI : num [1:90, 1:2] 2000 1984 1966 1952 1934 ...</span> <span class="co">## $ qntCI: num [1:90, 1:2] 2000 1986 1968 1955 1936 ...</span></pre></body></html></div> </div> <div id="inspect-baseline-transition-distributions" class="section level3"> <h3 class="hasAnchor"> <a href="#inspect-baseline-transition-distributions" class="anchor"></a>Inspect baseline transition distributions</h3> <p>The sirplus model controls transitions between compartments, i.e. a change in state for an individual (e.g. going from self-isolation to hospital), using a variety of transition parameters. You can use the <code><a href="https://rdrr.io/r/graphics/plot.html">plot()</a></code> functions, and set parameter <code>method</code> as <code>times</code> to examine the distributions of timings for various transitions based on these parameters. In the case of a disease with observed data available, these plots can be used to sanity check parameter settings.</p> <div class="sourceCode" id="cb5"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/graphics/plot.html">plot</a></span>(<span class="no">baseline_sim</span>, <span class="st">"times"</span>)</pre></body></html></div> <p><img src="sirplus_intro_v2_files/figure-html/baseline%20sims-1.png" width="700"></p> </div> <div id="plot-baseline-sirplus-results" class="section level3"> <h3 class="hasAnchor"> <a href="#plot-baseline-sirplus-results" class="anchor"></a>Plot baseline sirplus results</h3> <p>To visualise your sirplus model, you can plot the change in prevalence (i.e. people) over time in each compartment. By default, this plotting function shows the mean count across all simulations and the 95th quantile in the ribbon. You can hide the CI by setting parameter <code>ci</code> to <code>FALSE</code>.</p> <div class="sourceCode" id="cb6"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/graphics/plot.html">plot</a></span>(<span class="no">baseline_sim</span>, <span class="kw">start_date</span> <span class="kw">=</span> <span class="kw pkg">lubridate</span><span class="kw ns">::</span><span class="fu"><a href="http://lubridate.tidyverse.org/reference/ymd.html">ymd</a></span>(<span class="st">"2020-01-01"</span>), <span class="kw">comp_remove</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">'s.num'</span>, <span class="st">'r.num'</span>), <span class="kw">plot_title</span> <span class="kw">=</span> <span class="st">'Baseline Model'</span>) <span class="co">## Scale for 'colour' is already present. Adding another scale for 'colour',</span> <span class="co">## which will replace the existing scale.</span> <span class="co">## Warning: Removed 4 row(s) containing missing values (geom_path).</span></pre></body></html></div> <p><img src="sirplus_intro_v2_files/figure-html/viz%20prevalence-1.png" width="700"></p> </div> </div> <div id="run-an-experiment" class="section level2"> <h2 class="hasAnchor"> <a href="#run-an-experiment" class="anchor"></a>Run an experiment</h2> <p>With the sirplus package you can also set up experiments. We will set up two experiments here:</p> <ul> <li>Experiment #1: One week after the beginning of the epidemic, schools and non-essential businesses are closed to encourage social distancing. This causes the act.rate to gradually drop from 10 to 6 over the course of the next week. In this experiment, we imagine these policies are never lifted, so act.rate remains at 6 for the duration of the simulation.</li> <li>Experiment #2: Again, one week after the beginning of the epidemic, social distancing policies are put into place resulting in act.rate dropping from 10 to 6 over the next week. But after two weeks these policies are lifted and the act.rate returns to normal within the next week.</li> </ul> <div class="sourceCode" id="cb7"><html><body><pre class="r"><span class="co"># Experiment #1</span> <span class="no">vals</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">10</span>, <span class="fl">7</span>) <span class="no">timing</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">7</span>, <span class="fl">14</span>) <span class="no">act_rate</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/vary_param.html">vary_param</a></span>(<span class="kw">nstep</span> <span class="kw">=</span> <span class="no">nsteps</span>, <span class="kw">vals</span> <span class="kw">=</span> <span class="no">vals</span>, <span class="kw">timing</span> <span class="kw">=</span> <span class="no">timing</span>) <span class="no">control</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/control_seiqhrf.html">control_seiqhrf</a></span>(<span class="kw">nsteps</span> <span class="kw">=</span> <span class="no">nsteps</span>) <span class="no">param</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/param_seiqhrf.html">param_seiqhrf</a></span>(<span class="kw">act.rate.e</span> <span class="kw">=</span> <span class="no">act_rate</span>, <span class="kw">act.rate.i</span> <span class="kw">=</span> <span class="no">act_rate</span> * <span class="fl">0.5</span>) <span class="no">init</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/init_seiqhrf.html">init_seiqhrf</a></span>(<span class="kw">s.num</span> <span class="kw">=</span> <span class="no">s.num</span>, <span class="kw">i.num</span> <span class="kw">=</span> <span class="no">i.num</span>, <span class="kw">q.num</span> <span class="kw">=</span> <span class="no">q.num</span>, <span class="kw">h.num</span> <span class="kw">=</span> <span class="no">h.num</span>) <span class="no">sim_exp</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/seiqhrf.html">seiqhrf</a></span>(<span class="no">init</span>, <span class="no">control</span>, <span class="no">param</span>) <span class="co"># Experiment #2</span> <span class="no">vals</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">10</span>, <span class="fl">7</span>, <span class="fl">7</span>, <span class="fl">10</span>) <span class="no">timing</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">7</span>, <span class="fl">14</span>, <span class="fl">21</span>, <span class="fl">28</span>) <span class="no">act_rate_relax</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/vary_param.html">vary_param</a></span>(<span class="kw">nstep</span> <span class="kw">=</span> <span class="no">nsteps</span>, <span class="kw">vals</span> <span class="kw">=</span> <span class="no">vals</span>, <span class="kw">timing</span> <span class="kw">=</span> <span class="no">timing</span>) <span class="no">param</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/param_seiqhrf.html">param_seiqhrf</a></span>(<span class="kw">act.rate.e</span> <span class="kw">=</span> <span class="no">act_rate_relax</span>, <span class="kw">act.rate.i</span> <span class="kw">=</span> <span class="no">act_rate_relax</span> * <span class="fl">0.5</span>) <span class="no">sim_exp_relax</span> <span class="kw"><-</span> <span class="fu"><a href="../reference/seiqhrf.html">seiqhrf</a></span>(<span class="no">init</span>, <span class="no">control</span>, <span class="no">param</span>) <span class="co"># Compare experiments 1 and 2 to the baseline simulation</span> <span class="fu"><a href="https://rdrr.io/r/graphics/plot.html">plot</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span>(<span class="st">"Baseline"</span> <span class="kw">=</span> <span class="no">baseline_sim</span>, <span class="st">"Closures"</span> <span class="kw">=</span> <span class="no">sim_exp</span>, <span class="st">"Closures (2 mo)"</span> <span class="kw">=</span> <span class="no">sim_exp_relax</span>), <span class="kw">start_date</span> <span class="kw">=</span> <span class="kw pkg">lubridate</span><span class="kw ns">::</span><span class="fu"><a href="http://lubridate.tidyverse.org/reference/ymd.html">ymd</a></span>(<span class="st">"2020-01-01"</span>), <span class="kw">comp_remove</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">'s.num'</span>, <span class="st">'r.num'</span>), <span class="kw">plot_title</span> <span class="kw">=</span> <span class="st">'Closures Experiment'</span>) <span class="co">## Scale for 'colour' is already present. Adding another scale for 'colour',</span> <span class="co">## which will replace the existing scale.</span> <span class="co">## Warning: Removed 64 row(s) containing missing values (geom_path).</span></pre></body></html></div> <p><img src="sirplus_intro_v2_files/figure-html/Experiment%20example%20with%20act.rate-1.png" width="700"></p> <p>From these results we see that this policy would likely reduce the peak number of infections from 500 to 300 and would “flatten the curve” for infections and thus hospitalizations (the peak in number of infected people is lower, but the number of people infected declines more slowly after the peak of the epidemic than in the baseline model).</p> </div> <div id="visualize-sirplus-advanced-plotting-options" class="section level2"> <h2 class="hasAnchor"> <a href="#visualize-sirplus-advanced-plotting-options" class="anchor"></a>Visualize sirplus: Advanced Plotting Options</h2> <div id="a--adding-known-data" class="section level3"> <h3 class="hasAnchor"> <a href="#a--adding-known-data" class="anchor"></a>A. Adding known data</h3> <p>You can use the <code><a href="https://rdrr.io/r/graphics/plot.html">plot()</a></code> function to include known compartment values alongside your simulations by supplying the known values as a dataframe to parameter <code>known</code>. This can be helpful when wanting to know how well experiments are simulating the epidemic progression to the point where you have data.</p> <p>For example, if we know the hospitalization numbers have been growing exponentially (by 0.2) at each step, we can see how that compares to our experiments.</p> <div class="sourceCode" id="cb8"><html><body><pre class="r"><span class="no">known</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span>(<span class="st">'time'</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq</a></span>(<span class="fl">1</span>:<span class="fl">30</span>), <span class="st">'h.num'</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq</a></span>(<span class="fl">0</span>, <span class="fl">10</span>, <span class="kw">by</span><span class="kw">=</span><span class="fl">0.2</span>)[<span class="fl">1</span>:<span class="fl">30</span>]) <span class="fu"><a href="https://rdrr.io/r/graphics/plot.html">plot</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span>(<span class="st">"Baseline"</span> <span class="kw">=</span> <span class="no">baseline_sim</span>, <span class="st">"Closures"</span> <span class="kw">=</span> <span class="no">sim_exp</span>, <span class="st">"Closures (2 mo)"</span> <span class="kw">=</span> <span class="no">sim_exp_relax</span>), <span class="kw">time_lim</span> <span class="kw">=</span> <span class="fl">45</span>, <span class="kw">known</span> <span class="kw">=</span> <span class="no">known</span>, <span class="kw">start_date</span> <span class="kw">=</span> <span class="kw pkg">lubridate</span><span class="kw ns">::</span><span class="fu"><a href="http://lubridate.tidyverse.org/reference/ymd.html">ymd</a></span>(<span class="st">"2020-01-01"</span>), <span class="kw">comp_remove</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">'s.num'</span>, <span class="st">'r.num'</span>, <span class="st">'e.num'</span>, <span class="st">'i.num'</span>, <span class="st">'q.num'</span>), <span class="kw">plot_title</span> <span class="kw">=</span> <span class="st">'Closures Experiment'</span>) <span class="co">## Scale for 'colour' is already present. Adding another scale for 'colour',</span> <span class="co">## which will replace the existing scale.</span> <span class="co">## Warning: Removed 32 row(s) containing missing values (geom_path).</span></pre></body></html></div> <p><img src="sirplus_intro_v2_files/figure-html/sirplus%20plot%20with%20known-1.png" width="700"> From this, we can see that the closure for 2 months is slightly pessimistic, while the closures simulation is close to the known hospitalization rate.</p> </div> <div id="b--plotting-compartment-separately" class="section level3"> <h3 class="hasAnchor"> <a href="#b--plotting-compartment-separately" class="anchor"></a>B. Plotting compartment separately</h3> <p>You can use the <code><a href="https://rdrr.io/r/graphics/plot.html">plot()</a></code> function to plot counts for each compartment separately by specifying <code>sep_compartments</code> as ‘y’. This can be useful when visualizing compartments on different scales (e.g. i.num v f.num) without using log transformations.</p> <div class="sourceCode" id="cb9"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/graphics/plot.html">plot</a></span>(<span class="no">sim_exp</span>, <span class="kw">sep_compartments</span> <span class="kw">=</span> <span class="fl">TRUE</span>, <span class="kw">start_date</span> <span class="kw">=</span> <span class="kw pkg">lubridate</span><span class="kw ns">::</span><span class="fu"><a href="http://lubridate.tidyverse.org/reference/ymd.html">ymd</a></span>(<span class="st">"2020-01-01"</span>), <span class="kw">plot_title</span> <span class="kw">=</span> <span class="st">'Closures Experiment'</span>) <span class="co">## Scale for 'colour' is already present. Adding another scale for 'colour',</span> <span class="co">## which will replace the existing scale.</span> <span class="co">## Warning: Removed 5 row(s) containing missing values (geom_path).</span></pre></body></html></div> <p><img src="sirplus_intro_v2_files/figure-html/sirplus%20plot%20by%20compartment-1.png" width="700"></p> </div> <div id="c--weekly-hospitalization-numbers" class="section level3"> <h3 class="hasAnchor"> <a href="#c--weekly-hospitalization-numbers" class="anchor"></a>C. Weekly hospitalization numbers</h3> <p>Use the <code><a href="https://rdrr.io/r/graphics/plot.html">plot()</a></code> function with parameter <code>method = "weekly_local"</code> to extract and plot the number of weekly expected patients in a hospital. If <code>return_df</code> is <code>TRUE</code>, the function returns a dataframe that generates the plot, otherwise, it returns a ggplot object.</p> <p>This function takes the following input:</p> <ul> <li> <code>sims</code>: Single or list of outputs from simulate.seiqhrf().</li> <li> <code>market.share</code>: Percent of cases in your model population (s.num) that are anticipated at the hospital of interest. Default = 4% (0.04).</li> <li> <code>icu_percent</code>: Percent of hospitalised cases are are likely to need treatment in an intensive care unit (ICU). Default = 10% (0.1).</li> <li> <code>start_date</code>: Epidemic start date. Default is <code>NA</code>.</li> <li> <code>show_start_date</code>: First date to show in plots. Default is to show from beginning</li> <li> <code>time_lim</code>: Number of days (nsteps) to include. Default = 90.</li> <li> <code>total_population</code>: True population size. This parameter is only needed if the simulation size (s.num) was smaller than the true population size (i.e. scaled down) to reduce computational cost.</li> </ul> <div class="sourceCode" id="cb10"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/graphics/plot.html">plot</a></span>(<span class="no">baseline_sim</span>, <span class="kw">method</span> <span class="kw">=</span> <span class="st">"weekly_local"</span>, <span class="kw">time_lim</span> <span class="kw">=</span> <span class="fl">40</span>, <span class="kw">start_date</span> <span class="kw">=</span> <span class="fu">ymd</span>(<span class="st">"2020-01-01"</span>), <span class="kw">show_start_date</span> <span class="kw">=</span> <span class="fu">ymd</span>(<span class="st">"2020-01-06"</span>), <span class="kw">return_df</span> <span class="kw">=</span> <span class="fl">TRUE</span>) <span class="co">## $plot</span></pre></body></html></div> <p><img src="sirplus_intro_v2_files/figure-html/hospital%20visualization-1.png" width="700"></p> <pre><code>## ## $result ## # A tibble: 6 x 7 ## yr_wk h.num h.ci5 h.ci95 icu.num icu.ci5 icu.ci95 ## <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> ## 1 2020-01-06 14.5 4.66 27.9 1.61 0.518 3.10 ## 2 2020-01-13 54.4 36.1 72.4 6.05 4.01 8.04 ## 3 2020-01-20 192. 129. 241. 21.4 14.3 26.8 ## 4 2020-01-27 349. 299. 393. 38.8 33.2 43.6 ## 5 2020-02-03 361. 301. 413. 40.1 33.4 45.9 ## 6 2020-02-10 45.9 37.7 55.4 5.1 4.19 6.16</code></pre> </div> </div> </div> <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar"> <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2> </nav> </div> </div> <footer><div class="copyright"> <p>Developed by Christina Azodi, Puxue Qiao, Ruqian Lyu, Sam Tanner, Tim Churches, Davis McCarthy.</p> </div> <div class="pkgdown"> <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p> </div> </footer> </div> </body> </html>