<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Medicine on R Views</title>
    <link>https://rviews.rstudio.com/categories/medicine/</link>
    <description>Recent content in Medicine on R Views</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 19 Apr 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://rviews.rstudio.com/categories/medicine/" rel="self" type="application/rss+xml" />
    
    
    
    
    <item>
      <title>Multistate Models for Medical Applications</title>
      <link>https://rviews.rstudio.com/2023/04/19/multistate-models-for-medical-applications/</link>
      <pubDate>Wed, 19 Apr 2023 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2023/04/19/multistate-models-for-medical-applications/</guid>
      <description>
        


&lt;p&gt;Clinical research studies and healthcare economics studies are frequently concerned with assessing the prognosis for survival in circumstances where patients suffer from a disease that progresses from state to state. Standard survival models only directly model two states: alive and dead. Multi-state models enable directly modeling disease progression where patients are observed to be in various states of health or disease at random intervals, but for which, except for death, the times of entering or leaving states are unknown. Multi-state models easily accommodate &lt;a href=&#34;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3684949/#:~:text=In%20statistical%20literature%2C%20interval%20censoring,instead%20of%20being%20observed%20exactly.&#34;&gt;interval censored&lt;/a&gt; intermediate states while making the usual assumption that death times are known but may be &lt;a href=&#34;https://en.wikipedia.org/wiki/Censoring_(statistics)&#34;&gt;right censored&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A natural way to conceptualize modeling the dynamics of disease progression with interval censored states is as continuous time Markov chains. The following diagram illustrates a possible disease progression model where there is some possibility of dying from any state, but otherwise a patient would progress from being healthy, to mild disease, to severe disease and then perhaps death.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Loading required package: shape&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2023/04/19/multistate-models-for-medical-applications/index_files/figure-html/unnamed-chunk-1-1.png&#34; width=&#34;672&#34; /&gt;
It is true that in that the Markov assumption implies that the time patients spend in the various states are exponentially distributed. However, the mathematical theory of stochastic multi-state processes is very rich and can accommodate more realistic models with state dependent hazard rates that vary over time and other relaxations of the Markov assumption. Moreover, there is robust software in R (and other languages) that make multi-state stochastic survival models practical.&lt;/p&gt;
&lt;p&gt;In the remainder of this post, I present a variation of a disease progression model discussed by Ardo van den Hout in some detail in his incredibly informative and very readable monograph &lt;a href=&#34;https://www.routledge.com/Mult-i--State-Survival-Models-for-Interval-Censored-Data/Hout/p/book/9780367570569&#34;&gt;Multi-State Survival Models for Interval Censored Data&lt;/a&gt; . Also note that van den Hout’s model is itself an elaboration of the main example presented by Christopher Jackson in the &lt;a href=&#34;https://cran.r-project.org/web/packages/msm/vignettes/msm-manual.pdf&#34;&gt;vignette&lt;/a&gt; to his &lt;code&gt;msm&lt;/code&gt;package. This post presents a slower development of the model developed by Jackson and van den Hout that might be easier for a person not already familiar with the &lt;code&gt;msm&lt;/code&gt; package to follow.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse)
library(tidymodels)
library(msm)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;the-data&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;The Data&lt;/h3&gt;
&lt;p&gt;The data set explored by both Jackson and van den Hout is the Cardiac Allograft Vasculopathy (CAV) data set which contains the individual histories of angiographic examinations of 622 heart transplant recipients collected at the Papworth Hospital in the United Kingdom. This data is included in the &lt;code&gt;msm&lt;/code&gt; package and is a good candidate to be the &lt;em&gt;iris&lt;/em&gt; dataset for progressive disease models. It is a rich data set with 2846 rows and multiple covariates, including patient age and time time since transplant, both of which can be use for time scales, multiple state transitions among four states and no missing values. Observations of intermediate states are interval censored and have been recorded varying time intervals. Deaths are “exact” or right censored.&lt;/p&gt;
&lt;p&gt;The following code creates a new variable that preserves the original state data for each observation and displays the data in tibble format.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;set.seed(1234)
df &amp;lt;- tibble(cav) %&amp;gt;% mutate(o_state = state)

df&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## # A tibble: 2,846 × 11
##     PTNUM   age years  dage   sex pdiag cumrej state firstobs statemax o_state
##     &amp;lt;int&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;fct&amp;gt;  &amp;lt;int&amp;gt; &amp;lt;int&amp;gt;    &amp;lt;int&amp;gt;    &amp;lt;dbl&amp;gt;   &amp;lt;int&amp;gt;
##  1 100002  52.5  0       21     0 IHD        0     1        1        1       1
##  2 100002  53.5  1.00    21     0 IHD        2     1        0        1       1
##  3 100002  54.5  2.00    21     0 IHD        2     2        0        2       2
##  4 100002  55.6  3.09    21     0 IHD        2     2        0        2       2
##  5 100002  56.5  4       21     0 IHD        3     2        0        2       2
##  6 100002  57.5  5.00    21     0 IHD        3     3        0        3       3
##  7 100002  58.4  5.85    21     0 IHD        3     4        0        4       4
##  8 100003  29.5  0       17     0 IHD        0     1        1        1       1
##  9 100003  30.7  1.19    17     0 IHD        1     1        0        1       1
## 10 100003  31.5  2.01    17     0 IHD        1     3        0        3       3
## # ℹ 2,836 more rows&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The state table which presents the number of times each pair of states were observed in successive observation times shows that 46 transitions from state 2 (Mild CAV) to state 1 (No CAV), 4 transitions from state 3 (Severe CAV) to Healthy and 13 transitions from Severe CAV to Mild CAV.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;statetable.msm(state = state, subject = PTNUM, data = df)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##     to
## from    1    2    3    4
##    1 1367  204   44  148
##    2   46  134   54   48
##    3    4   13  107   55&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I will follow van den Hout and assume these backward transitions are misclassified and alter the state variable so there is no back sliding. The following code does this in a tidy way and also creates a new variable b_age which records the baseline age at which patients entered the study. (Note: you can find van den Hout’s code &lt;a href=&#34;https://www.ucl.ac.uk/~ucakadl/Book/Ch1_CAV_MsmAnalysis.r&#34;&gt;here&lt;/a&gt;)&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;df1 &amp;lt;- df %&amp;gt;% group_by(PTNUM) %&amp;gt;% 
                     mutate(b_age = min(age),
                            state = cummax(state)
                     )&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This transformation will make the state transition table conform to the diagram above, but with state 1 representing No CAV rather than Health.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;statetable.msm(state = state, subject = PTNUM, data = df1)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##     to
## from    1    2    3    4
##    1 1336  185   40  139
##    2    0  220   52   49
##    3    0    0  140   63&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;setting-up-and-running-the-model&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Setting Up and Running the Model&lt;/h3&gt;
&lt;p&gt;The next step is to set up the model using the function &lt;code&gt;msm()&lt;/code&gt; whose great flexibility means that some care must be taken to set parameter values.&lt;/p&gt;
&lt;p&gt;First, we set up the initial guess for the intensity matrix, Q, which determines the transition rates among states for a continuous time Markov chain. For the &lt;code&gt;msm&lt;/code&gt; function, positive values indicate possible transitions.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Intensity matrix Q:
q &amp;lt;- 0.01
Q &amp;lt;- rbind(c(0,q,0,q), c(0,0,q,q),c(0,0,0,q),c(0,0,0,0))
qnames &amp;lt;- c(&amp;quot;q12&amp;quot;,&amp;quot;q14&amp;quot;,&amp;quot;q23&amp;quot;,&amp;quot;q24&amp;quot;,&amp;quot;q34&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, we set up the covariate structure which van den Hout discusses in his monograph, but does not show in the code on the book’s website referenced above. For this model, transitions from state 1 to state 2 and from state 1 to state 4 depend on time,&lt;code&gt;years&lt;/code&gt;, the age of the patient at transplant time &lt;code&gt;b_age&lt;/code&gt;, and &lt;code&gt;dage&lt;/code&gt;, the age of the donor. The other transitions depend only on &lt;code&gt;dage&lt;/code&gt;. So, we see that &lt;code&gt;msm()&lt;/code&gt; can deal with time varying covariates as well as permitting individual state transitions to be driven by different covariates.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;covariates = list(&amp;quot;1-2&amp;quot; = ~ years + b_age + dage , 
                  &amp;quot;1-4&amp;quot; = ~ years + b_age + dage ,
                  &amp;quot;2-3&amp;quot; = ~ dage,
                  &amp;quot;2-4&amp;quot; = ~ dage,
                  &amp;quot;3-4&amp;quot; = ~ dage)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, we set the remaining parameters for the model.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;obstype &amp;lt;- 1
center &amp;lt;- FALSE
deathexact &amp;lt;- TRUE
method &amp;lt;- &amp;quot;BFGS&amp;quot;
control &amp;lt;- list(trace = 0, REPORT = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;obstype = 1&lt;/strong&gt; indicates that observations have been taken at arbitrary time points. They are &lt;em&gt;snapshots&lt;/em&gt; of the process that are common for panel data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;center = FALSE&lt;/strong&gt; means that covariates will not be centered at their means during the maximum likelihood estimation process. The default for this parameter is TRUE.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;deathexact = TRUE&lt;/strong&gt; indicates that the final absorbing state is exactly observed. This is the defining assumption survival data. In &lt;code&gt;msm&lt;/code&gt; this is equivalent to setting obstupe = 3 for state 4, our absorbing state.&lt;/p&gt;
&lt;p&gt;** method = BFGS** signals &lt;code&gt;optim()&lt;/code&gt; to use the optimization method published simultaneously in 1970 by Broyden, Fletcher, Goldfarb and Shanno. (look &lt;a href=&#34;https://en.wikipedia.org/wiki/Charles_George_Broyden&#34;&gt;here&lt;/a&gt;). This is a quasi-Newton method that uses function values and gradients to build up a picture of the surface to be optimized.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;control = list(trace=0,REPORT=1)&lt;/strong&gt; indicates more parameters that will be passed to &lt;code&gt;optim()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;REPORT&lt;/strong&gt; sets the the frequency of reports for the “BFGS”, “L-BFGS-B” and “SANN” methods if control$trace is positive. Defaults to every 10 iterations for “BFGS” and “L-BFGS-B”, or every 100 temperatures for “SANN”. (Note: SANN is a variant of the simulated annealing method presented by C. J. P. Belisle (1992) &lt;em&gt;Convergence theorems for a class of simulated annealing algorithms on R&lt;sup&gt;d&lt;/sup&gt;&lt;/em&gt; Journal of Applied Probability.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;trace&lt;/strong&gt; is also passed to&lt;code&gt;optim()&lt;/code&gt;. trace must be a non-negative integer. If positive, tracing information on the progress of the optimization is produced. Higher values may produce more tracing information.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model_1 &amp;lt;- msm(state~years, subject = PTNUM, data = df1, center= center, 
             qmatrix=Q, obstype = obstype, deathexact = deathexact, method = method,
             covariates = covariates, control = control)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First check to see if the model has converged. For the BFGS method, possible convergence codes returned by &lt;code&gt;optim()&lt;/code&gt; are:
0 indicates convergence, 1 indicates that the maximum iteration limit has been reached, 51 and 52 indicate warnings.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;#Model Status
conv &amp;lt;- model_1$opt$convergence; cat(&amp;quot;Convergence code =&amp;quot;, conv,&amp;quot;\n&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Convergence code = 0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, look at a measure of how well the model fits the data proposed by using a visual test proposed by &lt;a href=&#34;https://onlinelibrary.wiley.com/doi/10.1002/sim.4780130803&#34;&gt;Gentleman et al. (1994)&lt;/a&gt; which plots the observed numbers of individuals occupying a state at a series of times against forecasts from the fitted model, for each state. The &lt;code&gt;msm&lt;/code&gt; function &lt;code&gt;plot.prevalence.msm()&lt;/code&gt; produces a perfectly adequate base R plot. However, to emphasize that &lt;code&gt;msm&lt;/code&gt; users are not limited to base R plots, I’ll do a little extra work to use &lt;code&gt;ggplot()&lt;/code&gt;. When a package author is kind enough to provide an extractor function you can do anything you want with the data.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;prevalence.msm()&lt;/code&gt; function extracts both the observed and forecast prevalence matrices.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;prev &amp;lt;- prevalence.msm(model_1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This not very elegant, but straightforward code reshapes the data and plots.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# reshape observed prevalence
do1 &amp;lt;-as_tibble(row.names(prev$Observed)) %&amp;gt;% rename(time = value) %&amp;gt;% 
          mutate(time = as.numeric(time))
do2 &amp;lt;-as_tibble(prev$Observed) %&amp;gt;% mutate(type = &amp;quot;observed&amp;quot;)
do &amp;lt;- cbind(do1,do2) %&amp;gt;% select(-Total)
do_l &amp;lt;- do %&amp;gt;% gather(state, number, -time, -type)
# reshape expected prevalence
de1 &amp;lt;-as_tibble(row.names(prev$Expected)) %&amp;gt;% rename(time = value) %&amp;gt;% 
          mutate(time = as.numeric(time))
de2 &amp;lt;-as_tibble(prev$Expected) %&amp;gt;% mutate(type = &amp;quot;expected&amp;quot;)
de &amp;lt;- cbind(de1,de2) %&amp;gt;% select(-Total) 
de_l &amp;lt;- de %&amp;gt;% gather(state, number, -time, -type) 

# bind into a single data frame
prev_l &amp;lt;-rbind(do_l,de_l) %&amp;gt;% mutate(type = factor(type),
                                     state = factor(state),
                                     time = round(time,3))


# plot for comparison
prev_gp &amp;lt;- prev_l %&amp;gt;% group_by(state)
pp &amp;lt;- prev_l %&amp;gt;% ggplot() +
     geom_line(aes(time, number, color = type)) +
     xlab(&amp;quot;time&amp;quot;) +
     ylab(&amp;quot;&amp;quot;) +
     ggtitle(&amp;quot;&amp;quot;)
pp + facet_wrap(~state)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2023/04/19/multistate-models-for-medical-applications/index_files/figure-html/unnamed-chunk-13-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The agreement of the observed and forecast prevalence for states 1 through 3 look pretty good. After about 8 years the observed deaths are notably higher than the forecast. As Jackson points out (See the &lt;a href=&#34;https://cran.r-project.org/web/packages/msm/vignettes/msm-manual.pdf&#34;&gt;msm Manual&lt;/a&gt; page 33), this kind of discrepancy could indicate that the underlying process is not homogeneous. I have attempted to capture this non-homogeneity by having some of the transitions depend on time. And, although the plot above looks a little better that than the plot in the manual, which does not attempt to model non-homogeneity, it is apparent that there is room to find a better model!&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;survival-curves-and-calculations&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Survival Curves and Calculations&lt;/h3&gt;
&lt;p&gt;Now, we can jump straight to the major result and look at the fitted survival curves. There is a &lt;code&gt;plot()&lt;/code&gt; method for &lt;code&gt;msm&lt;/code&gt; that will directly plot these curves. However, just to emphasize that if a package author is kind enough to provide a &lt;code&gt;plot&lt;/code&gt; method, it will probably not be too difficult to hack the code for the method to use an alternative plotting system. To save space, I will not show my code, but you can easily recreate it by stating with the &lt;code&gt;plot.msm()&lt;/code&gt; function, deleting the plotting parts and returning the values for time and the states “Health, Mild_CAV, and Severe_CAV which are used int the code below. Check my hack by running &lt;code&gt;plot(model_1)&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# plot_prep was obtained from plot.msm()
res &amp;lt;- plot_prep(model_1)
time &amp;lt;- res[[1]]
Health &amp;lt;- res[[2]]
Mild_CAV &amp;lt;- res[[3]]
Severe_CAV &amp;lt;- res[[4]]
df_w &amp;lt;- tibble(time,Health, Mild_CAV, Severe_CAV)
df_l &amp;lt;- df_w %&amp;gt;% gather(&amp;quot;state&amp;quot;, &amp;quot;survival&amp;quot;, -time)
p &amp;lt;- df_l %&amp;gt;% ggplot(aes(time, 1 - survival, group = state)) +
     geom_line(aes(color = state)) +
     xlab(&amp;quot;Years&amp;quot;) +
     ylab(&amp;quot;Probability&amp;quot;) +
     ggtitle(&amp;quot;Fitted Survival Probabilities&amp;quot;)
p&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2023/04/19/multistate-models-for-medical-applications/index_files/figure-html/unnamed-chunk-15-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;These curves indicate that a treatment that could prevent CAV or at least delay progression from mild CAV to severe CAV might prolong survival. Additionally, the Markov structure of the model permits extracting information that relates to disease progression and the total time spent in each state.&lt;/p&gt;
&lt;p&gt;The function &lt;code&gt;totlos.msm()&lt;/code&gt; estimates the total expected time that a patient will spend in each state. Parameter settings for this function include:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;start&lt;/strong&gt; = c(1,0,0,0) specifies that patients will start in state 1 with probability 0.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;fromt&lt;/strong&gt; = 0 indicates starting at the beginning of the process.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;covariates&lt;/strong&gt; = “mean” indicates that the covariates will be set to their mean values for the calculation.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;total_state_time &amp;lt;-totlos.msm(model_1,start = c(1,0,0,0), from = 0, covariates = &amp;quot;mean&amp;quot;)
total_state_time&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## State 1 State 2 State 3 State 4 
##   7.002   2.473   1.621     Inf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The table indicates that the mean time a patient can expect to avoid CAV is about 7 years. After progressing to a Mild_CAV, a patient can expect five additional years.&lt;/p&gt;
&lt;p&gt;A more direct calculation based on the intensity matrix, Q, give the expected time to the “absorbing” state, Death, from each of the “transient” living states.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;time_to_death &amp;lt;- efpt.msm(model_1, tostate = 4, covariates = &amp;quot;mean&amp;quot;)
time_to_death&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 11.097  5.836  3.005  0.000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This agrees with the total state times calculated above.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;sum(total_state_time[1:3])&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 11.1&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within the scope of the information provided by the covariates, it is also possible to generate more individualized forecasts. For example, here is the expected time to death for a person starting off with no CAV at age 60, who received a heart from a 20 year old donor, 5 years after the transplant.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;efpt.msm(model_1, tostate = 4, start = c(1,0,0,0), covariates = list(years = 5, b_age = 60, dage = 20))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##       [,1]
## [1,] 7.953&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A related quantity, mean sojourn time, is the mean time that each visit to each state is expected to last. Since, we are assuming a progressive disease model where each patient visits each state only once, the estimate should be close to total time spent in each state. However, Jackson notes that in a progressive model, sojourn time in the disease state will be greater than the expected length of stay in the disease state because the mean sojourn time in a state is conditional on entering the state, whereas the expected total time in a diseased state is a forecast for an individual, who may die before getting the disease. (See help(totlos.msm)). And indeed, that is what we see here for states 2 and 3.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;sojourn.msm(model_1, covariates=&amp;quot;mean&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         estimates     SE     L     U
## State 1     7.002 0.4024 6.256 7.837
## State 2     3.525 0.3020 2.980 4.169
## State 3     3.005 0.3748 2.353 3.837&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;hazard-ratios&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Hazard Ratios&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;model_1&lt;/code&gt; will also product estimates of hazard ratios which show the estimate effect on transition intensities for each state.&lt;/p&gt;
&lt;p&gt;Here is the table of Hazard Ratios:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model_1&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 
## Call:
## msm(formula = state ~ years, subject = PTNUM, data = df1, qmatrix = Q,     obstype = obstype, covariates = covariates, deathexact = deathexact,     center = center, method = method, control = control)
## 
## Maximum likelihood estimates
## Baselines are with covariates set to 0
## 
## Transition intensities with hazard ratios for each covariate
##                   Baseline                         years              
## State 1 - State 1 -0.032750 (-0.0607897,-0.017644)                    
## State 1 - State 2  0.030957 ( 0.0160470, 0.059721) 1.112 (1.061,1.166)
## State 1 - State 4  0.001793 ( 0.0004703, 0.006836) 1.093 (1.012,1.182)
## State 2 - State 2 -0.395633 (-0.6488723,-0.241227)                    
## State 2 - State 3  0.264310 ( 0.1488153, 0.469441) 1.000              
## State 2 - State 4  0.131323 ( 0.0330133, 0.522385) 1.000              
## State 3 - State 3 -0.434548 (-0.9113857,-0.207192)                    
## State 3 - State 4  0.434548 ( 0.2071918, 0.911386) 1.000              
##                   b_age                dage                 
## State 1 - State 1                                           
## State 1 - State 2 1.001 (0.9884,1.014) 1.0281 (1.0159,1.040)
## State 1 - State 4 1.053 (1.0271,1.079) 1.0208 (1.0039,1.038)
## State 2 - State 2                                           
## State 2 - State 3 1.000                0.9932 (0.9756,1.011)
## State 2 - State 4 1.000                0.9757 (0.9298,1.024)
## State 3 - State 3                                           
## State 3 - State 4 1.000                0.9906 (0.9672,1.015)
## 
## -2 * log-likelihood:  3466&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The table shows that time, the covariate &lt;code&gt;years&lt;/code&gt;, affects disease progression represented by the the transition from state 1 to state 2, but has a smaller effect on the transition from state 1 to state 4.&lt;/p&gt;
&lt;p&gt;The covariate &lt;code&gt;b_age&lt;/code&gt;, the baseline age of patient at transplant time has a larger effect on dying before the onset of CAV than on the transition to CAV.&lt;/p&gt;
&lt;p&gt;The covariate &lt;code&gt;dage&lt;/code&gt; has a minor effect on the transitions from state 1 but apparently has no effect thereafter.&lt;/p&gt;
&lt;p&gt;The hazard ratios are computed by calculating the exponential of the estimated covariate effects on the log-transition intensities for the Markov process which are stored in the model object.&lt;/p&gt;
&lt;p&gt;To see how these work, first look at the baseline hazard ratios.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model_1$Qmatrices$baseline&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##          State 1  State 2 State 3  State 4
## State 1 -0.03275  0.03096  0.0000 0.001793
## State 2  0.00000 -0.39563  0.2643 0.131323
## State 3  0.00000  0.00000 -0.4345 0.434548
## State 4  0.00000  0.00000  0.0000 0.000000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These baseline hazard ratios are computed from the model intensity matrix, Q, assuming no covariates. They can also be directly extracted from the model by &lt;code&gt;qmatrix.msm()&lt;/code&gt; extractor function with covariates set to zero.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;qmatrix.msm(model_1,  covariates = 0)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1                          State 2                         
## State 1 -0.032750 (-0.0607897,-0.017644)  0.030957 ( 0.0160470, 0.059721)
## State 2 0                                -0.395633 (-0.6488723,-0.241227)
## State 3 0                                0                               
## State 4 0                                0                               
##         State 3                          State 4                         
## State 1 0                                 0.001793 ( 0.0004703, 0.006836)
## State 2  0.264310 ( 0.1488153, 0.469441)  0.131323 ( 0.0330133, 0.522385)
## State 3 -0.434548 (-0.9113857,-0.207192)  0.434548 ( 0.2071918, 0.911386)
## State 4 0                                0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The 95% confidence limits are computed by assuming normality of the log-effect.&lt;/p&gt;
&lt;p&gt;A more representative value for the intensity matrix for this model can be obtained by setting the covariates to their expected mean values.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;qmatrix.msm(model_1,  covariates = &amp;quot;mean&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1                      State 2                     
## State 1 -0.14281 (-0.15984,-0.12760)  0.10019 ( 0.08742, 0.11482)
## State 2 0                            -0.28369 (-0.33556,-0.23984)
## State 3 0                            0                           
## State 4 0                            0                           
##         State 3                      State 4                     
## State 1 0                             0.04262 ( 0.03339, 0.05441)
## State 2  0.21821 ( 0.17636, 0.26999)  0.06548 ( 0.03872, 0.11075)
## State 3 -0.33281 (-0.42498,-0.26064)  0.33281 ( 0.26064, 0.42498)
## State 4 0                            0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, we may want to examine the contribution of the covariate covariates to the hazard ratios. To take a particular example, look at the &lt;code&gt;dage&lt;/code&gt; to the hazard ratios&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model_1$Qmatrices$dage&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1 State 2   State 3   State 4
## State 1       0 0.02771  0.000000  0.020575
## State 2       0 0.00000 -0.006783 -0.024625
## State 3       0 0.00000  0.000000 -0.009439
## State 4       0 0.00000  0.000000  0.000000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and focus on the contribution of &lt;code&gt;dage&lt;/code&gt; to the intensity matrix for the transition from state 3 to state 4 which is given as -0.009439 in the table above. Taking the exponential of this value, yields the hazard ratio for the &lt;code&gt;dage&lt;/code&gt; state 3 to 4 transition in the hazard ratio’s table we got by printing out &lt;code&gt;model_1&lt;/code&gt; above.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;exp(-.009439)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 0.9906&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The hazard ratio tables for the remaining covariates are given by:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model_1$Qmatrices$years&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1 State 2 State 3 State 4
## State 1       0  0.1064       0 0.08933
## State 2       0  0.0000       0 0.00000
## State 3       0  0.0000       0 0.00000
## State 4       0  0.0000       0 0.00000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model_1$Qmatrices$b_age&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1   State 2 State 3 State 4
## State 1       0 0.0009645       0 0.05152
## State 2       0 0.0000000       0 0.00000
## State 3       0 0.0000000       0 0.00000
## State 4       0 0.0000000       0 0.00000&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;exploring-transition-probabilities-and-intensities&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Exploring Transition Probabilities and Intensities&lt;/h3&gt;
&lt;p&gt;It is also possible to look at the state transition matrix at different times and see how these probabilities change over time. Here we compute the transition matrix at 1 year.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pmatrix.msm(model_1, t = 1, covariates = &amp;quot;mean&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1 State 2  State 3 State 4
## State 1  0.8669 0.08101 0.008493 0.04357
## State 2  0.0000 0.75300 0.160340 0.08666
## State 3  0.0000 0.00000 0.716903 0.28310
## State 4  0.0000 0.00000 0.000000 1.00000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and at 5 years.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pmatrix.msm(model_1, t = 5, covariates = &amp;quot;mean&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1 State 2 State 3 State 4
## State 1  0.4897  0.1761 0.07871  0.2556
## State 2  0.0000  0.2421 0.23419  0.5237
## State 3  0.0000  0.0000 0.18937  0.8106
## State 4  0.0000  0.0000 0.00000  1.0000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Additionally, it is possible to examine the effect of covariates on transition probabilities. Here are the 5 year transition probabilities for a patient with a baseline age of 35.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pmatrix.msm(model_1, t = 5, covariates = list(years = 5, b_age = 35, dage = 20))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1 State 2 State 3 State 4
## State 1  0.5474  0.1674 0.07575  0.2095
## State 2  0.0000  0.2112 0.21622  0.5726
## State 3  0.0000  0.0000 0.16547  0.8345
## State 4  0.0000  0.0000 0.00000  1.0000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and those who had the procedure at age 60.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pmatrix.msm(model_1, t = 5, covariates = list(years = 5, b_age = 60, dage = 20))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         State 1 State 2 State 3 State 4
## State 1  0.3863  0.1409 0.06784  0.4050
## State 2  0.0000  0.2112 0.21622  0.5726
## State 3  0.0000  0.0000 0.16547  0.8345
## State 4  0.0000  0.0000 0.00000  1.0000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the transitions from CAV states are unaffected.&lt;/p&gt;
&lt;p&gt;To summarize: Continuous Time Markov Chains provide a natural framework for working with multi-state survival models. The &lt;code&gt;msm&lt;/code&gt; package is sufficiently sophisticated to permit modeling clinical process with level of fidelity that may provide insight about clinically observed disease progression. The software is relatively easy to use and there is plenty of documentation to help you get started.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;learning-more-about-multi-state-survival-models&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Learning More About Multi-State Survival Models&lt;/h3&gt;
&lt;p&gt;To dive deeper into multi-state survival models, I am sure you will find Ardo van den Hout’ &lt;a href=&#34;https://www.routledge.com/Multi-State-Survival-Models-for-Interval-Censored-Data/Hout/p/book/9780367570569&#34;&gt;Multi-State Survival Models for Interval-Censored Data&lt;/a&gt; extraordinarily helpful. There are many good textbooks about the basics of Continuous Time Markov Chains. I recommend J.R.Norris’ - &lt;a href=&#34;https://www.cambridge.org/core/books/markov-chains/A3F966B10633A32C8F06F37158031739&#34;&gt;Markov Chains&lt;/a&gt; which is still modestly priced. There are also many expositions freely available on the internet including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;David F. Anderson - &lt;a href=&#34;https://u.math.biu.ac.il/~amirgi/CTMCnotes.pdf&#34;&gt;Chapter 6: Continuous Time Markov Chains&lt;/a&gt; from &lt;a href=&#34;https://u.math.biu.ac.il/~amirgi/SBA.pdf&#34;&gt;Lecture Notes on Stochastic Processes with Applications in Biology&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Miranda Holmes-Cerfon - &lt;a href=&#34;https://cims.nyu.edu/~holmes/teaching/asa19/handout_Lecture4_2019.pdf&#34;&gt;Lecture 4: Continuous-time Markov Chains&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Søren Feodor Nielsen - &lt;a href=&#34;http://web.math.ku.dk/~susanne/kursusstokproc/ContinuousTime.pdf&#34;&gt;Continuous-time homogeneous Markov chains&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Karl Sigman - &lt;a href=&#34;http://www.columbia.edu/~ks20/stochastic-I/stochastic-I-CTMC.pdf&#34;&gt;Continuous-Time Markov Chains&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2023/04/19/multistate-models-for-medical-applications/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>The COVID19 package, an interface to the COVID-19 Data Hub</title>
      <link>https://rviews.rstudio.com/2021/12/08/the-r-package-covid19/</link>
      <pubDate>Wed, 08 Dec 2021 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2021/12/08/the-r-package-covid19/</guid>
      <description>
        
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;/2021/12/08/the-r-package-covid19/index_files/dygraphs/dygraph.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/dygraphs/dygraph-combined.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/dygraphs/shapes.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/moment/moment.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/moment-timezone/moment-timezone-with-data.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/moment-fquarter/moment-fquarter.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/12/08/the-r-package-covid19/index_files/dygraphs-binding/dygraphs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;&lt;img src=&#34;logo.png&#34; style=&#34;float:right&#34; height=&#34;128&#34; width = &#34;128&#34; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://cran.r-project.org/package=COVID19&#34;&gt;&lt;img src=&#34;https://www.r-pkg.org/badges/version/COVID19&#34; style=&#34;display:inline-block&#34;/&gt;&lt;/a&gt;
&lt;a href=&#34;https://cran.r-project.org/package=COVID19&#34;&gt;&lt;img src=&#34;https://cranlogs.r-pkg.org/badges/last-month/COVID19&#34; style=&#34;display:inline-block&#34;/&gt;&lt;/a&gt;
&lt;a href=&#34;https://doi.org/10.21105/joss.02376&#34;&gt;&lt;img src=&#34;https://joss.theoj.org/papers/10.21105/joss.02376/status.svg&#34; style=&#34;display:inline-block&#34;/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://covid19datahub.io&#34;&gt;COVID-19 Data Hub&lt;/a&gt; provides a daily summary of COVID-19 cases, deaths, recovered, tests, vaccinations, and hospitalizations for 230+ countries, 760+ regions, and 12000+ administrative divisions of lower level. It includes policy measures, mobility, and geospatial data. This post presents version 3.0.0 of the &lt;code&gt;COVID19&lt;/code&gt; package to seamlessly import the data in R.&lt;/p&gt;
&lt;div id=&#34;why-another-package-for-covid-19-data&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Why another package for COVID-19 data&lt;/h2&gt;
&lt;p&gt;Many packages now exist to retrieve COVID-19 related data from within R. As an example, &lt;a href=&#34;https://cran.r-project.org/package=covid19br&#34;&gt;covid19br&lt;/a&gt; retrieves case data for Brazil, &lt;a href=&#34;https://cran.r-project.org/package=covid19sf&#34;&gt;covid19sf&lt;/a&gt; for San Francisco, &lt;a href=&#34;https://cran.r-project.org/package=covid19us&#34;&gt;covid19us&lt;/a&gt; for United States, &lt;a href=&#34;https://cran.r-project.org/package=covid19india&#34;&gt;covid19india&lt;/a&gt; for India, &lt;a href=&#34;https://cran.r-project.org/package=covid19italy&#34;&gt;covid19italy&lt;/a&gt; for Italy, &lt;a href=&#34;https://cran.r-project.org/package=covid19swiss&#34;&gt;covid19swiss&lt;/a&gt; for Switzerland, &lt;a href=&#34;https://cran.r-project.org/package=covid19france&#34;&gt;covid19france&lt;/a&gt; for France, and so on. There also other packages, such as &lt;a href=&#34;https://cran.r-project.org/package=coronavirus&#34;&gt;coronavirus&lt;/a&gt;, that retrieve national-level statistics worldwide from the Center for Systems Science and Engineering at Johns Hopkins University (JHU CCSE). However, national counts only represent a small portion of the available governmental data, and having the information scattered across many packages and different interfaces makes international comparisons of large, detailed outbreak data difficult, and prevents
inferences from such data to be effective.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;COVID19&lt;/code&gt; is the official package created around &lt;a href=&#34;https://covid19datahub.io&#34;&gt;COVID-19 Data Hub&lt;/a&gt;: a unified database harmonizing open governmental data around the globe at fine-grained spatial resolution. Moreover, as epidemiological data alone are typically of limited use, the database includes a set of identifiers to match the epidemiological data with exogenous indicators and geospatial information. By unifying the access to the data, this database makes it possible to study the pandemic in its global scale with high resolution, taking into account within-country variations, non pharmaceutical interventions, and environmental and exogenous variables.&lt;/p&gt;
&lt;p&gt;In particular, this package allows you to download a large set of &lt;a href=&#34;https://covid19datahub.io/articles/docs.html#epidemiological-variables&#34;&gt;epidemiological variables&lt;/a&gt;, exogenous indicators from &lt;a href=&#34;https://data.worldbank.org/&#34;&gt;World Bank&lt;/a&gt;, mobility data from &lt;a href=&#34;https://www.google.com/covid19/mobility/&#34;&gt;Google&lt;/a&gt; and &lt;a href=&#34;https://www.apple.com/covid19/mobility&#34;&gt;Apple&lt;/a&gt; mobility reports, and geospatial information from &lt;a href=&#34;https://ec.europa.eu/eurostat/web/nuts/nuts-maps&#34;&gt;Eurostat&lt;/a&gt; for Europe or &lt;a href=&#34;https://gadm.org/&#34;&gt;GADM&lt;/a&gt; worldwide, in, literally, one line of code.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;whats-new-in-version-3.0.0&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;What’s new in version 3.0.0&lt;/h2&gt;
&lt;p&gt;Version 3 is a major update of COVID-19 Data Hub, which includes a great improvement in the spatial coverage, new data on vaccines, and a new set of identifiers to enable geospatial analyses. The full changelog is available &lt;a href=&#34;https://covid19datahub.io/news/index.html&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The large amount of data that is now available (~2GB) has led to some breaking changes in the way the data are provided. Version 3 of the &lt;code&gt;COVID19&lt;/code&gt; package is designed to be compatible with the latest version of COVID-19 Data Hub, and process large amount of data at speed with low memory requirements. The documentation and a quick start guide is available &lt;a href=&#34;https://covid19datahub.io/articles/r.html&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;data-coverage&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Data coverage&lt;/h2&gt;
&lt;p&gt;The figure shows the granularity and the spatial coverage of the data as of November 27, 2021.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;main.png&#34; /&gt;&lt;/p&gt;
&lt;p&gt;What’s included?&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(COVID19)  # load the package
x &amp;lt;- covid19()    # download the data&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Refer to the &lt;a href=&#34;https://covid19datahub.io/articles/docs.html&#34;&gt;documentation&lt;/a&gt; for the description of each variable.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;colnames(x)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##  [1] &amp;quot;id&amp;quot;                                  &amp;quot;date&amp;quot;                               
##  [3] &amp;quot;confirmed&amp;quot;                           &amp;quot;deaths&amp;quot;                             
##  [5] &amp;quot;recovered&amp;quot;                           &amp;quot;tests&amp;quot;                              
##  [7] &amp;quot;vaccines&amp;quot;                            &amp;quot;people_vaccinated&amp;quot;                  
##  [9] &amp;quot;people_fully_vaccinated&amp;quot;             &amp;quot;hosp&amp;quot;                               
## [11] &amp;quot;icu&amp;quot;                                 &amp;quot;vent&amp;quot;                               
## [13] &amp;quot;school_closing&amp;quot;                      &amp;quot;workplace_closing&amp;quot;                  
## [15] &amp;quot;cancel_events&amp;quot;                       &amp;quot;gatherings_restrictions&amp;quot;            
## [17] &amp;quot;transport_closing&amp;quot;                   &amp;quot;stay_home_restrictions&amp;quot;             
## [19] &amp;quot;internal_movement_restrictions&amp;quot;      &amp;quot;international_movement_restrictions&amp;quot;
## [21] &amp;quot;information_campaigns&amp;quot;               &amp;quot;testing_policy&amp;quot;                     
## [23] &amp;quot;contact_tracing&amp;quot;                     &amp;quot;facial_coverings&amp;quot;                   
## [25] &amp;quot;vaccination_policy&amp;quot;                  &amp;quot;elderly_people_protection&amp;quot;          
## [27] &amp;quot;government_response_index&amp;quot;           &amp;quot;stringency_index&amp;quot;                   
## [29] &amp;quot;containment_health_index&amp;quot;            &amp;quot;economic_support_index&amp;quot;             
## [31] &amp;quot;administrative_area_level&amp;quot;           &amp;quot;administrative_area_level_1&amp;quot;        
## [33] &amp;quot;administrative_area_level_2&amp;quot;         &amp;quot;administrative_area_level_3&amp;quot;        
## [35] &amp;quot;latitude&amp;quot;                            &amp;quot;longitude&amp;quot;                          
## [37] &amp;quot;population&amp;quot;                          &amp;quot;iso_alpha_3&amp;quot;                        
## [39] &amp;quot;iso_alpha_2&amp;quot;                         &amp;quot;iso_numeric&amp;quot;                        
## [41] &amp;quot;iso_currency&amp;quot;                        &amp;quot;key_local&amp;quot;                          
## [43] &amp;quot;key_google_mobility&amp;quot;                 &amp;quot;key_apple_mobility&amp;quot;                 
## [45] &amp;quot;key_jhu_csse&amp;quot;                        &amp;quot;key_nuts&amp;quot;                           
## [47] &amp;quot;key_gadm&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;data-transparency&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Data transparency&lt;/h2&gt;
&lt;p&gt;This package applies no pre-processing to the original data, that are provided as-is. The data acquisition pipeline is open source and all the original data providers are listed &lt;a href=&#34;https://covid19datahub.io/reference/index.html&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As an example, the following code snippet plots the fraction of confirmed cases on a given day per number of tests performed on that day in U.S. Notice that around June 2021, the fraction becomes negative. This is a known issue due to decreasing cumulative counts in the original data provider. This package applies no cleaning procedure for this kind of issues, which are typically due to changes in the data collection methodology. If the provider corrects the data retroactively, the changes are reflected in this package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(xts)
library(dygraphs)
x &amp;lt;- covid19(&amp;quot;USA&amp;quot;, verbose = FALSE)  # download the data
ts &amp;lt;- xts(x[,c(&amp;quot;confirmed&amp;quot;, &amp;quot;tests&amp;quot;)], order.by = x$date)  # convert to an xts object
ts$ratio &amp;lt;- diff(ts$confirmed) / diff(ts$tests)  # compute daily ratio
dygraph(ts$ratio, main = &amp;quot;Daily fraction confirmed/tests in U.S.&amp;quot;)  # plot&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:672px;height:480px;&#34; class=&#34;dygraphs html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;attrs&#34;:{&#34;title&#34;:&#34;Daily fraction confirmed/tests in U.S.&#34;,&#34;labels&#34;:[&#34;day&#34;,&#34;ratio&#34;],&#34;legend&#34;:&#34;auto&#34;,&#34;retainDateWindow&#34;:false,&#34;axes&#34;:{&#34;x&#34;:{&#34;pixelsPerLabel&#34;:60}}},&#34;scale&#34;:&#34;daily&#34;,&#34;annotations&#34;:[],&#34;shadings&#34;:[],&#34;events&#34;:[],&#34;format&#34;:&#34;date&#34;,&#34;data&#34;:[[&#34;2020-01-21T00:00:00.000Z&#34;,&#34;2020-01-22T00:00:00.000Z&#34;,&#34;2020-01-23T00:00:00.000Z&#34;,&#34;2020-01-24T00:00:00.000Z&#34;,&#34;2020-01-25T00:00:00.000Z&#34;,&#34;2020-01-26T00:00:00.000Z&#34;,&#34;2020-01-27T00:00:00.000Z&#34;,&#34;2020-01-28T00:00:00.000Z&#34;,&#34;2020-01-29T00:00:00.000Z&#34;,&#34;2020-01-30T00:00:00.000Z&#34;,&#34;2020-01-31T00:00:00.000Z&#34;,&#34;2020-02-01T00:00:00.000Z&#34;,&#34;2020-02-02T00:00:00.000Z&#34;,&#34;2020-02-03T00:00:00.000Z&#34;,&#34;2020-02-04T00:00:00.000Z&#34;,&#34;2020-02-05T00:00:00.000Z&#34;,&#34;2020-02-06T00:00:00.000Z&#34;,&#34;2020-02-07T00:00:00.000Z&#34;,&#34;2020-02-08T00:00:00.000Z&#34;,&#34;2020-02-09T00:00:00.000Z&#34;,&#34;2020-02-10T00:00:00.000Z&#34;,&#34;2020-02-11T00:00:00.000Z&#34;,&#34;2020-02-12T00:00:00.000Z&#34;,&#34;2020-02-13T00:00:00.000Z&#34;,&#34;2020-02-14T00:00:00.000Z&#34;,&#34;2020-02-15T00:00:00.000Z&#34;,&#34;2020-02-16T00:00:00.000Z&#34;,&#34;2020-02-17T00:00:00.000Z&#34;,&#34;2020-02-18T00:00:00.000Z&#34;,&#34;2020-02-19T00:00:00.000Z&#34;,&#34;2020-02-20T00:00:00.000Z&#34;,&#34;2020-02-21T00:00:00.000Z&#34;,&#34;2020-02-22T00:00:00.000Z&#34;,&#34;2020-02-23T00:00:00.000Z&#34;,&#34;2020-02-24T00:00:00.000Z&#34;,&#34;2020-02-25T00:00:00.000Z&#34;,&#34;2020-02-26T00:00:00.000Z&#34;,&#34;2020-02-27T00:00:00.000Z&#34;,&#34;2020-02-28T00:00:00.000Z&#34;,&#34;2020-02-29T00:00:00.000Z&#34;,&#34;2020-03-01T00:00:00.000Z&#34;,&#34;2020-03-02T00:00:00.000Z&#34;,&#34;2020-03-03T00:00:00.000Z&#34;,&#34;2020-03-04T00:00:00.000Z&#34;,&#34;2020-03-05T00:00:00.000Z&#34;,&#34;2020-03-06T00:00:00.000Z&#34;,&#34;2020-03-07T00:00:00.000Z&#34;,&#34;2020-03-08T00:00:00.000Z&#34;,&#34;2020-03-09T00:00:00.000Z&#34;,&#34;2020-03-10T00:00:00.000Z&#34;,&#34;2020-03-11T00:00:00.000Z&#34;,&#34;2020-03-12T00:00:00.000Z&#34;,&#34;2020-03-13T00:00:00.000Z&#34;,&#34;2020-03-14T00:00:00.000Z&#34;,&#34;2020-03-15T00:00:00.000Z&#34;,&#34;2020-03-16T00:00:00.000Z&#34;,&#34;2020-03-17T00:00:00.000Z&#34;,&#34;2020-03-18T00:00:00.000Z&#34;,&#34;2020-03-19T00:00:00.000Z&#34;,&#34;2020-03-20T00:00:00.000Z&#34;,&#34;2020-03-21T00:00:00.000Z&#34;,&#34;2020-03-22T00:00:00.000Z&#34;,&#34;2020-03-23T00:00:00.000Z&#34;,&#34;2020-03-24T00:00:00.000Z&#34;,&#34;2020-03-25T00:00:00.000Z&#34;,&#34;2020-03-26T00:00:00.000Z&#34;,&#34;2020-03-27T00:00:00.000Z&#34;,&#34;2020-03-28T00:00:00.000Z&#34;,&#34;2020-03-29T00:00:00.000Z&#34;,&#34;2020-03-30T00:00:00.000Z&#34;,&#34;2020-03-31T00:00:00.000Z&#34;,&#34;2020-04-01T00:00:00.000Z&#34;,&#34;2020-04-02T00:00:00.000Z&#34;,&#34;2020-04-03T00:00:00.000Z&#34;,&#34;2020-04-04T00:00:00.000Z&#34;,&#34;2020-04-05T00:00:00.000Z&#34;,&#34;2020-04-06T00:00:00.000Z&#34;,&#34;2020-04-07T00:00:00.000Z&#34;,&#34;2020-04-08T00:00:00.000Z&#34;,&#34;2020-04-09T00:00:00.000Z&#34;,&#34;2020-04-10T00:00:00.000Z&#34;,&#34;2020-04-11T00:00:00.000Z&#34;,&#34;2020-04-12T00:00:00.000Z&#34;,&#34;2020-04-13T00:00:00.000Z&#34;,&#34;2020-04-14T00:00:00.000Z&#34;,&#34;2020-04-15T00:00:00.000Z&#34;,&#34;2020-04-16T00:00:00.000Z&#34;,&#34;2020-04-17T00:00:00.000Z&#34;,&#34;2020-04-18T00:00:00.000Z&#34;,&#34;2020-04-19T00:00:00.000Z&#34;,&#34;2020-04-20T00:00:00.000Z&#34;,&#34;2020-04-21T00:00:00.000Z&#34;,&#34;2020-04-22T00:00:00.000Z&#34;,&#34;2020-04-23T00:00:00.000Z&#34;,&#34;2020-04-24T00:00:00.000Z&#34;,&#34;2020-04-25T00:00:00.000Z&#34;,&#34;2020-04-26T00:00:00.000Z&#34;,&#34;2020-04-27T00:00:00.000Z&#34;,&#34;2020-04-28T00:00:00.000Z&#34;,&#34;2020-04-29T00:00:00.000Z&#34;,&#34;2020-04-30T00:00:00.000Z&#34;,&#34;2020-05-01T00:00:00.000Z&#34;,&#34;2020-05-02T00:00:00.000Z&#34;,&#34;2020-05-03T00:00:00.000Z&#34;,&#34;2020-05-04T00:00:00.000Z&#34;,&#34;2020-05-05T00:00:00.000Z&#34;,&#34;2020-05-06T00:00:00.000Z&#34;,&#34;2020-05-07T00:00:00.000Z&#34;,&#34;2020-05-08T00:00:00.000Z&#34;,&#34;2020-05-09T00:00:00.000Z&#34;,&#34;2020-05-10T00:00:00.000Z&#34;,&#34;2020-05-11T00:00:00.000Z&#34;,&#34;2020-05-12T00:00:00.000Z&#34;,&#34;2020-05-13T00:00:00.000Z&#34;,&#34;2020-05-14T00:00:00.000Z&#34;,&#34;2020-05-15T00:00:00.000Z&#34;,&#34;2020-05-16T00:00:00.000Z&#34;,&#34;2020-05-17T00:00:00.000Z&#34;,&#34;2020-05-18T00:00:00.000Z&#34;,&#34;2020-05-19T00:00:00.000Z&#34;,&#34;2020-05-20T00:00:00.000Z&#34;,&#34;2020-05-21T00:00:00.000Z&#34;,&#34;2020-05-22T00:00:00.000Z&#34;,&#34;2020-05-23T00:00:00.000Z&#34;,&#34;2020-05-24T00:00:00.000Z&#34;,&#34;2020-05-25T00:00:00.000Z&#34;,&#34;2020-05-26T00:00:00.000Z&#34;,&#34;2020-05-27T00:00:00.000Z&#34;,&#34;2020-05-28T00:00:00.000Z&#34;,&#34;2020-05-29T00:00:00.000Z&#34;,&#34;2020-05-30T00:00:00.000Z&#34;,&#34;2020-05-31T00:00:00.000Z&#34;,&#34;2020-06-01T00:00:00.000Z&#34;,&#34;2020-06-02T00:00:00.000Z&#34;,&#34;2020-06-03T00:00:00.000Z&#34;,&#34;2020-06-04T00:00:00.000Z&#34;,&#34;2020-06-05T00:00:00.000Z&#34;,&#34;2020-06-06T00:00:00.000Z&#34;,&#34;2020-06-07T00:00:00.000Z&#34;,&#34;2020-06-08T00:00:00.000Z&#34;,&#34;2020-06-09T00:00:00.000Z&#34;,&#34;2020-06-10T00:00:00.000Z&#34;,&#34;2020-06-11T00:00:00.000Z&#34;,&#34;2020-06-12T00:00:00.000Z&#34;,&#34;2020-06-13T00:00:00.000Z&#34;,&#34;2020-06-14T00:00:00.000Z&#34;,&#34;2020-06-15T00:00:00.000Z&#34;,&#34;2020-06-16T00:00:00.000Z&#34;,&#34;2020-06-17T00:00:00.000Z&#34;,&#34;2020-06-18T00:00:00.000Z&#34;,&#34;2020-06-19T00:00:00.000Z&#34;,&#34;2020-06-20T00:00:00.000Z&#34;,&#34;2020-06-21T00:00:00.000Z&#34;,&#34;2020-06-22T00:00:00.000Z&#34;,&#34;2020-06-23T00:00:00.000Z&#34;,&#34;2020-06-24T00:00:00.000Z&#34;,&#34;2020-06-25T00:00:00.000Z&#34;,&#34;2020-06-26T00:00:00.000Z&#34;,&#34;2020-06-27T00:00:00.000Z&#34;,&#34;2020-06-28T00:00:00.000Z&#34;,&#34;2020-06-29T00:00:00.000Z&#34;,&#34;2020-06-30T00:00:00.000Z&#34;,&#34;2020-07-01T00:00:00.000Z&#34;,&#34;2020-07-02T00:00:00.000Z&#34;,&#34;2020-07-03T00:00:00.000Z&#34;,&#34;2020-07-04T00:00:00.000Z&#34;,&#34;2020-07-05T00:00:00.000Z&#34;,&#34;2020-07-06T00:00:00.000Z&#34;,&#34;2020-07-07T00:00:00.000Z&#34;,&#34;2020-07-08T00:00:00.000Z&#34;,&#34;2020-07-09T00:00:00.000Z&#34;,&#34;2020-07-10T00:00:00.000Z&#34;,&#34;2020-07-11T00:00:00.000Z&#34;,&#34;2020-07-12T00:00:00.000Z&#34;,&#34;2020-07-13T00:00:00.000Z&#34;,&#34;2020-07-14T00:00:00.000Z&#34;,&#34;2020-07-15T00:00:00.000Z&#34;,&#34;2020-07-16T00:00:00.000Z&#34;,&#34;2020-07-17T00:00:00.000Z&#34;,&#34;2020-07-18T00:00:00.000Z&#34;,&#34;2020-07-19T00:00:00.000Z&#34;,&#34;2020-07-20T00:00:00.000Z&#34;,&#34;2020-07-21T00:00:00.000Z&#34;,&#34;2020-07-22T00:00:00.000Z&#34;,&#34;2020-07-23T00:00:00.000Z&#34;,&#34;2020-07-24T00:00:00.000Z&#34;,&#34;2020-07-25T00:00:00.000Z&#34;,&#34;2020-07-26T00:00:00.000Z&#34;,&#34;2020-07-27T00:00:00.000Z&#34;,&#34;2020-07-28T00:00:00.000Z&#34;,&#34;2020-07-29T00:00:00.000Z&#34;,&#34;2020-07-30T00:00:00.000Z&#34;,&#34;2020-07-31T00:00:00.000Z&#34;,&#34;2020-08-01T00:00:00.000Z&#34;,&#34;2020-08-02T00:00:00.000Z&#34;,&#34;2020-08-03T00:00:00.000Z&#34;,&#34;2020-08-04T00:00:00.000Z&#34;,&#34;2020-08-05T00:00:00.000Z&#34;,&#34;2020-08-06T00:00:00.000Z&#34;,&#34;2020-08-07T00:00:00.000Z&#34;,&#34;2020-08-08T00:00:00.000Z&#34;,&#34;2020-08-09T00:00:00.000Z&#34;,&#34;2020-08-10T00:00:00.000Z&#34;,&#34;2020-08-11T00:00:00.000Z&#34;,&#34;2020-08-12T00:00:00.000Z&#34;,&#34;2020-08-13T00:00:00.000Z&#34;,&#34;2020-08-14T00:00:00.000Z&#34;,&#34;2020-08-15T00:00:00.000Z&#34;,&#34;2020-08-16T00:00:00.000Z&#34;,&#34;2020-08-17T00:00:00.000Z&#34;,&#34;2020-08-18T00:00:00.000Z&#34;,&#34;2020-08-19T00:00:00.000Z&#34;,&#34;2020-08-20T00:00:00.000Z&#34;,&#34;2020-08-21T00:00:00.000Z&#34;,&#34;2020-08-22T00:00:00.000Z&#34;,&#34;2020-08-23T00:00:00.000Z&#34;,&#34;2020-08-24T00:00:00.000Z&#34;,&#34;2020-08-25T00:00:00.000Z&#34;,&#34;2020-08-26T00:00:00.000Z&#34;,&#34;2020-08-27T00:00:00.000Z&#34;,&#34;2020-08-28T00:00:00.000Z&#34;,&#34;2020-08-29T00:00:00.000Z&#34;,&#34;2020-08-30T00:00:00.000Z&#34;,&#34;2020-08-31T00:00:00.000Z&#34;,&#34;2020-09-01T00:00:00.000Z&#34;,&#34;2020-09-02T00:00:00.000Z&#34;,&#34;2020-09-03T00:00:00.000Z&#34;,&#34;2020-09-04T00:00:00.000Z&#34;,&#34;2020-09-05T00:00:00.000Z&#34;,&#34;2020-09-06T00:00:00.000Z&#34;,&#34;2020-09-07T00:00:00.000Z&#34;,&#34;2020-09-08T00:00:00.000Z&#34;,&#34;2020-09-09T00:00:00.000Z&#34;,&#34;2020-09-10T00:00:00.000Z&#34;,&#34;2020-09-11T00:00:00.000Z&#34;,&#34;2020-09-12T00:00:00.000Z&#34;,&#34;2020-09-13T00:00:00.000Z&#34;,&#34;2020-09-14T00:00:00.000Z&#34;,&#34;2020-09-15T00:00:00.000Z&#34;,&#34;2020-09-16T00:00:00.000Z&#34;,&#34;2020-09-17T00:00:00.000Z&#34;,&#34;2020-09-18T00:00:00.000Z&#34;,&#34;2020-09-19T00:00:00.000Z&#34;,&#34;2020-09-20T00:00:00.000Z&#34;,&#34;2020-09-21T00:00:00.000Z&#34;,&#34;2020-09-22T00:00:00.000Z&#34;,&#34;2020-09-23T00:00:00.000Z&#34;,&#34;2020-09-24T00:00:00.000Z&#34;,&#34;2020-09-25T00:00:00.000Z&#34;,&#34;2020-09-26T00:00:00.000Z&#34;,&#34;2020-09-27T00:00:00.000Z&#34;,&#34;2020-09-28T00:00:00.000Z&#34;,&#34;2020-09-29T00:00:00.000Z&#34;,&#34;2020-09-30T00:00:00.000Z&#34;,&#34;2020-10-01T00:00:00.000Z&#34;,&#34;2020-10-02T00:00:00.000Z&#34;,&#34;2020-10-03T00:00:00.000Z&#34;,&#34;2020-10-04T00:00:00.000Z&#34;,&#34;2020-10-05T00:00:00.000Z&#34;,&#34;2020-10-06T00:00:00.000Z&#34;,&#34;2020-10-07T00:00:00.000Z&#34;,&#34;2020-10-08T00:00:00.000Z&#34;,&#34;2020-10-09T00:00:00.000Z&#34;,&#34;2020-10-10T00:00:00.000Z&#34;,&#34;2020-10-11T00:00:00.000Z&#34;,&#34;2020-10-12T00:00:00.000Z&#34;,&#34;2020-10-13T00:00:00.000Z&#34;,&#34;2020-10-14T00:00:00.000Z&#34;,&#34;2020-10-15T00:00:00.000Z&#34;,&#34;2020-10-16T00:00:00.000Z&#34;,&#34;2020-10-17T00:00:00.000Z&#34;,&#34;2020-10-18T00:00:00.000Z&#34;,&#34;2020-10-19T00:00:00.000Z&#34;,&#34;2020-10-20T00:00:00.000Z&#34;,&#34;2020-10-21T00:00:00.000Z&#34;,&#34;2020-10-22T00:00:00.000Z&#34;,&#34;2020-10-23T00:00:00.000Z&#34;,&#34;2020-10-24T00:00:00.000Z&#34;,&#34;2020-10-25T00:00:00.000Z&#34;,&#34;2020-10-26T00:00:00.000Z&#34;,&#34;2020-10-27T00:00:00.000Z&#34;,&#34;2020-10-28T00:00:00.000Z&#34;,&#34;2020-10-29T00:00:00.000Z&#34;,&#34;2020-10-30T00:00:00.000Z&#34;,&#34;2020-10-31T00:00:00.000Z&#34;,&#34;2020-11-01T00:00:00.000Z&#34;,&#34;2020-11-02T00:00:00.000Z&#34;,&#34;2020-11-03T00:00:00.000Z&#34;,&#34;2020-11-04T00:00:00.000Z&#34;,&#34;2020-11-05T00:00:00.000Z&#34;,&#34;2020-11-06T00:00:00.000Z&#34;,&#34;2020-11-07T00:00:00.000Z&#34;,&#34;2020-11-08T00:00:00.000Z&#34;,&#34;2020-11-09T00:00:00.000Z&#34;,&#34;2020-11-10T00:00:00.000Z&#34;,&#34;2020-11-11T00:00:00.000Z&#34;,&#34;2020-11-12T00:00:00.000Z&#34;,&#34;2020-11-13T00:00:00.000Z&#34;,&#34;2020-11-14T00:00:00.000Z&#34;,&#34;2020-11-15T00:00:00.000Z&#34;,&#34;2020-11-16T00:00:00.000Z&#34;,&#34;2020-11-17T00:00:00.000Z&#34;,&#34;2020-11-18T00:00:00.000Z&#34;,&#34;2020-11-19T00:00:00.000Z&#34;,&#34;2020-11-20T00:00:00.000Z&#34;,&#34;2020-11-21T00:00:00.000Z&#34;,&#34;2020-11-22T00:00:00.000Z&#34;,&#34;2020-11-23T00:00:00.000Z&#34;,&#34;2020-11-24T00:00:00.000Z&#34;,&#34;2020-11-25T00:00:00.000Z&#34;,&#34;2020-11-26T00:00:00.000Z&#34;,&#34;2020-11-27T00:00:00.000Z&#34;,&#34;2020-11-28T00:00:00.000Z&#34;,&#34;2020-11-29T00:00:00.000Z&#34;,&#34;2020-11-30T00:00:00.000Z&#34;,&#34;2020-12-01T00:00:00.000Z&#34;,&#34;2020-12-02T00:00:00.000Z&#34;,&#34;2020-12-03T00:00:00.000Z&#34;,&#34;2020-12-04T00:00:00.000Z&#34;,&#34;2020-12-05T00:00:00.000Z&#34;,&#34;2020-12-06T00:00:00.000Z&#34;,&#34;2020-12-07T00:00:00.000Z&#34;,&#34;2020-12-08T00:00:00.000Z&#34;,&#34;2020-12-09T00:00:00.000Z&#34;,&#34;2020-12-10T00:00:00.000Z&#34;,&#34;2020-12-11T00:00:00.000Z&#34;,&#34;2020-12-12T00:00:00.000Z&#34;,&#34;2020-12-13T00:00:00.000Z&#34;,&#34;2020-12-14T00:00:00.000Z&#34;,&#34;2020-12-15T00:00:00.000Z&#34;,&#34;2020-12-16T00:00:00.000Z&#34;,&#34;2020-12-17T00:00:00.000Z&#34;,&#34;2020-12-18T00:00:00.000Z&#34;,&#34;2020-12-19T00:00:00.000Z&#34;,&#34;2020-12-20T00:00:00.000Z&#34;,&#34;2020-12-21T00:00:00.000Z&#34;,&#34;2020-12-22T00:00:00.000Z&#34;,&#34;2020-12-23T00:00:00.000Z&#34;,&#34;2020-12-24T00:00:00.000Z&#34;,&#34;2020-12-25T00:00:00.000Z&#34;,&#34;2020-12-26T00:00:00.000Z&#34;,&#34;2020-12-27T00:00:00.000Z&#34;,&#34;2020-12-28T00:00:00.000Z&#34;,&#34;2020-12-29T00:00:00.000Z&#34;,&#34;2020-12-30T00:00:00.000Z&#34;,&#34;2020-12-31T00:00:00.000Z&#34;,&#34;2021-01-01T00:00:00.000Z&#34;,&#34;2021-01-02T00:00:00.000Z&#34;,&#34;2021-01-03T00:00:00.000Z&#34;,&#34;2021-01-04T00:00:00.000Z&#34;,&#34;2021-01-05T00:00:00.000Z&#34;,&#34;2021-01-06T00:00:00.000Z&#34;,&#34;2021-01-07T00:00:00.000Z&#34;,&#34;2021-01-08T00:00:00.000Z&#34;,&#34;2021-01-09T00:00:00.000Z&#34;,&#34;2021-01-10T00:00:00.000Z&#34;,&#34;2021-01-11T00:00:00.000Z&#34;,&#34;2021-01-12T00:00:00.000Z&#34;,&#34;2021-01-13T00:00:00.000Z&#34;,&#34;2021-01-14T00:00:00.000Z&#34;,&#34;2021-01-15T00:00:00.000Z&#34;,&#34;2021-01-16T00:00:00.000Z&#34;,&#34;2021-01-17T00:00:00.000Z&#34;,&#34;2021-01-18T00:00:00.000Z&#34;,&#34;2021-01-19T00:00:00.000Z&#34;,&#34;2021-01-20T00:00:00.000Z&#34;,&#34;2021-01-21T00:00:00.000Z&#34;,&#34;2021-01-22T00:00:00.000Z&#34;,&#34;2021-01-23T00:00:00.000Z&#34;,&#34;2021-01-24T00:00:00.000Z&#34;,&#34;2021-01-25T00:00:00.000Z&#34;,&#34;2021-01-26T00:00:00.000Z&#34;,&#34;2021-01-27T00:00:00.000Z&#34;,&#34;2021-01-28T00:00:00.000Z&#34;,&#34;2021-01-29T00:00:00.000Z&#34;,&#34;2021-01-30T00:00:00.000Z&#34;,&#34;2021-01-31T00:00:00.000Z&#34;,&#34;2021-02-01T00:00:00.000Z&#34;,&#34;2021-02-02T00:00:00.000Z&#34;,&#34;2021-02-03T00:00:00.000Z&#34;,&#34;2021-02-04T00:00:00.000Z&#34;,&#34;2021-02-05T00:00:00.000Z&#34;,&#34;2021-02-06T00:00:00.000Z&#34;,&#34;2021-02-07T00:00:00.000Z&#34;,&#34;2021-02-08T00:00:00.000Z&#34;,&#34;2021-02-09T00:00:00.000Z&#34;,&#34;2021-02-10T00:00:00.000Z&#34;,&#34;2021-02-11T00:00:00.000Z&#34;,&#34;2021-02-12T00:00:00.000Z&#34;,&#34;2021-02-13T00:00:00.000Z&#34;,&#34;2021-02-14T00:00:00.000Z&#34;,&#34;2021-02-15T00:00:00.000Z&#34;,&#34;2021-02-16T00:00:00.000Z&#34;,&#34;2021-02-17T00:00:00.000Z&#34;,&#34;2021-02-18T00:00:00.000Z&#34;,&#34;2021-02-19T00:00:00.000Z&#34;,&#34;2021-02-20T00:00:00.000Z&#34;,&#34;2021-02-21T00:00:00.000Z&#34;,&#34;2021-02-22T00:00:00.000Z&#34;,&#34;2021-02-23T00:00:00.000Z&#34;,&#34;2021-02-24T00:00:00.000Z&#34;,&#34;2021-02-25T00:00:00.000Z&#34;,&#34;2021-02-26T00:00:00.000Z&#34;,&#34;2021-02-27T00:00:00.000Z&#34;,&#34;2021-02-28T00:00:00.000Z&#34;,&#34;2021-03-01T00:00:00.000Z&#34;,&#34;2021-03-02T00:00:00.000Z&#34;,&#34;2021-03-03T00:00:00.000Z&#34;,&#34;2021-03-04T00:00:00.000Z&#34;,&#34;2021-03-05T00:00:00.000Z&#34;,&#34;2021-03-06T00:00:00.000Z&#34;,&#34;2021-03-07T00:00:00.000Z&#34;,&#34;2021-03-08T00:00:00.000Z&#34;,&#34;2021-03-09T00:00:00.000Z&#34;,&#34;2021-03-10T00:00:00.000Z&#34;,&#34;2021-03-11T00:00:00.000Z&#34;,&#34;2021-03-12T00:00:00.000Z&#34;,&#34;2021-03-13T00:00:00.000Z&#34;,&#34;2021-03-14T00:00:00.000Z&#34;,&#34;2021-03-15T00:00:00.000Z&#34;,&#34;2021-03-16T00:00:00.000Z&#34;,&#34;2021-03-17T00:00:00.000Z&#34;,&#34;2021-03-18T00:00:00.000Z&#34;,&#34;2021-03-19T00:00:00.000Z&#34;,&#34;2021-03-20T00:00:00.000Z&#34;,&#34;2021-03-21T00:00:00.000Z&#34;,&#34;2021-03-22T00:00:00.000Z&#34;,&#34;2021-03-23T00:00:00.000Z&#34;,&#34;2021-03-24T00:00:00.000Z&#34;,&#34;2021-03-25T00:00:00.000Z&#34;,&#34;2021-03-26T00:00:00.000Z&#34;,&#34;2021-03-27T00:00:00.000Z&#34;,&#34;2021-03-28T00:00:00.000Z&#34;,&#34;2021-03-29T00:00:00.000Z&#34;,&#34;2021-03-30T00:00:00.000Z&#34;,&#34;2021-03-31T00:00:00.000Z&#34;,&#34;2021-04-01T00:00:00.000Z&#34;,&#34;2021-04-02T00:00:00.000Z&#34;,&#34;2021-04-03T00:00:00.000Z&#34;,&#34;2021-04-04T00:00:00.000Z&#34;,&#34;2021-04-05T00:00:00.000Z&#34;,&#34;2021-04-06T00:00:00.000Z&#34;,&#34;2021-04-07T00:00:00.000Z&#34;,&#34;2021-04-08T00:00:00.000Z&#34;,&#34;2021-04-09T00:00:00.000Z&#34;,&#34;2021-04-10T00:00:00.000Z&#34;,&#34;2021-04-11T00:00:00.000Z&#34;,&#34;2021-04-12T00:00:00.000Z&#34;,&#34;2021-04-13T00:00:00.000Z&#34;,&#34;2021-04-14T00:00:00.000Z&#34;,&#34;2021-04-15T00:00:00.000Z&#34;,&#34;2021-04-16T00:00:00.000Z&#34;,&#34;2021-04-17T00:00:00.000Z&#34;,&#34;2021-04-18T00:00:00.000Z&#34;,&#34;2021-04-19T00:00:00.000Z&#34;,&#34;2021-04-20T00:00:00.000Z&#34;,&#34;2021-04-21T00:00:00.000Z&#34;,&#34;2021-04-22T00:00:00.000Z&#34;,&#34;2021-04-23T00:00:00.000Z&#34;,&#34;2021-04-24T00:00:00.000Z&#34;,&#34;2021-04-25T00:00:00.000Z&#34;,&#34;2021-04-26T00:00:00.000Z&#34;,&#34;2021-04-27T00:00:00.000Z&#34;,&#34;2021-04-28T00:00:00.000Z&#34;,&#34;2021-04-29T00:00:00.000Z&#34;,&#34;2021-04-30T00:00:00.000Z&#34;,&#34;2021-05-01T00:00:00.000Z&#34;,&#34;2021-05-02T00:00:00.000Z&#34;,&#34;2021-05-03T00:00:00.000Z&#34;,&#34;2021-05-04T00:00:00.000Z&#34;,&#34;2021-05-05T00:00:00.000Z&#34;,&#34;2021-05-06T00:00:00.000Z&#34;,&#34;2021-05-07T00:00:00.000Z&#34;,&#34;2021-05-08T00:00:00.000Z&#34;,&#34;2021-05-09T00:00:00.000Z&#34;,&#34;2021-05-10T00:00:00.000Z&#34;,&#34;2021-05-11T00:00:00.000Z&#34;,&#34;2021-05-12T00:00:00.000Z&#34;,&#34;2021-05-13T00:00:00.000Z&#34;,&#34;2021-05-14T00:00:00.000Z&#34;,&#34;2021-05-15T00:00:00.000Z&#34;,&#34;2021-05-16T00:00:00.000Z&#34;,&#34;2021-05-17T00:00:00.000Z&#34;,&#34;2021-05-18T00:00:00.000Z&#34;,&#34;2021-05-19T00:00:00.000Z&#34;,&#34;2021-05-20T00:00:00.000Z&#34;,&#34;2021-05-21T00:00:00.000Z&#34;,&#34;2021-05-22T00:00:00.000Z&#34;,&#34;2021-05-23T00:00:00.000Z&#34;,&#34;2021-05-24T00:00:00.000Z&#34;,&#34;2021-05-25T00:00:00.000Z&#34;,&#34;2021-05-26T00:00:00.000Z&#34;,&#34;2021-05-27T00:00:00.000Z&#34;,&#34;2021-05-28T00:00:00.000Z&#34;,&#34;2021-05-29T00:00:00.000Z&#34;,&#34;2021-05-30T00:00:00.000Z&#34;,&#34;2021-05-31T00:00:00.000Z&#34;,&#34;2021-06-01T00:00:00.000Z&#34;,&#34;2021-06-02T00:00:00.000Z&#34;,&#34;2021-06-03T00:00:00.000Z&#34;,&#34;2021-06-04T00:00:00.000Z&#34;,&#34;2021-06-05T00:00:00.000Z&#34;,&#34;2021-06-06T00:00:00.000Z&#34;,&#34;2021-06-07T00:00:00.000Z&#34;,&#34;2021-06-08T00:00:00.000Z&#34;,&#34;2021-06-09T00:00:00.000Z&#34;,&#34;2021-06-10T00:00:00.000Z&#34;,&#34;2021-06-11T00:00:00.000Z&#34;,&#34;2021-06-12T00:00:00.000Z&#34;,&#34;2021-06-13T00:00:00.000Z&#34;,&#34;2021-06-14T00:00:00.000Z&#34;,&#34;2021-06-15T00:00:00.000Z&#34;,&#34;2021-06-16T00:00:00.000Z&#34;,&#34;2021-06-17T00:00:00.000Z&#34;,&#34;2021-06-18T00:00:00.000Z&#34;,&#34;2021-06-19T00:00:00.000Z&#34;,&#34;2021-06-20T00:00:00.000Z&#34;,&#34;2021-06-21T00:00:00.000Z&#34;,&#34;2021-06-22T00:00:00.000Z&#34;,&#34;2021-06-23T00:00:00.000Z&#34;,&#34;2021-06-24T00:00:00.000Z&#34;,&#34;2021-06-25T00:00:00.000Z&#34;,&#34;2021-06-26T00:00:00.000Z&#34;,&#34;2021-06-27T00:00:00.000Z&#34;,&#34;2021-06-28T00:00:00.000Z&#34;,&#34;2021-06-29T00:00:00.000Z&#34;,&#34;2021-06-30T00:00:00.000Z&#34;,&#34;2021-07-01T00:00:00.000Z&#34;,&#34;2021-07-02T00:00:00.000Z&#34;,&#34;2021-07-03T00:00:00.000Z&#34;,&#34;2021-07-04T00:00:00.000Z&#34;,&#34;2021-07-05T00:00:00.000Z&#34;,&#34;2021-07-06T00:00:00.000Z&#34;,&#34;2021-07-07T00:00:00.000Z&#34;,&#34;2021-07-08T00:00:00.000Z&#34;,&#34;2021-07-09T00:00:00.000Z&#34;,&#34;2021-07-10T00:00:00.000Z&#34;,&#34;2021-07-11T00:00:00.000Z&#34;,&#34;2021-07-12T00:00:00.000Z&#34;,&#34;2021-07-13T00:00:00.000Z&#34;,&#34;2021-07-14T00:00:00.000Z&#34;,&#34;2021-07-15T00:00:00.000Z&#34;,&#34;2021-07-16T00:00:00.000Z&#34;,&#34;2021-07-17T00:00:00.000Z&#34;,&#34;2021-07-18T00:00:00.000Z&#34;,&#34;2021-07-19T00:00:00.000Z&#34;,&#34;2021-07-20T00:00:00.000Z&#34;,&#34;2021-07-21T00:00:00.000Z&#34;,&#34;2021-07-22T00:00:00.000Z&#34;,&#34;2021-07-23T00:00:00.000Z&#34;,&#34;2021-07-24T00:00:00.000Z&#34;,&#34;2021-07-25T00:00:00.000Z&#34;,&#34;2021-07-26T00:00:00.000Z&#34;,&#34;2021-07-27T00:00:00.000Z&#34;,&#34;2021-07-28T00:00:00.000Z&#34;,&#34;2021-07-29T00:00:00.000Z&#34;,&#34;2021-07-30T00:00:00.000Z&#34;,&#34;2021-07-31T00:00:00.000Z&#34;,&#34;2021-08-01T00:00:00.000Z&#34;,&#34;2021-08-02T00:00:00.000Z&#34;,&#34;2021-08-03T00:00:00.000Z&#34;,&#34;2021-08-04T00:00:00.000Z&#34;,&#34;2021-08-05T00:00:00.000Z&#34;,&#34;2021-08-06T00:00:00.000Z&#34;,&#34;2021-08-07T00:00:00.000Z&#34;,&#34;2021-08-08T00:00:00.000Z&#34;,&#34;2021-08-09T00:00:00.000Z&#34;,&#34;2021-08-10T00:00:00.000Z&#34;,&#34;2021-08-11T00:00:00.000Z&#34;,&#34;2021-08-12T00:00:00.000Z&#34;,&#34;2021-08-13T00:00:00.000Z&#34;,&#34;2021-08-14T00:00:00.000Z&#34;,&#34;2021-08-15T00:00:00.000Z&#34;,&#34;2021-08-16T00:00:00.000Z&#34;,&#34;2021-08-17T00:00:00.000Z&#34;,&#34;2021-08-18T00:00:00.000Z&#34;,&#34;2021-08-19T00:00:00.000Z&#34;,&#34;2021-08-20T00:00:00.000Z&#34;,&#34;2021-08-21T00:00:00.000Z&#34;,&#34;2021-08-22T00:00:00.000Z&#34;,&#34;2021-08-23T00:00:00.000Z&#34;,&#34;2021-08-24T00:00:00.000Z&#34;,&#34;2021-08-25T00:00:00.000Z&#34;,&#34;2021-08-26T00:00:00.000Z&#34;,&#34;2021-08-27T00:00:00.000Z&#34;,&#34;2021-08-28T00:00:00.000Z&#34;,&#34;2021-08-29T00:00:00.000Z&#34;,&#34;2021-08-30T00:00:00.000Z&#34;,&#34;2021-08-31T00:00:00.000Z&#34;,&#34;2021-09-01T00:00:00.000Z&#34;,&#34;2021-09-02T00:00:00.000Z&#34;,&#34;2021-09-03T00:00:00.000Z&#34;,&#34;2021-09-04T00:00:00.000Z&#34;,&#34;2021-09-05T00:00:00.000Z&#34;,&#34;2021-09-06T00:00:00.000Z&#34;,&#34;2021-09-07T00:00:00.000Z&#34;,&#34;2021-09-08T00:00:00.000Z&#34;,&#34;2021-09-09T00:00:00.000Z&#34;,&#34;2021-09-10T00:00:00.000Z&#34;,&#34;2021-09-11T00:00:00.000Z&#34;,&#34;2021-09-12T00:00:00.000Z&#34;,&#34;2021-09-13T00:00:00.000Z&#34;,&#34;2021-09-14T00:00:00.000Z&#34;,&#34;2021-09-15T00:00:00.000Z&#34;,&#34;2021-09-16T00:00:00.000Z&#34;,&#34;2021-09-17T00:00:00.000Z&#34;,&#34;2021-09-18T00:00:00.000Z&#34;,&#34;2021-09-19T00:00:00.000Z&#34;,&#34;2021-09-20T00:00:00.000Z&#34;,&#34;2021-09-21T00:00:00.000Z&#34;,&#34;2021-09-22T00:00:00.000Z&#34;,&#34;2021-09-23T00:00:00.000Z&#34;,&#34;2021-09-24T00:00:00.000Z&#34;,&#34;2021-09-25T00:00:00.000Z&#34;,&#34;2021-09-26T00:00:00.000Z&#34;,&#34;2021-09-27T00:00:00.000Z&#34;,&#34;2021-09-28T00:00:00.000Z&#34;,&#34;2021-09-29T00:00:00.000Z&#34;,&#34;2021-09-30T00:00:00.000Z&#34;,&#34;2021-10-01T00:00:00.000Z&#34;,&#34;2021-10-02T00:00:00.000Z&#34;,&#34;2021-10-03T00:00:00.000Z&#34;,&#34;2021-10-04T00:00:00.000Z&#34;,&#34;2021-10-05T00:00:00.000Z&#34;,&#34;2021-10-06T00:00:00.000Z&#34;,&#34;2021-10-07T00:00:00.000Z&#34;,&#34;2021-10-08T00:00:00.000Z&#34;,&#34;2021-10-09T00:00:00.000Z&#34;,&#34;2021-10-10T00:00:00.000Z&#34;,&#34;2021-10-11T00:00:00.000Z&#34;,&#34;2021-10-12T00:00:00.000Z&#34;,&#34;2021-10-13T00:00:00.000Z&#34;,&#34;2021-10-14T00:00:00.000Z&#34;,&#34;2021-10-15T00:00:00.000Z&#34;,&#34;2021-10-16T00:00:00.000Z&#34;,&#34;2021-10-17T00:00:00.000Z&#34;,&#34;2021-10-18T00:00:00.000Z&#34;,&#34;2021-10-19T00:00:00.000Z&#34;,&#34;2021-10-20T00:00:00.000Z&#34;,&#34;2021-10-21T00:00:00.000Z&#34;,&#34;2021-10-22T00:00:00.000Z&#34;,&#34;2021-10-23T00:00:00.000Z&#34;,&#34;2021-10-24T00:00:00.000Z&#34;,&#34;2021-10-25T00:00:00.000Z&#34;,&#34;2021-10-26T00:00:00.000Z&#34;,&#34;2021-10-27T00:00:00.000Z&#34;,&#34;2021-10-28T00:00:00.000Z&#34;,&#34;2021-10-29T00:00:00.000Z&#34;,&#34;2021-10-30T00:00:00.000Z&#34;,&#34;2021-10-31T00:00:00.000Z&#34;,&#34;2021-11-01T00:00:00.000Z&#34;,&#34;2021-11-02T00:00:00.000Z&#34;,&#34;2021-11-03T00:00:00.000Z&#34;,&#34;2021-11-04T00:00:00.000Z&#34;,&#34;2021-11-05T00:00:00.000Z&#34;,&#34;2021-11-06T00:00:00.000Z&#34;,&#34;2021-11-07T00:00:00.000Z&#34;,&#34;2021-11-08T00:00:00.000Z&#34;,&#34;2021-11-09T00:00:00.000Z&#34;,&#34;2021-11-10T00:00:00.000Z&#34;,&#34;2021-11-11T00:00:00.000Z&#34;,&#34;2021-11-12T00:00:00.000Z&#34;,&#34;2021-11-13T00:00:00.000Z&#34;,&#34;2021-11-14T00:00:00.000Z&#34;,&#34;2021-11-15T00:00:00.000Z&#34;,&#34;2021-11-16T00:00:00.000Z&#34;,&#34;2021-11-17T00:00:00.000Z&#34;,&#34;2021-11-18T00:00:00.000Z&#34;,&#34;2021-11-19T00:00:00.000Z&#34;,&#34;2021-11-20T00:00:00.000Z&#34;,&#34;2021-11-21T00:00:00.000Z&#34;,&#34;2021-11-22T00:00:00.000Z&#34;,&#34;2021-11-23T00:00:00.000Z&#34;,&#34;2021-11-24T00:00:00.000Z&#34;,&#34;2021-11-25T00:00:00.000Z&#34;,&#34;2021-11-26T00:00:00.000Z&#34;,&#34;2021-11-27T00:00:00.000Z&#34;,&#34;2021-11-28T00:00:00.000Z&#34;,&#34;2021-11-29T00:00:00.000Z&#34;,&#34;2021-11-30T00:00:00.000Z&#34;,&#34;2021-12-01T00:00:00.000Z&#34;,&#34;2021-12-02T00:00:00.000Z&#34;,&#34;2021-12-03T00:00:00.000Z&#34;,&#34;2021-12-04T00:00:00.000Z&#34;,&#34;2021-12-05T00:00:00.000Z&#34;,&#34;2021-12-06T00:00:00.000Z&#34;,&#34;2021-12-07T00:00:00.000Z&#34;],[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0.0311890838206628,0.0339805825242718,0.0406779661016949,0.0557868442964196,0.0545335085413929,0.0660643704121965,0.0725609756097561,0.0838548185231539,0.0778995960761685,0.0507772020725389,0.0456698240866035,0.0474686246051396,0.0517983399938518,0.0486385366867595,0.0332392714479422,0.0351560536764336,0.048508425460969,0.0667591354171827,0.0736976024342899,0.0859868829095132,0.115585434476788,0.130889198378941,0.0998058029521778,0.127595016173893,0.131530890181998,0.127615078166997,0.173070761343751,0.168018434852031,0.173897195807481,0.172270532080167,0.175890063811583,0.183710435212661,0.190922356193841,0.237587236260501,0.184786293958521,0.216099088519823,0.168608205595634,0.189098602263003,0.19941610202123,0.194559562905054,0.150721772929001,0.243356405106871,0.225703324808184,0.164230073466977,0.174309477239882,0.171603671676953,0.158724321710308,0.169795752415574,0.18859384654324,0.170800289291236,0.115347752179102,0.122264205352637,0.144815315025618,0.141620925714638,0.156718423341972,0.155831060129165,0.102724772714189,0.0913920690473366,0.0900884091109558,0.094114765635415,0.100895196117451,0.109836627612319,0.121267228621664,0.0875384639913267,0.0742054114959077,0.0681371417767484,0.0785357351659625,0.0685026201360241,0.0741063020752625,0.081627159501808,0.0550838715324451,0.0528590086684034,0.0469562282234801,0.0598904015868891,0.058894039214806,0.0646816630943528,0.0624642737468709,0.0618382917480005,0.0483519269776876,0.0498363630472117,0.0559870676901119,0.0483596647193294,0.0570940688113265,0.0578075218174262,0.0580346019920149,0.040952021811026,0.0338723930238484,0.0419781494334106,0.0448933535964243,0.0515587503553382,0.0552676196674943,0.049877680438437,0.0398413321963418,0.034329832275573,0.0349561350313321,0.0501071642999763,0.04848834630103,0.0459012836381748,0.0405261927815432,0.0335530952529641,0.0363374427357712,0.0377320442662807,0.0413411173274953,0.047648603305723,0.046307951508579,0.0397173566250217,0.0369763906822764,0.0363403799627176,0.0399711103703514,0.0437807385195534,0.0548234351568438,0.0626056124095768,0.0555913399691626,0.050043820458873,0.0482239822691568,0.0533658750290011,0.0562033829676394,0.0609863880354277,0.0697697006514641,0.0593944461320525,0.0565167930407808,0.0564847550500027,0.0646987309224975,0.0713403940610002,0.0805743942741038,0.084952027447587,0.0652031915333416,0.0598570973225669,0.0606149890453611,0.0591795554888003,0.067147404037879,0.0722722782294059,0.0828314439940217,0.0709325836871302,0.0653481876392093,0.0660136969099848,0.0735527921820458,0.0677237956187652,0.0684509293065029,0.0867060875957735,0.0659918501916241,0.0629840043380683,0.0628398165418683,0.0645821340536392,0.0684105582543468,0.0757197950294994,0.0800100940487909,0.074184430056847,0.0651840284878041,0.0641789036672561,0.0664055953754553,0.0697412664427694,0.0716902488747149,0.0813599610451185,0.0611089805131795,0.0605820967793028,0.0556354116397032,0.0580621648988097,0.0602156487628897,0.0677327670135049,0.0773751193026025,0.0600973573877339,0.0586804944571529,0.0527831803329703,0.0551557872205405,0.0618602914486418,0.0660993281037102,0.0735820819938078,0.0554395731848759,0.0482849586540566,0.0428032640063688,0.046191408994023,0.0507836776294529,0.0566881747505587,0.0575548660767529,0.0605961531251172,0.0432530706997785,0.0445232799408963,0.0446902195319343,0.0471655016424461,0.0558751654936502,0.0543782909772932,0.0551427193988662,0.0485247266910783,0.0315808634218183,0.0449230304479716,0.0521238823843667,0.0517479776856518,0.0530213584270696,0.0606805890111374,0.0435813766486822,0.0347511682072476,0.0349826332241725,0.0432218236271185,0.0451670432127,0.053104011747449,0.0520624122283932,0.0405321884508533,0.0344578254047926,0.0391270632164156,0.0397637292516819,0.0445489328649468,0.0582455522000689,0.0732419896571947,0.036308145857933,0.0344824152048288,0.0375936222907127,0.0483132282700676,0.045468583599574,0.0624265653505615,0.0559360986966709,0.0443802336977773,0.0350207836501952,0.0379091105838924,0.0449539637180066,0.0489449168646324,0.0546918504260639,0.0773039903588313,0.0349157938125518,0.0375312630742123,0.0393910050847387,0.042087996333843,0.0467832867143002,0.0598831300813008,0.0593224422323998,0.0510660470356288,0.0486704722872756,0.0501068795465976,0.0529826023011461,0.0472465694052919,0.0621291448516579,0.0747300684606908,0.0474198243884115,0.0434058126232755,0.0490166335561362,0.0581941706902563,0.06660569402016,0.0752368989017164,0.0781759298827749,0.0555034083854639,0.0544472719510971,0.0610188449160721,0.0665051563005691,0.0690117793806339,0.0824796705037491,0.092465706265037,0.0677251158785702,0.066212052801536,0.0715497382384174,0.0791877742847655,0.086512640170592,0.102284393996641,0.106582511183283,0.0908266689197313,0.0797701105787322,0.0882929116304766,0.0953104642693412,0.0995118672999898,0.11293507899591,0.111632461298629,0.0848437541829764,0.0820871520837453,0.0903224687666186,0.0924958277594929,0.0926267824808977,0.0990048463812468,0.107367350159237,0.0902222914365979,0.0811836749739937,0.0683948325025865,0.136182839449814,0.112330307845939,0.118227756189669,0.114466307956684,0.0999672795288686,0.0959049283973877,0.101420241102358,0.109269962472809,0.121639952646823,0.133019767928588,0.132803607176692,0.114764801992403,0.103454088469641,0.103237691692764,0.136419828736612,0.120528641320256,0.147530874578856,0.134470988847245,0.104462109069892,0.117900958706469,0.115826166951958,0.1242542961446,0.113330648691646,0.140981165785752,0.131846231955363,0.101473817916102,0.0999640106212557,0.102308552455927,0.0936702446557539,0.218590487940586,0.16082093339988,0.146433109175989,0.107771006313045,0.104630879200277,0.120098751466638,0.117313846886819,0.260892982076301,0.192087641771494,0.1789046909644,0.119179190194502,0.109544286592224,0.124059488227063,0.139866679377155,0.146587344397254,0.178159803685935,0.147964020414061,0.112944320738946,0.108318348488219,0.114661871894959,0.11707650659984,0.126641955389422,0.15801119958977,0.108956676880414,0.102949930969842,0.0865993435765275,0.0921894820494231,0.0989136614087239,0.108050734303825,0.12865703627272,0.126139436861402,0.0840118300756752,0.0750408757675347,0.0866391868246914,0.088890796860918,0.0932356101497205,0.120228041834435,0.136757591591742,0.070326119255906,0.0640426770002046,0.0648376941735047,0.0704673773931516,0.0785050182560242,0.105045951059354,0.0886316062393478,0.0566964314599022,0.0576891304506282,0.0742152565603997,0.0702540094224866,0.0766326949991219,0.0958211578765503,0.0689545904230567,0.0514490471881988,0.047556913616565,0.0506057235340475,0.0574371509665259,0.0657233003805579,0.0805260607900252,0.0569880457928359,0.0435619345998539,0.043799817466324,0.0481644496750426,0.0528352445446487,0.0581520392740134,0.080160936011401,0.056803699814849,0.0356598690376401,0.0382105976873559,0.0431724936250598,0.0457579436472762,0.0529418589202611,0.0655100806121948,0.0963437234326675,0.0361876092445135,0.0359203339520145,0.0414920566724018,0.0457510934030754,0.0482407980655788,0.0654493017293956,0.0599956129441238,0.0362646680344086,0.0363410213670233,0.0409006945745536,0.0450046360944264,0.0549213794272636,0.0556010862318487,0.0559295024138738,0.0369844621721675,0.0480868298789148,0.0476512214089914,0.0541142254043912,0.060694476802611,0.0713241962308651,0.0699736284519921,0.0405350570209462,0.0428993699849648,0.053395929367104,0.0509347959756543,0.0660253823410721,0.0651968760457297,0.0805864120245187,0.0398727612910199,0.0438137176679761,0.0530089556132846,0.056182545410471,0.0640244083293622,0.0743651903266507,0.0681269078176602,0.0479415829570249,0.0452377354974986,0.0496574904012409,0.0538508431848656,0.0534410208490807,0.067562517237834,0.0689265470213254,0.0388741876260525,0.0377904884917244,0.0442688597599199,0.0452288601311824,0.0507518551257181,0.0569174983479336,0.0474182664759317,0.0329607142494078,0.0347124247405655,0.0405638446257238,0.0445054071670156,0.0494960162336406,0.0567083801405844,0.0557110396962352,0.0287965496171827,0.029230435368049,0.0364225640587019,0.0403521948881952,0.0394853510356313,0.0460576256642133,0.0425415296890001,0.0254822699813605,0.0263966618633962,0.0321837367429111,0.0377771570847956,0.036882144725282,0.0368145195936523,0.0366209474276816,0.0229491129796783,0.0244147920028286,0.0293770494404891,0.0294771816274379,0.0258120522949136,0.0346224803887505,0.0359996403969119,0.0212704923376679,0.022287706403832,0.0299258728784037,0.0262925729211808,0.0199609414795616,0.0206729113192662,0.017404257607049,0.0318779007194773,0.015195313591504,0.0197005308853452,-0.0276130196210185,0.0169507749366049,0.016690854344966,0.0302113959025445,0.0160230705105469,0.0238457641572685,0.0201462352209085,0.022041284674057,0.0148614736176981,0.0196527540495619,0.0253463135606717,0.0143002719846205,0.0182783983602586,0.0168877815438595,0.0184055570289663,0.0153240283999935,0.0122497218713161,0.0279681765786821,0.0163887897133728,0.0184405141947668,0.0212918247796561,0.0223550574152815,0.0138475121989017,0.0121384742410112,0.0283816370005422,0.0226799515515054,0.023705169824982,0.101263316736453,0.0341297954316577,0.00895442058642148,0.0112444297357828,0.0149854421537779,0.0458816332824422,0.0388939442106984,0.0681640711532497,0.0532175254114249,0.0159626345136931,0.0162354684795248,0.0603361691315773,0.0582835229923088,0.0502004456105775,0.0469639301682424,0.0721820473694686,0.0236815765136609,0.0227907352517913,0.0900402261427328,0.0690950595213595,0.0645864816781186,0.0716190609483676,0.0944790356227208,0.033070890264077,0.0281886169584089,0.118846745075609,0.103396406128399,0.0770836660037453,0.0889668087386488,0.117266938722447,0.0388735086031428,0.0403887509901366,0.141154738433024,0.119043131167535,0.0851896338356264,0.092386677668199,0.126550107456076,0.0421336230613931,0.0505040180015431,0.158147763649671,0.113366918661539,0.101929811343006,0.0909906115851675,0.123103928063244,0.0442179859633613,0.055265467974331,0.203336214333905,0.0900006736157197,0.0969913479600182,0.0969688434963705,0.12959795973754,0.0676403782156252,0.0484457780542643,0.201958675973893,0.0831239972483304,0.0879335241159243,0.0963520752584932,0.104393721808217,0.0596978243577822,0.0432878118903378,0.195893955716144,0.0821723234384695,0.10379428763702,0.0896587480761458,0.102755825647554,0.0487903604063426,0.044827213833793,0.0935206435254425,0.215333284708904,0.0905979130739317,0.0827186573439596,0.0858515968506084,0.0484848087360016,0.0404052578518964,0.19297484323138,0.0814406465074008,0.0804836538193264,0.0776860946690656,0.0877502929162367,0.049080302227546,0.0418510139098374,0.151556694883726,0.0681230686015942,0.0719774033907602,0.0643629420786879,0.0734253210401033,0.0382987947371078,0.0392298639702891,0.160231938134476,0.0608274660642955,0.0642891732133781,0.0604295260133642,0.0692264803836473,0.0336438131886608,0.0325177570940283,0.136950246625747,0.0538078367942094,0.0640487798924816,0.0557947933964357,0.0635949870079844,0.0303061543394526,0.0320721543428055,0.108153391030299,0.0679838217319618,0.0579503720707889,0.0479731041325166,0.0578992262087991,0.0281546731670629,0.03205960377039,0.101066543431954,0.0491456781190941,0.0463151140875005,0.0448795640965678,0.0544153910981566,0.0271657498772604,0.0272422878296967,0.0922656975189188,0.0524653423753226,0.0530471355534309,0.0515316903303266,0.0577234365362945,0.0282231984692242,0.0312395050780946,0.119595428165458,0.0474016657086901,0.0451855481232159,0.0477863575346893,0.0581901006824186,0.0288912347545118,0.0267459336129233,0.104160283337452,0.0452263251124131,0.0553477434209534,0.0379640757271683,0.0887568848667079,0.0558611083057881,0.0307823293340252,0.120858558957824,0.0498944598594563,0.0594268865387503,0.0595361629023184,0.0733167354297021,0.0365770559674206,0.041885292083557,0.140785270964112,0.0582892048324792,0.0742041399884261,0.0417293334776022,0.0701918099337929,0.0284144813801616,0.0351848859245765,0.200136007216709,0.0773178227011364,0.127478665433566,0.239510960398912,null,null,null,null,null]]},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;/div&gt;
&lt;div id=&#34;world-bank-data&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;World Bank data&lt;/h2&gt;
&lt;p&gt;Country-level covariates by &lt;a href=&#34;https://data.worldbank.org/&#34;&gt;World Bank Open Data&lt;/a&gt; can be easily added. Refer to the table at the bottom of &lt;a href=&#34;https://datatopics.worldbank.org/universal-health-coverage/coronavirus/&#34;&gt;this page&lt;/a&gt; for relevant indicators. The following code snippet shows e.g., how to download the number of hospital beds for each country. Refer to the &lt;a href=&#34;https://covid19datahub.io/articles/r.html&#34;&gt;quickstart guide&lt;/a&gt; for more details.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;x &amp;lt;- covid19(wb = c(&amp;quot;hosp_beds&amp;quot; = &amp;quot;SH.MED.BEDS.ZS&amp;quot;), verbose = FALSE)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;mobility-data&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Mobility data&lt;/h2&gt;
&lt;p&gt;Mobility data are obtained from &lt;a href=&#34;https://www.google.com/covid19/mobility/&#34;&gt;Google&lt;/a&gt; and &lt;a href=&#34;https://www.apple.com/covid19/mobility&#34;&gt;Apple&lt;/a&gt; mobility reports. The following example shows how to download the data by Google. Refer to the &lt;a href=&#34;https://covid19datahub.io/articles/r.html&#34;&gt;quickstart guide&lt;/a&gt; for Apple’s reports and for more details.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;x &amp;lt;- covid19(gmr = TRUE, verbose = FALSE)
colnames(x[,48:53])&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;retail_and_recreation_percent_change_from_baseline&amp;quot;
## [2] &amp;quot;grocery_and_pharmacy_percent_change_from_baseline&amp;quot; 
## [3] &amp;quot;parks_percent_change_from_baseline&amp;quot;                
## [4] &amp;quot;transit_stations_percent_change_from_baseline&amp;quot;     
## [5] &amp;quot;workplaces_percent_change_from_baseline&amp;quot;           
## [6] &amp;quot;residential_percent_change_from_baseline&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;spatial-data&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Spatial data&lt;/h2&gt;
&lt;p&gt;The dataset contains NUTS codes to match the &lt;a href=&#34;https://ec.europa.eu/eurostat/web/nuts/nuts-maps&#34;&gt;Eurostat&lt;/a&gt; database for Europe, and GID codes to match the &lt;a href=&#34;https://gadm.org/&#34;&gt;GADM&lt;/a&gt; worldwide database. The following example shows how to access spatial data using GADM for U.S. counties. Similar maps are available worldwide for most other countries at the various granularity levels.&lt;/p&gt;
&lt;p&gt;First, download level 3 data for U.S.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;x &amp;lt;- covid19(&amp;quot;USA&amp;quot;, level = 3, verbose = FALSE)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;GADM data by country can be found &lt;a href=&#34;https://gadm.org/download_country.html&#34;&gt;here&lt;/a&gt;. Download the geopackage for U.S. using GADM version 3.6:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;url &amp;lt;- &amp;quot;https://biogeo.ucdavis.edu/data/gadm3.6/gpkg/gadm36_USA_gpkg.zip&amp;quot;
zip &amp;lt;- tempfile()
download.file(url, destfile = zip)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unzip the geopackage:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;exdir &amp;lt;- tempfile()
unzip(zip, exdir = exdir)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Load the &lt;code&gt;sf&lt;/code&gt; package and list the layers:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
file &amp;lt;- paste0(exdir, &amp;quot;/gadm36_USA.gpkg&amp;quot;)
st_layers(file)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Driver: GPKG 
## Available layers:
##     layer_name geometry_type features fields
## 1 gadm36_USA_2 Multi Polygon     3148     13
## 2 gadm36_USA_1 Multi Polygon       51     10
## 3 gadm36_USA_0 Multi Polygon        1      2&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Read layer 2 that corresponds to U.S. counties. Note: in general, there is not a perfect correspondence between GADM layers and the granularity &lt;code&gt;level&lt;/code&gt; from this package. It is recommended to read all the layers, and match on the corresponding GID. Read more about how &lt;code&gt;key_gadm&lt;/code&gt; from this package is mapped to the corresponding GID &lt;a href=&#34;https://covid19datahub.io/articles/docs.html#external-keys&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;g &amp;lt;- st_read(file, layer = &amp;quot;gadm36_USA_2&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Reading layer `gadm36_USA_2&amp;#39; from data source 
##   `/private/var/folders/w0/skxpg0h51jg72m5b01y_8n_c0000gn/T/RtmpmUy7P6/file56232c611dfd/gadm36_USA.gpkg&amp;#39; 
##   using driver `GPKG&amp;#39;
## Simple feature collection with 3148 features and 13 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -179.2 ymin: 18.91 xmax: 179.8 ymax: 72.69
## Geodetic CRS:  WGS 84&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Subset the data to extract only the counts as of, e.g., 15 November 2021. Select only the administrative divisions inside the following bounding box for better visualization.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;x &amp;lt;- x[
  x$date == &amp;quot;2021-11-15&amp;quot; &amp;amp; 
  x$latitude &amp;gt; 24.9493 &amp;amp; x$latitude &amp;lt; 49.5904 &amp;amp;
  x$longitude &amp;gt; -125.0011 &amp;amp; x$longitude &amp;lt; -66.9326,]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Merge COVID-19 data with the spatial data:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(dplyr)
gx &amp;lt;- right_join(g, x, by = c(&amp;quot;GID_2&amp;quot; = &amp;quot;key_gadm&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plot e.g., the total number of confirmed cases:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;plot(gx[&amp;quot;confirmed&amp;quot;], logz = TRUE)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;map2.png&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;academic-publications&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Academic publications&lt;/h2&gt;
&lt;p&gt;See the &lt;a href=&#34;https://scholar.google.com/scholar?oi=bibs&amp;amp;hl=en&amp;amp;cites=1585537563493742217&#34;&gt;publications&lt;/a&gt; that use COVID-19 Data Hub.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;cite-as&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Cite as&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Guidotti, E., Ardia, D., (2020), “COVID-19 Data Hub”, Journal of Open Source Software 5(51):2376, doi: 10.21105/joss.02376.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A BibTeX entry for LaTeX users is&lt;/p&gt;
&lt;pre class=&#34;latex&#34;&gt;&lt;code&gt;@Article{,
    title = {COVID-19 Data Hub},
    year = {2020},
    doi = {10.21105/joss.02376},
    author = {Emanuele Guidotti and David Ardia},
    journal = {Journal of Open Source Software},
    volume = {5},
    number = {51},
    pages = {2376}
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2021/12/08/the-r-package-covid19/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>Simulating COVID-19 interventions with R</title>
      <link>https://rviews.rstudio.com/2020/03/19/simulating-covid-19-interventions-with-r/</link>
      <pubDate>Thu, 19 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2020/03/19/simulating-covid-19-interventions-with-r/</guid>
      <description>
        
&lt;script src=&#34;/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/rmarkdown-libs/viz/viz.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;/rmarkdown-libs/DiagrammeR-styles/styles.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;/rmarkdown-libs/grViz-binding/grViz.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;&lt;em&gt;Tim Churches is a Senior Research Fellow at the UNSW Medicine South Western Sydney Clinical School at Liverpool Hospital, and a health data scientist at the Ingham Institute for Applied Medical Research. This post examines simulation of COVID-19 spread using &lt;code&gt;R&lt;/code&gt;, and how such simulations can be used to understand the effects of various public health interventions design to limit or slow its spread.&lt;/em&gt;&lt;/p&gt;
&lt;div id=&#34;disclaimer&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;DISCLAIMER&lt;/h1&gt;
&lt;p&gt;The simulation results in this blog post, or any other results produced by the &lt;code&gt;R&lt;/code&gt; code described in it, should &lt;strong&gt;not&lt;/strong&gt; be used as actual estimates of mortality or any other aspect of the COVID-19 pandemic. The simulations are intended to explain principles, and permit exploration of the potential effects of various combinations and timings of interventions on spread. Furthermore, the code for these simulations has been written hurriedly over just a few days, it has not yet been peer-reviewed, and is considered &lt;em&gt;alpha&lt;/em&gt; quality, and the simulation parameterisation presented here has not yet been validated against real-world COVID-19 data.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;introduction&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;In a &lt;a href=&#34;https://rviews.rstudio.com/2020/03/05/covid-19-epidemiology-with-r/&#34;&gt;previous post&lt;/a&gt;, we looked at the use of some &lt;code&gt;R&lt;/code&gt; packages developed by the &lt;a href=&#34;https://www.repidemicsconsortium.org&#34;&gt;&lt;strong&gt;R&lt;/strong&gt; &lt;strong&gt;E&lt;/strong&gt;pidemics &lt;strong&gt;Con&lt;/strong&gt;sortium (RECON)&lt;/a&gt; to undertake epidemiological analyses COVID-19 incidence data scraped from various web sources.&lt;/p&gt;
&lt;p&gt;Undertaking such value-adding analyses of COVID-19 incidence data, as the full horror of the pandemic unfolds, is a worthwhile endeavour. But it would also be useful to be able to gain a better understanding of the likely effects of various public health interventions on COVID-19 spread.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.fastcompany.com/90476143/the-story-behind-flatten-the-curve-the-defining-chart-of-the-coronavirus&#34;&gt;“Flattening-the-curve”&lt;/a&gt; infographics such as the one shown below are now everywhere. They are a useful and succinct way of communicating a key public health message – that social distancing and related measures will help take the strain off our health care systems in the coming months.&lt;/p&gt;
&lt;div class=&#34;figure&#34;&gt;
&lt;img src=&#34;https://upload.wikimedia.org/wikipedia/commons/c/c5/Covid-19-curves-graphic-social-v3.gif&#34; alt=&#34;Source: Siouxsie Wiles and Toby Morris&#34; /&gt;
&lt;p class=&#34;caption&#34;&gt;Source: &lt;a href=&#34;https://thespinoff.co.nz/society/09-03-2020/the-three-phases-of-covid-19-and-how-we-can-make-it-manageable/&#34;&gt;Siouxsie Wiles and Toby Morris&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;However, as pointed out by several commentators, many of these infographics miss a crucial point: that public health measures can do more than just &lt;strong&gt;flatten&lt;/strong&gt; the curve, they can also &lt;strong&gt;shrink&lt;/strong&gt; it, thus reducing the total number of cases (and thus serious cases) of COVID-19 in a population, rather than just spread the same number of cases over a longer period such that the area under the curve remains the same.&lt;/p&gt;
&lt;p&gt;This crucial point was beautifully illustrated using R in a &lt;a href=&#34;https://staff.math.su.se/hoehle/blog/2020/03/16/flatteningthecurve.html&#34;&gt;post by Michael Höhle&lt;/a&gt;, which is highly recommended reading. Michael used a dynamic model of disease transmission, which is based on solving a system of ordinary differential equations (ODEs) with the tools found in base &lt;code&gt;R&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Such mathematical approaches to disease outbreak simulation are elegant, and efficient to compute, but they can become unwieldy as the complexity of the model grows. An alternative is to use a more computational approach. In this post, we will briefly look at the individual contact model (ICM) simulation capability implemented in the excellent &lt;a href=&#34;http://www.epimodel.org&#34;&gt;&lt;code&gt;EpiModel&lt;/code&gt;&lt;/a&gt; package by Samuel Jenness and colleagues at the Emory University Rollins School of Public Health, and some extensions to it. Note also that this post is based on &lt;a href=&#34;https://timchurches.github.io/blog/&#34;&gt;two more detailed posts&lt;/a&gt; that provide more technical details and access to relevant source code.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;the-epimodel-package&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;The &lt;code&gt;EpiModel&lt;/code&gt; package&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;EpiModel&lt;/code&gt; package provides facilities to explore three types of disease transmission model (or simulations): dynamic contact models (DCMs) as used by &lt;a href=&#34;https://staff.math.su.se/hoehle/blog/2020/03/16/flatteningthecurve.html&#34;&gt;Michael Höhle&lt;/a&gt;, stochastic individual contact models (ICMs) and stochastic network models. The last are particularly interesting, as they can accurately model disease transmission with shifting social contact networks – they were developed to model HIV transmission, but have been used to model transmission of other diseases, including ebola, and even the propagation of &lt;em&gt;memes&lt;/em&gt; in social media networks. These network models potentially have application to COVID-19 modelling – they could be used to model shifting household, workplace or school and wider community interactions, and thus opportunity for transmission of the virus. However, the networks models as currently implemented are not quite suitable for such purposes, modifying them is complex, and they are also very computationally intensive to run. For these reasons, we will focus on the simpler ICM simulation facilities provided by &lt;code&gt;EpiModel&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Interested readers should consult the extensive tutorials and other documentation for &lt;code&gt;EpiModel&lt;/code&gt; for a fuller treatment, but in a nutshell, an &lt;code&gt;EpiModel&lt;/code&gt; ICM simulation starts with a hypothetical population of individuals who are permitted to be in one of several groups, or &lt;em&gt;compartments&lt;/em&gt;, at any particular time. Out-of-the-box, &lt;code&gt;EpiModel&lt;/code&gt; supports several types of models, including the popular SIR model which uses &lt;strong&gt;S&lt;/strong&gt;usceptible, &lt;strong&gt;I&lt;/strong&gt;nfectious and &lt;strong&gt;R&lt;/strong&gt;ecovered compartments. At each time step of the simulation, individuals randomly encounter and are exposed to other individuals in the population. The intensity of this population mixing is controlled by an &lt;em&gt;act rate&lt;/em&gt; parameter, with each “act” representing an opportunity for disease transmission, or at least those “acts” between susceptible individuals and infectious individuals. Recovered individuals are no longer infectious and are assumed to be immune from further re-infection, so we are not interested in their interactions with others, nor are we interested in interactions between pairs of susceptible individuals, only the interactions between susceptible and infectious individuals. However, not every such opportunity for disease transmission will result in actual disease transmission. The probability of transmission at each interaction is controlled by an &lt;em&gt;infection probability&lt;/em&gt; parameter.&lt;/p&gt;
&lt;p&gt;It is easy to see that decreasing the &lt;code&gt;act.rate&lt;/code&gt; parameter is equivalent to increasing social distancing in the population, and decreasing the &lt;code&gt;inf.prob&lt;/code&gt; parameter is equates to increased practice of hygiene measures such as hand washing, use of hand sanitisers, not touching one’s face, and mask wearing by the infectious. This was what I explored in some detail in my &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-03-10-modelling-the-effects-of-public-health-interventions-on-covid-19-transmission-part-1/&#34;&gt;first personal blog post on simulating COVID-19 spread&lt;/a&gt;.&lt;/p&gt;
&lt;div id=&#34;extensions-to-epimodel&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Extensions to &lt;code&gt;EpiModel&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;However, the SIR model type is a bit too simplistic if we want to use the model to explore the potential effect of various public health measures on COVID-19 spread. Fortunately, &lt;code&gt;EpiModel&lt;/code&gt; provides a plug-in architecture that allows more elaborate models to be implemented. The full details of my recent extensions to &lt;code&gt;EpiModel&lt;/code&gt; can be found in my &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-03-18-modelling-the-effects-of-public-health-interventions-on-covid-19-transmission-part-2/&#34;&gt;second personal blog post on COVID-19 simulation&lt;/a&gt;, but the gist of it is that several new compartment types were added, as shown in the table below, with support for transition between them as shown in the diagram below the table. The dashed lines indicate infection interactions.&lt;/p&gt;
&lt;table&gt;
&lt;colgroup&gt;
&lt;col width=&#34;13%&#34; /&gt;
&lt;col width=&#34;86%&#34; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&#34;header&#34;&gt;
&lt;th&gt;Compartment&lt;/th&gt;
&lt;th&gt;Functional definition&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td&gt;S&lt;/td&gt;
&lt;td&gt;Susceptible individuals&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td&gt;E&lt;/td&gt;
&lt;td&gt;Exposed &lt;strong&gt;and&lt;/strong&gt; infected, not yet symptomatic but potentially infectious&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td&gt;I&lt;/td&gt;
&lt;td&gt;Infected, symptomatic &lt;strong&gt;and&lt;/strong&gt; infectious&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td&gt;Q&lt;/td&gt;
&lt;td&gt;Infectious, but (self-)quarantined&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td&gt;H&lt;/td&gt;
&lt;td&gt;Requiring hospitalisation (would normally be hospitalised if capacity available)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td&gt;R&lt;/td&gt;
&lt;td&gt;Recovered, immune from further infection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td&gt;F&lt;/td&gt;
&lt;td&gt;Case fatality (death due to COVID-19, not other causes)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:672px;height:480px;&#34; class=&#34;grViz html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;diagram&#34;:&#34;\ndigraph SEIQHRF {\n\n  # a \&#34;graph\&#34; statement\n  graph [overlap = false, fontsize = 10] #, rankdir = LR]\n\n  # several \&#34;node\&#34; statements\n  node [shape = box,\n        fontname = Helvetica]\n  S[label=\&#34;S=Susceptible\&#34;];\n  E[label=\&#34;E=Exposed and infected,\nasymptomatic,\npotentially infectious\&#34;];\n  I[label=\&#34;I=Infected and infectious\&#34;];\n  Q[label=\&#34;Q=(Self-)quarantined\n(infectious)\&#34;];\n  H[label=\&#34;H=Requires\nhospitalisation\&#34;];\n  R[label=\&#34;R=Recovered/immune\&#34;];\n  F[label=\&#34;F=Case fatality\&#34;]\n\n  # several \&#34;edge\&#34; statements\n  S-&gt;E\n  I-&gt;S[style=\&#34;dashed\&#34;]\n  E-&gt;I\n  E-&gt;S[style=\&#34;dashed\&#34;]\n  I-&gt;Q\n  Q-&gt;S[style=\&#34;dashed\&#34;]\n  I-&gt;R\n  I-&gt;H\n  H-&gt;F\n  H-&gt;R\n  Q-&gt;R\n  Q-&gt;H\n}\n&#34;,&#34;config&#34;:{&#34;engine&#34;:&#34;dot&#34;,&#34;options&#34;:null}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;Another capability that has been added is the ability to specify time-variant parameters, as a vector of the same length as there are time steps in the simulation. This allows us to smoothly (or step-wise) introduce, and withdraw, various interventions at arbitrary times during the course of our simulation.&lt;/p&gt;
&lt;p&gt;We won’t cover here the details of how to obtain these extensions, which at the time of writing should still be considered &lt;em&gt;alpha&lt;/em&gt; quality code – please see the &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-03-18-modelling-the-effects-of-public-health-interventions-on-covid-19-transmission-part-2/&#34;&gt;blog post&lt;/a&gt; for those. Let’s just proceed to running some simulations.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;baseline-simulation&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Baseline simulation&lt;/h1&gt;
&lt;p&gt;First we’ll run a baseline simulation for a hypothetical population of 10,000 people, in which there are just three infectious COVID-19 cases at the outset. We’ll run it for 365 days, and we’ll set a very low rate at which infectious individuals enter self-quarantine (thereby dramatically lowering their rate of interactions with others) after they become symptomatic (or have been tested and found positive), and thus aware of their infectivity. Because it is stochastic, the simulation is run eight times, using parallel processing if available, and the results averaged.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tic()
baseline_sim &amp;lt;- simulate(ncores = 4)
toc()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 58.092 sec elapsed&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s visualise the results as a set of time-series of the daily count of our 10,000 individuals in each compartment.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-19-simulating-covid-19-interventions-with-r/index_files/figure-html/unnamed-chunk-5-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;OK, that looks very reasonable. Note that almost the entire population ends up being infected. However, the &lt;strong&gt;S&lt;/strong&gt; and &lt;strong&gt;R&lt;/strong&gt; compartments dominate the plot (which is good, because it means humanity will survive!), so let’s re-plot leaving out those compartments so we can see a bit more detail.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-19-simulating-covid-19-interventions-with-r/index_files/figure-html/unnamed-chunk-6-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Notice that the &lt;strong&gt;I&lt;/strong&gt; compartment curve lags behind the &lt;strong&gt;E&lt;/strong&gt; compartment curve – the lag is the incubation period, and that the &lt;strong&gt;Q&lt;/strong&gt; curve lags still further as infected people only reluctantly and belatedly quarantine themselves (in this baseline scenario).&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;running-intervention-experiments&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Running intervention experiments&lt;/h1&gt;
&lt;p&gt;Now we are in a position to run an experiment, by altering some parameters of our baseline model.&lt;/p&gt;
&lt;p&gt;Let’s model the effect of decreasing the infection probability at each exposure event by smoothly decreasing the &lt;code&gt;inf.prob&lt;/code&gt; parameters for the &lt;strong&gt;I&lt;/strong&gt; compartment. The infection probability at each exposure event (for the &lt;strong&gt;I&lt;/strong&gt; compartment individuals) starts at 5%, and we’ll reduce it to 2% between days 15 and 30. This models the effect of symptomatic infected people adopting better hygiene practices such as wearing masks, coughing into their elbows, using hand sanitisers, not shaking hands and so on, perhaps in response to a concerted public health advertising campaign by the government.&lt;/p&gt;
&lt;p&gt;Let’s examine the results of experiment 1, alongside the baseline for comparison:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;exp-1.png&#34; height = &#34;500&#34; width=&#34;700&#34;&gt;&lt;/p&gt;
&lt;p&gt;We can see from the plots on the left that by encouraging hygiene measures in symptomatic infectious individuals, we have not only substantially “flattened the curve”, but we have actually shrunk it. The result, as shown in the plots on the right, is that demand for hospital beds is substantially reduced, and only briefly exceeds our defined hospital capacity of 40 bed. This results in a substantially reduced mortality rate, shown by the black line.&lt;/p&gt;
&lt;div id=&#34;more-experiments&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;More experiments&lt;/h2&gt;
&lt;p&gt;We can now embark on a series of experiments, exploring various interventions singly, or in combination, and with different timings.&lt;/p&gt;
&lt;div id=&#34;experiment-2&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Experiment 2&lt;/h3&gt;
&lt;p&gt;Let’s repeat experiment 1, but let’s delay the start of the hygiene campaign until day 30 and make it less intense so it takes until day 60 to achieve the desired increase in hygiene in the symptomatic infected.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;infectious_hygiene_delayed_ramp &amp;lt;- function(t) {
  ifelse(t &amp;lt; 30, 0.05, ifelse(t &amp;lt;= 60, 0.05 - (t - 30) * (0.05 - 
    0.02)/30, 0.02))
}

infectious_hygiene_delayed_ramp_sim &amp;lt;- simulate(inf.prob.i = infectious_hygiene_delayed_ramp(1:366))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;experiment-3&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Experiment 3&lt;/h3&gt;
&lt;p&gt;Let’s repeat experiment 1, except this time instead of promoting hygiene measures in the symptomatic infected, we’ll promote, starting at day 15, prompt self-quarantine by anyone who is infected as soon as they become symptomatic. By “prompt”, we mean most such people will self-quarantine themselves immediately, but with an exponentially declining tail of such people taking longer to enter quarantine, with a few never complying. Those in self-quarantine won’t or can’t achieve complete social isolation, so we have set the &lt;code&gt;act.rate&lt;/code&gt; parameter for the quarantined compartment to a quarter of that for the other compartments to simulate such a reduction in social mixing (an increase in social distancing) in that group.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;quarantine_ramp &amp;lt;- function(t) {
  ifelse(t &amp;lt; 15, 0.0333, ifelse(t &amp;lt;= 30, 0.0333 + (t - 15) * 
    (0.3333 - 0.0333)/15, 0.333))
}

quarantine_ramp_sim &amp;lt;- simulate(quar.rate = quarantine_ramp(1:366))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;experiment-4&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Experiment 4&lt;/h3&gt;
&lt;p&gt;Let’s add a moderate increase in social distancing for everyone (halving the &lt;code&gt;act.rate&lt;/code&gt;), again ramping it down between days 15 and 30.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;social_distance_ramp &amp;lt;- function(t) {
  ifelse(t &amp;lt; 15, 10, ifelse(t &amp;lt;= 30, 10 - (t - 15) * (10 - 
    5)/15, 5))
}

soc_dist_ramp_sim &amp;lt;- simulate(act.rate.i = social_distance_ramp(1:366), 
  act.rate.e = social_distance_ramp(1:366))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;experiment-5&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Experiment 5&lt;/h3&gt;
&lt;p&gt;Let’s combine experiments 3 and 4: we’ll add a moderate increase in social distancing for everyone, as well as prompt self-quarantining in the symptomatic.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;quar_soc_dist_ramp_sim &amp;lt;- simulate(quar.rate = quarantine_ramp(1:366), 
  act.rate.i = social_distance_ramp(1:366), act.rate.e = social_distance_ramp(1:366))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let’s examine the results.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;exp-5A.png&#34; height = &#34;500&#34; width=&#34;700&#34;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;discussion&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Discussion&lt;/h2&gt;
&lt;p&gt;The results of our experiments almost speak for themselves, but a few things are worth highlighting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Implementing interventions too late is almost worthless. Act early and decisively. You can always wind back the intervention later, whereas a failure to act early enough can never be recovered from.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prompt self-quarantining of symptomatic cases is effective. In practice that means everyone with COVID-19-like symptoms, whether they actually have COVID-19 or something else, should immediately self-quarantine. Don’t wait to be tested.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A moderate increase in social distancing (decrease in social mixing) in everyone is also effective, mainly because it reduces exposure opportunities with both the asymptomatic-but-infected and the symptomatic infected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Combining measures is even more effective, as can be seen in experiment 5. In fact, there are theoretical reasons to believe that the effect of combined measures is partially multiplicative, not just additive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public health interventions don’t just flatten the curve, they shrink it, and the result is very substantially reduced mortality due to COVID-19.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;None of these insights are novel, but it is nice to be able to independently confirm the recommendations of various expert groups, such as the WHO Collaborating Centre for Infectious Disease Modelling at Imperial College London (ICL) who have recently released a &lt;a href=&#34;https://www.imperial.ac.uk/mrc-global-infectious-disease-analysis/news--wuhan-coronavirus/&#34;&gt;report on the impact of non-pharmaceutical interventions (NPIs) to reduce COVID-19 mortality and healthcare demand&lt;/a&gt; which recommends similar strategies to those we have just discovered from our modest simulations in &lt;code&gt;R&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;two-more-experiments&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Two more experiments&lt;/h1&gt;
&lt;p&gt;What happens if we dramatically increase social distancing through a two week lock-down, which is then relaxed? We’ll use a step function to model this. We test such a lock-down lasting from day 15 to 30, and separately a lock-down from day 30 to day 45 instead. We’ll model the lock-down by reducing the &lt;code&gt;act.rate&lt;/code&gt; parameters for all compartments from 10 to 2.5.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;twoweek_lockdown_day15_vector &amp;lt;- c(rep(10, 15), rep(2.5, 15), 
  rep(10, 336))
twoweek_lockdown_day30_vector &amp;lt;- c(rep(10, 30), rep(2.5, 15), 
  rep(10, 321))

twoweek_lockdown_day15_sim &amp;lt;- simulate(act.rate.i = twoweek_lockdown_day15_vector, 
  act.rate.e = twoweek_lockdown_day15_vector)

twoweek_lockdown_day30_sim &amp;lt;- simulate(act.rate.i = twoweek_lockdown_day30_vector, 
  act.rate.e = twoweek_lockdown_day30_vector)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;exp-6A.png&#34; height = &#34;500&#34; width=&#34;700&#34;&gt;&lt;/p&gt;
&lt;p&gt;Wow, that’s a bit surprising! The two week lock-down starting at day 15 isn’t effective at all - it just stops the spread in its tracks for two weeks, and then it just resumes again.
But a two-week lock-down starting at day 30 is somewhat more effective, presumably because there are more infected people being taken out of circulation from day 30 onwards. But the epidemic still partially bounces back after the two weeks are over.&lt;/p&gt;
&lt;p&gt;What this tells us is that single lock-downs for only two weeks aren’t effective. What about a lock-down for a whole month, instead, combined with prompt quarantine with even more effective isolation and hygiene measures for those quarantined?&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;fourweek_lockdown_day15_vector &amp;lt;- c(rep(10, 15), rep(2.5, 30), 
  rep(7.5, 321))
fourweek_lockdown_day30_vector &amp;lt;- c(rep(10, 30), rep(2.5, 30), 
  rep(7.5, 306))

fourweek_lockdown_day15_sim &amp;lt;- simulate(act.rate.i = fourweek_lockdown_day15_vector, 
  act.rate.e = fourweek_lockdown_day15_vector, quar.rate = quarantine_ramp(1:366), 
  inf.prob.q = 0.01)

fourweek_lockdown_day30_sim &amp;lt;- simulate(act.rate.i = fourweek_lockdown_day30_vector, 
  act.rate.e = fourweek_lockdown_day30_vector, quar.rate = quarantine_ramp(1:366), 
  inf.prob.q = 0.01)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;exp-7A.png&#34; height = &#34;500&#34; width=&#34;700&#34;&gt;&lt;/p&gt;
&lt;p&gt;Well, that’s satisfying! By acting early, and decisively, we’ve managed to stop COVID-19 dead in it tracks in experiment 8, and in doing so have saved many lives – at least, we have in our little simulated world. But even experiment 9 provides a much better outcome, indicating that decisive action, even if somewhat belated, is much better than none.&lt;/p&gt;
&lt;p&gt;Of course, the real world is far more complex and messier, and COVID-19 may not behave in exactly the same way in real-life, but at least we can see the principles of public health interventions in action in our simulation, and perhaps better understand or want to question what is being done, or not done, or being done too late, to contain the spread of the virus in the real world.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;conclusion&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;Although there is still a lot of work yet to be done on the extensions to &lt;code&gt;EpiModel&lt;/code&gt; demonstrated here, it seems that they offer promise as a tool for understanding real-world action and inaction on COVID-19, and prompting legitimate questions about such actions or lack thereof.&lt;/p&gt;
&lt;p&gt;One would hope that governments are using far more sophisticated simulation models than the one we have described here, which was built over the course of just a few days, to plan or inform their responses to COVID-19. If not, they ought to be.&lt;/p&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2020/03/19/simulating-covid-19-interventions-with-r/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>COVID-19 epidemiology with R</title>
      <link>https://rviews.rstudio.com/2020/03/05/covid-19-epidemiology-with-r/</link>
      <pubDate>Thu, 05 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2020/03/05/covid-19-epidemiology-with-r/</guid>
      <description>
        


&lt;p&gt;&lt;em&gt;Tim Churches is a Senior Research Fellow at the UNSW Medicine South Western Sydney Clinical School at Liverpool Hospital, and a health data scientist at the Ingham Institute for Applied Medical Research, also located at Liverpool, Sydney. His background is in general medicine, general practice medicine, occupational health, public health practice, particularly population health surveillance, and clinical epidemiology.&lt;/em&gt;&lt;/p&gt;
&lt;div id=&#34;introduction&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;As I write this on 4th March, 2020, the world is on the cusp of a global COVID-19 pandemic caused by the SARS-Cov2 virus. Every news report is dominated by alarming, and ever-growing cumulative counts of global cases and deaths due to COVID-19. &lt;a href=&#34;https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html&#34;&gt;Dashboards of global spread&lt;/a&gt; are beginning to light up like Christmas trees.&lt;/p&gt;
&lt;p&gt;For &lt;code&gt;R&lt;/code&gt; users, an obvious question is: “Does &lt;code&gt;R&lt;/code&gt; have anything to offer in helping to understand the situation?”.&lt;/p&gt;
&lt;p&gt;The answer is: “Yes, a lot!”.&lt;/p&gt;
&lt;p&gt;In fact, &lt;code&gt;R&lt;/code&gt; is one of the tools of choice for outbreak epidemiologists, and a quick search will yield many &lt;code&gt;R&lt;/code&gt; libraries on CRAN and elsewhere devoted to outbreak management and analysis. This post doesn’t seek to provide a review of the available packages – rather it illustrates the utility of a few of the excellent packages available in the &lt;a href=&#34;https://www.repidemicsconsortium.org&#34;&gt;&lt;strong&gt;R&lt;/strong&gt; &lt;strong&gt;E&lt;/strong&gt;pidemics &lt;strong&gt;Con&lt;/strong&gt;sortium (&lt;strong&gt;RECON&lt;/strong&gt;) suite&lt;/a&gt;, as well as the use of base &lt;code&gt;R&lt;/code&gt; and &lt;a href=&#34;https://www.tidyverse.org&#34;&gt;&lt;code&gt;tidyverse&lt;/code&gt;&lt;/a&gt; packages for data acquisition, wrangling and visualization. This post is based on &lt;a href=&#34;https://timchurches.github.io/blog/&#34;&gt;two much longer and more detailed blog posts&lt;/a&gt; I have published in the last few weeks on the same topic, but it uses US data.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;data-acquisition&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Data acquisition&lt;/h1&gt;
&lt;p&gt;Obtaining detailed, accurate and current data for the COVID-19 epidemic is not as straightforward as it might seem. Various national and provincial/governmental web sites in affected countries provide detailed summary data on incident cases, recovered cases and deaths due to the virus, but these data tend to be in the form of counts embedded in (usually non-English) text.&lt;/p&gt;
&lt;p&gt;There are several potential sources of data which have been abstracted and collated from such governmental sites. A widely-used source is a &lt;a href=&#34;https://github.com/CSSEGISandData/COVID-19&#34;&gt;dataset&lt;/a&gt; which is being collated by Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) and which is used as the source for &lt;a href=&#34;https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6&#34;&gt;the dashboard&lt;/a&gt; mentioned above. It is very easy to use – just read CSV files from the appropriate GitHub URL. However, it lacks detail (that wasn’t its intended purpose) and contains quite a few missing or anomalous data points when examined as a differenced daily time-series of incident cases, a relatively minor issue that is explored further &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-02-18-analysing-covid-19-2019-ncov-outbreak-data-with-r-part-1/#checking-the-data&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Another set of convenient sources are relevant wikipedia pages, such as &lt;a href=&#34;https://en.wikipedia.org/wiki/Timeline_of_the_2019–20_Wuhan_coronavirus_outbreak&#34;&gt;this one for China&lt;/a&gt;. There are equivalent pages for &lt;a href=&#34;https://en.wikipedia.org/wiki/Template:2019–20_coronavirus_outbreak_data/Japan_medical_cases&#34;&gt;Japan&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/Template:2019–20_coronavirus_outbreak_data/South_Korea_medical_cases&#34;&gt;South Korea&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/Template:2019–20_coronavirus_outbreak_data/Iran_medical_cases&#34;&gt;Iran&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/Template:2019–20_coronavirus_outbreak_data/Italy_medical_cases&#34;&gt;Italy&lt;/a&gt; and many other countries. These wikipedia pages tend to be much more detailed and are well-referenced back to the original source web pages, but they are quite challenging to web-scrape because the format of the tables in which the data appears changes quite often, as various wikipedia contributors adjust their appearance. Nonetheless, we’ll scrape some detailed data about the initial set of identified COVID-19 cases in the United States (as at 4th March) from a suitable wikipedia page. The saving grace is that wikipedia pages are versioned, and thus it is possible to scrape data from a specific version of a table. But if you want daily updates to your data, using wikipedia pages as a source will involve daily maintenance of your web scraping code.&lt;/p&gt;
&lt;div id=&#34;incidence-data-collated-by-john-hopkins-university&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Incidence data collated by John Hopkins University&lt;/h2&gt;
&lt;p&gt;Acquiring these data is easy. The time-series format they provide is the most convenient for our purposes. We’ll also remove columns of US cases associated with the &lt;em&gt;Diamond Princess&lt;/em&gt; cruise ship because we can assume that those cases were (home) quarantined on repatriation and were unlikely, or at least a lot less likely, to give rise to further cases. We also shift the dates in the JHU data back one day reflect US time zones, somewhat approximately, because the original dates are with respect to midnight UTC (Greenwich time). That is necessary because we will be combining the JHU data with wikipedia-sourced US data, which is tabulated by dates referencing local US time zones.&lt;/p&gt;
&lt;p&gt;We also need to difference the JHU data, which is provided as cumulative counts, to get daily incident counts. Incident counts of cases are a lot more epidemiologically useful than cumulative counts. &lt;code&gt;dplyr&lt;/code&gt; makes short work of all that.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;jhu_url &amp;lt;- paste(&amp;quot;https://raw.githubusercontent.com/CSSEGISandData/&amp;quot;, 
  &amp;quot;COVID-19/master/csse_covid_19_data/&amp;quot;, &amp;quot;csse_covid_19_time_series/&amp;quot;, 
  &amp;quot;time_series_19-covid-Confirmed.csv&amp;quot;, sep = &amp;quot;&amp;quot;)

us_confirmed_long_jhu &amp;lt;- read_csv(jhu_url) %&amp;gt;% rename(province = &amp;quot;Province/State&amp;quot;, 
  country_region = &amp;quot;Country/Region&amp;quot;) %&amp;gt;% pivot_longer(-c(province, 
  country_region, Lat, Long), names_to = &amp;quot;Date&amp;quot;, values_to = &amp;quot;cumulative_cases&amp;quot;) %&amp;gt;% 
  # adjust JHU dates back one day to reflect US time, more or
# less
mutate(Date = mdy(Date) - days(1)) %&amp;gt;% filter(country_region == 
  &amp;quot;US&amp;quot;) %&amp;gt;% arrange(province, Date) %&amp;gt;% group_by(province) %&amp;gt;% 
  mutate(incident_cases = c(0, diff(cumulative_cases))) %&amp;gt;% 
  ungroup() %&amp;gt;% select(-c(country_region, Lat, Long, cumulative_cases)) %&amp;gt;% 
  filter(str_detect(province, &amp;quot;Diamond Princess&amp;quot;, negate = TRUE))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can now visualize the JHU data using &lt;code&gt;ggplot2&lt;/code&gt;, summarized for the whole of the US:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/plot_jhu_data-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;So, not a lot of data to work with as yet. One thing that is missing is information on whether those cases were &lt;em&gt;imported&lt;/em&gt;, that is, the infection was most likely acquired outside the US, or whether they were &lt;em&gt;local&lt;/em&gt;, as a result of local transmission (possibly from imported cases).&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;scraping-wikipedia&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Scraping wikipedia&lt;/h2&gt;
&lt;p&gt;The wikipedia page on COVID-19 in the US contains several tables, one of which contains a line-listing of all the initial US cases, which at the time of writing appeared to be fairly complete up to 2nd March. We’ll scrape that line-listing table from &lt;a href=&#34;https://en.wikipedia.org/w/index.php?title=2020_coronavirus_outbreak_in_the_United_States&amp;amp;oldid=944107102&#34;&gt;this version of the wikipedia page&lt;/a&gt;, leveraging the excellent &lt;code&gt;rvest&lt;/code&gt; package, part of the &lt;code&gt;tidyverse&lt;/code&gt;. Once again we need to do a bit of data wrangling to get the parsed table into a usable form.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# the URL of the wikipedia page to use is in wp_page_url
wp_page_url&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;https://en.wikipedia.org/w/index.php?title=2020_coronavirus_outbreak_in_the_United_States&amp;amp;oldid=944107102&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# read the page using the rvest package.
outbreak_webpage &amp;lt;- read_html(wp_page_url)

# parse the web page and extract the data from the eighth
# table
us_cases &amp;lt;- outbreak_webpage %&amp;gt;% html_nodes(&amp;quot;table&amp;quot;) %&amp;gt;% .[[8]] %&amp;gt;% 
  html_table(fill = TRUE)

# The automatically assigned column names are OK except that
# instead of County/city and State columns we have two
# columns called Location, due to the unfortunate use of
# colspans in the header row.  The tidyverse abhors
# duplicated column names, so we have to fix those, and make
# some of the other colnames a bit more tidyverse-friendly.
us_cases_colnames &amp;lt;- colnames(us_cases)
us_cases_colnames[min(which(us_cases_colnames == &amp;quot;Location&amp;quot;))] &amp;lt;- &amp;quot;CityCounty&amp;quot;
us_cases_colnames[min(which(us_cases_colnames == &amp;quot;Location&amp;quot;))] &amp;lt;- &amp;quot;State&amp;quot;
us_cases_colnames &amp;lt;- us_cases_colnames %&amp;gt;% str_replace(&amp;quot;Location&amp;quot;, 
  &amp;quot;CityCounty&amp;quot;) %&amp;gt;% str_replace(&amp;quot;Location&amp;quot;, &amp;quot;State&amp;quot;) %&amp;gt;% str_replace(&amp;quot;Case no.&amp;quot;, 
  &amp;quot;CaseNo&amp;quot;) %&amp;gt;% str_replace(&amp;quot;Date announced&amp;quot;, &amp;quot;Date&amp;quot;) %&amp;gt;% str_replace(&amp;quot;CDC origin type&amp;quot;, 
  &amp;quot;OriginTypeCDC&amp;quot;) %&amp;gt;% str_replace(&amp;quot;Treatment facility&amp;quot;, &amp;quot;TreatmentFacility&amp;quot;)
colnames(us_cases) &amp;lt;- us_cases_colnames

# utility function to remove wikipedia references in square
# brackets
rm_refs &amp;lt;- function(x) stringr::str_split(x, &amp;quot;\\[&amp;quot;, simplify = TRUE)[, 
  1]

# now remove references from CaseNo column, convert it to
# integer, convert the date column to date type and then lose
# all rows which then have NA in CaseNo or NA in the date
# column
us_cases &amp;lt;- us_cases %&amp;gt;% mutate(CaseNo = rm_refs(CaseNo)) %&amp;gt;% 
  mutate(CaseNo = as.integer(CaseNo), Date = as.Date(parse_date_time(Date, 
    c(&amp;quot;%B %d, %Y&amp;quot;, &amp;quot;%d %B, %Y&amp;quot;)))) %&amp;gt;% filter(!is.na(CaseNo), 
  !is.na(Date)) %&amp;gt;% # convert the various versions of unknown into NA in the
# OriginTypeCDC column
mutate(OriginTypeCDC = if_else(OriginTypeCDC %in% c(&amp;quot;Unknown&amp;quot;, 
  &amp;quot;Undisclosed&amp;quot;), NA_character_, OriginTypeCDC))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At this point we have an acceptably clean table, that looks like this:&lt;/p&gt;
&lt;style&gt;html {
  font-family: -apple-system, BlinkMacSystemFont, &#39;Segoe UI&#39;, Roboto, Oxygen, Ubuntu, Cantarell, &#39;Helvetica Neue&#39;, &#39;Fira Sans&#39;, &#39;Droid Sans&#39;, Arial, sans-serif;
}

#aessoebrkv .gt_table {
  display: table;
  border-collapse: collapse;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#aessoebrkv .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#aessoebrkv .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#aessoebrkv .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 0;
  padding-bottom: 4px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#aessoebrkv .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#aessoebrkv .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#aessoebrkv .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#aessoebrkv .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#aessoebrkv .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#aessoebrkv .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#aessoebrkv .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#aessoebrkv .gt_group_heading {
  padding: 8px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
}

#aessoebrkv .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#aessoebrkv .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#aessoebrkv .gt_from_md &gt; :first-child {
  margin-top: 0;
}

#aessoebrkv .gt_from_md &gt; :last-child {
  margin-bottom: 0;
}

#aessoebrkv .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#aessoebrkv .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 12px;
}

#aessoebrkv .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#aessoebrkv .gt_first_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
}

#aessoebrkv .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#aessoebrkv .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#aessoebrkv .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#aessoebrkv .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#aessoebrkv .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding: 4px;
}

#aessoebrkv .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#aessoebrkv .gt_sourcenote {
  font-size: 90%;
  padding: 4px;
}

#aessoebrkv .gt_left {
  text-align: left;
}

#aessoebrkv .gt_center {
  text-align: center;
}

#aessoebrkv .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#aessoebrkv .gt_font_normal {
  font-weight: normal;
}

#aessoebrkv .gt_font_bold {
  font-weight: bold;
}

#aessoebrkv .gt_font_italic {
  font-style: italic;
}

#aessoebrkv .gt_super {
  font-size: 65%;
}

#aessoebrkv .gt_footnote_marks {
  font-style: italic;
  font-size: 65%;
}
&lt;/style&gt;
&lt;div id=&#34;aessoebrkv&#34; style=&#34;overflow-x:auto;overflow-y:auto;width:auto;height:auto;&#34;&gt;&lt;table class=&#34;gt_table&#34;&gt;
  &lt;thead class=&#34;gt_header&#34;&gt;
    &lt;tr&gt;
      &lt;th colspan=&#34;10&#34; class=&#34;gt_heading gt_title gt_font_normal&#34; style&gt;US cases of COVID-19 as at 3rd March 2020&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th colspan=&#34;10&#34; class=&#34;gt_heading gt_subtitle gt_font_normal gt_bottom_border&#34; style&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;thead class=&#34;gt_col_headings&#34;&gt;
    &lt;tr&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;CaseNo&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;Date&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;Status&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;OriginTypeCDC&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;Origin&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;CityCounty&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;State&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;TreatmentFacility&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;Sex&lt;/th&gt;
      &lt;th class=&#34;gt_col_heading gt_columns_bottom_border gt_left&#34; rowspan=&#34;1&#34; colspan=&#34;1&#34;&gt;Age&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody class=&#34;gt_table_body&#34;&gt;
    &lt;tr class=&#34;gt_group_heading_row&#34;&gt;
      &lt;td colspan=&#34;10&#34; class=&#34;gt_group_heading&#34;&gt;Last 6 rows&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;60&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-04&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Deceased&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;NA&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Unknown&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Placer County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;California&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Hospitalized&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Elderly adult&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;61&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-04&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;NA&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Unknown&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Santa Clara County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;California&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Hospitalized&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;62&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-04&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Person-to-person spread&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Santa Clara County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;California&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;In-home isolation&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;63&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-04&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Person-to-person spread&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Santa Clara County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;California&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;In-home isolation&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;64&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-04&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;NA&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Unknown&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Williamson County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Tennessee&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;In-home isolation&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;44&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;65&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-05&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Unknown&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Clark County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Nevada&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;VA Southern Nevada Healthcare System&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;50&#39;s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;66&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-03-05&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Unknown&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Chicago&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Illinois&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Rush University Medical Center&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;20&#39;s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class=&#34;gt_group_heading_row&#34;&gt;
      &lt;td colspan=&#34;10&#34; class=&#34;gt_group_heading&#34;&gt;First 6 rows&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;1&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-01-21&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Recovered&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Wuhan, China&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Snohomish County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Washington&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Providence Regional Medical Center Everett&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;35&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;2&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-01-24&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Recovered&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Wuhan, China&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Chicago&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Illinois&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;St. Alexius Medical Center&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Female&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;60s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;3&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-01-25&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Recovered&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Wuhan, China&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Orange County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;California&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;In-home isolation&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;50s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;4&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-01-26&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Confirmed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Wuhan, China&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Los Angeles County&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;California&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Undisclosed&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;5&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-01-26&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Recovered&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Travel-related&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Wuhan, China&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Tempe&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Arizona&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;In-home isolation&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Under 60&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_row gt_left gt_stub&#34;&gt;6&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;2020-01-30&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Recovered&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Person-to-person spread&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Spouse&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Chicago&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Illinois&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;St. Alexius Medical Center&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;Male&lt;/td&gt;
      &lt;td class=&#34;gt_row gt_left&#34;&gt;60s&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tfoot class=&#34;gt_sourcenotes&#34;&gt;
    &lt;tr&gt;
      &lt;td class=&#34;gt_sourcenote&#34; colspan=&#34;10&#34;&gt;Source: &lt;a href=&#34;https://en.wikipedia.org/w/index.php?title=2020_coronavirus_outbreak_in_the_United_States&amp;amp;oldid=944107102&#34;&gt;wikipedia: 2020 coronavirus outbreak in the United States&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tfoot&gt;
  
&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;We’ll won’t bother cleaning all the columns, because we’ll only be using a few of them here.&lt;/p&gt;
&lt;p&gt;OK, so we’ll use the wikipedia data prior to 20th February, but the JHU counts after that, but we’ll use the wikipedia data after 20th February to divide the JHU counts into travel-related or not, more or less. That will give us a data set which distinguishes local from imported cases, at least to the extent of completeness of our data sources. Outbreak epidemiology involves practicing the art of &lt;em&gt;good enough for now&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Let’s visualize each of our two sources, and the combined data set.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/combine_us_data-1.png&#34; width=&#34;768&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;analysis-with-the-earlyr-and-epiestim-packages&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Analysis with the &lt;code&gt;earlyR&lt;/code&gt; and &lt;code&gt;EpiEstim&lt;/code&gt; packages&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://www.repidemicsconsortium.org/earlyR/&#34;&gt;&lt;code&gt;earlyR&lt;/code&gt;&lt;/a&gt; package, as its name suggests, is intended for use early in an outbreak to calculate several key statistics. In particular the &lt;code&gt;get_R()&lt;/code&gt; function in &lt;code&gt;earlyR&lt;/code&gt; calculates a maximum-likelihood estimate for the reproduction number, which is the mean number of new cases each infected person give rise to. The &lt;code&gt;overall_infectivity()&lt;/code&gt; function in the &lt;code&gt;EpiEstim&lt;/code&gt; package calculates &lt;span class=&#34;math inline&#34;&gt;\(\lambda\)&lt;/span&gt; (lambda), which is a relative measure of the current “force of infection” or infectivity of an outbreak:&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math display&#34;&gt;\[ \lambda = \sum_{s=1}^{t-1} {y_{s} w (t - s)} \]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;where &lt;span class=&#34;math inline&#34;&gt;\(w()\)&lt;/span&gt; is the probability mass function (PMF) of the serial interval, and &lt;span class=&#34;math inline&#34;&gt;\(y_s\)&lt;/span&gt; is the incidence at time &lt;span class=&#34;math inline&#34;&gt;\(s\)&lt;/span&gt;. If &lt;span class=&#34;math inline&#34;&gt;\(\lambda\)&lt;/span&gt; is falling, then that’s good: if not, bad.&lt;/p&gt;
&lt;p&gt;The critical parameter for these calculations is the distribution of &lt;em&gt;serial intervals&lt;/em&gt; (SI), which is the time between the date of onset of symptoms for a case and the dates of onsets for any secondary cases that case gives rise to. Typically a discrete &lt;span class=&#34;math inline&#34;&gt;\(\gamma\)&lt;/span&gt; distribution for these &lt;em&gt;serial intervals&lt;/em&gt; is assumed, parameterised by a mean and standard deviation, although more complex distributions are probably more realistic. See the &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-02-18-analysing-covid-19-2019-ncov-outbreak-data-with-r-part-1/#estimating-changes-in-the-effective-reproduction-number&#34;&gt;previous post&lt;/a&gt; for more detailed discussion of the &lt;em&gt;serial interval&lt;/em&gt;, and the paramount importance of line-listing data from which it can be empirically estimated.&lt;/p&gt;
&lt;p&gt;For now, we’ll just use a discrete &lt;span class=&#34;math inline&#34;&gt;\(\gamma\)&lt;/span&gt; distribution with a mean of 5.0 days and a standard deviation of 3.4 for the &lt;em&gt;serial interval&lt;/em&gt; distribution. That mean is less than estimates published earlier in the outbreak in China, but appears to be closer to the behavior of the COVID-19 virus (based on a personal communication from an informed source who is party to WHO conference calls on COVID-19). Obviously a sensitivity analysis, using different but plausible &lt;em&gt;serial interval&lt;/em&gt; distributions, should be undertaken, but we’ll omit that here for the sake of brevity.&lt;/p&gt;
&lt;p&gt;Note that only local transmission is used to calculate &lt;span class=&#34;math inline&#34;&gt;\(\lambda\)&lt;/span&gt;. If we just use the JHU data, which includes both local and imported cases, our estimates of &lt;span class=&#34;math inline&#34;&gt;\(\lambda\)&lt;/span&gt; would be biased, upwards.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/us_lambda-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The US is not winning the war against COVID-19, but it is early days yet.&lt;/p&gt;
&lt;p&gt;We can also estimate the &lt;em&gt;reproduction number&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/us_plot_r-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;That estimate of &lt;span class=&#34;math inline&#34;&gt;\(R_{0}\)&lt;/span&gt; is consistent with those reported recently by WHO, although higher than some initial estimates from Wuhan. The key thing is that it is well above 1.0, meaning that the outbreak is growing, rapidly.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;fitting-a-log-linear-model-to-the-epidemic-curve&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Fitting a log-linear model to the &lt;em&gt;epidemic curve&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;We can also use functions in the &lt;strong&gt;RECON&lt;/strong&gt; &lt;code&gt;incidence&lt;/code&gt; package to fit a log-linear model to our epidemic curve. Typically, two models are fitted, one for the growth-phase and one for the decay phase. Functions are provided in the package for finding the peak of the epidemic curve using naïve and optimizing methods. Examples of that can be found &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-03-01-analysing-covid-19-2019-ncov-outbreak-data-with-r-part-2/#modelling-epidemic-trajectory-in-hubei-province-using-log-linear-models&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But for now, the US outbreak is still in growth phase, so we only fit one curve.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;us_incidence_fit &amp;lt;- incidence::fit(local_cases_obj, split = NULL)

# plot the incidence data and the model fit
plot(local_cases_obj) %&amp;gt;% add_incidence_fit(us_incidence_fit)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/us_growth_fit-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;That’s clearly not a good fit, because we are including the handful of very early cases that did not appear to establish sustained chains of local transmission. Let’s exclude them.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/us_growth_refit-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;That’s a much better fit!&lt;/p&gt;
&lt;p&gt;From the that model, we can extract various (very preliminary at this early stage) parameters of interest: the &lt;strong&gt;growth rate is 0.54&lt;/strong&gt; (95% CI 0.32 - 0.77), which is equivalent to a &lt;strong&gt;doubling time of 1.3 days&lt;/strong&gt; (95% CI 0.9 - 2.2 days).&lt;/p&gt;
&lt;p&gt;That’s all a bit alarming, but these estimates are almost certainly biased because cases are being tabulated by their &lt;strong&gt;date of reporting&lt;/strong&gt;, and not by their &lt;strong&gt;date of symptom onset&lt;/strong&gt;. I discussed the extreme importance of health authorities reporting or providing data by &lt;strong&gt;date of onset&lt;/strong&gt; &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-03-01-analysing-covid-19-2019-ncov-outbreak-data-with-r-part-2/#data-limitations&#34;&gt;in an earlier post&lt;/a&gt;. Nonetheless, as the the epidemic in the US spreads, the bias due to use of date of reporting should diminish, provided that testing and reporting of cases occurs swiftly and consistently. The ability to test and report cases promptly is a key indicator of the quality of public health intervention capability.&lt;/p&gt;
&lt;p&gt;We can also project how many cases might be expected in the next week, assuming that public health controls don’t start to have an effect, and subject to the estimation biases discussed above, and bearing it mind our model is fitted to just a few days of data, so far. We’ll plot on a log scale so the observed cases so far aren’t obscured by the predicted values.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/us_growth__refit_predict-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;On a linear scale, that looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/post/2020-03-05-covid-19-epidemiology-with-r/index_files/figure-html/us_growth_refit_predict_linear-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;So, we predict, on very sketchy preliminary data, over 2211 new cases per day by 10 March. That’s probably an overestimate, due to potential reporting-date-not-onset-date bias already discussed, but it nevertheless illustrates the exponential nature of typical epidemic behavior.&lt;/p&gt;
&lt;p&gt;Humans tend to use linear heuristics when contemplating trends, and thus tend to be surprised by such exponential behavior, and fail to plan for it accordingly.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;estimating-the-instantaneous-effective-reproduction-ratio&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Estimating the instantaneous &lt;em&gt;effective reproduction ratio&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;One other statistic which the &lt;code&gt;EpiEstim&lt;/code&gt; package estimates is the instantaneous effective reproduction number, based on an adjustable sliding window. This is very useful for assessing how well public health interventions are working. There isn’t enough US data available, yet, to estimate this, but here is an example of a plot of the instantaneous &lt;span class=&#34;math inline&#34;&gt;\(R_{e}\)&lt;/span&gt; for Hubei province in China, taken from an &lt;a href=&#34;https://timchurches.github.io/blog/posts/2020-02-18-analysing-covid-19-2019-ncov-outbreak-data-with-r-part-1/#estimating-changes-in-the-effective-reproduction-number&#34;&gt;earlier blog post&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://timchurches.github.io/blog/posts/2020-02-18-analysing-covid-19-2019-ncov-outbreak-data-with-r-part-1/analysing-covid-19-2019-ncov-outbreak-data-with-r-part-1_files/figure-html5/Cori_empirical_si_model_fit_hubei_daily-1.png&#34; alt=&#34;Instantaneous effect reproduction number for Hubei province&#34; style=&#34;width:70.0%&#34; /&gt;
You can clearly see the effect of the lock-down implemented in Hubei province and Wuhan city on or around 24th January, and the fact that the instantaneous &lt;span class=&#34;math inline&#34;&gt;\(R_{e}\)&lt;/span&gt; started to fall a long time before the daily incidence of new cases reached its peak. Availability of such information helps governmental authorities to keep their nerve and to persist with unpopular public health measures, even in the face of rising incidence.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;conclusion&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;In this post we have seen how base &lt;code&gt;R&lt;/code&gt;, the &lt;code&gt;tidyverse&lt;/code&gt; packages, and libraries provided by &lt;a href=&#34;https://www.repidemicsconsortium.org&#34;&gt;&lt;strong&gt;R&lt;/strong&gt; &lt;strong&gt;E&lt;/strong&gt;pidemics &lt;strong&gt;Con&lt;/strong&gt;sortium (&lt;strong&gt;RECON&lt;/strong&gt;)&lt;/a&gt; can be used to assemble COVID-19 outbreak data, visualize it, and estimate some key statistics from it which are vital for assessing and planning the public health response to this disease. There are several other libraries for &lt;code&gt;R&lt;/code&gt; than can also be used for such purposes. It should only take a small team of data scientists a few days, using these and related tools, to construct ongoing reports or decision support tools, able to be updated continuously, or at least daily, to help support public health authorities in their (literally) life-and-death fight against COVID-19.&lt;/p&gt;
&lt;p&gt;But you need to start right away: epidemic behavior is exponential.&lt;/p&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2020/03/05/covid-19-epidemiology-with-r/&#39;;&lt;/script&gt;
      </description>
    </item>
    
  </channel>
</rss>
