Overview of the incidence package

Thibaut Jombart, Zhian N. Kamvar

2019-03-14

incidence implements functions and classes to compute, handle, visualise and model incidences from dates data. This vignette provides an overview of current features. It largely reproduces the content of REAME.md.


Installing the package

To install the current stable, CRAN version of the package, type:

install.packages("incidence")

To benefit from the latest features and bug fixes, install the development, github version of the package using:

devtools::install_github("reconhub/incidence")

Note that this requires the package devtools installed.


What does it do?

The main functions of the package include:

Worked example: simulated Ebola outbreak

Loading the data

This example uses the simulated Ebola Virus Disease (EVD) outbreak from the package outbreaks. We will compute incidence for various time steps, calibrate two exponential models around the peak of the epidemic, and analyse the results.

First, we load the data:

Computing and plotting incidence

We compute the daily incidence:

The daily incidence is quite noisy, but we can easily compute other incidence using larger time intervals:

incidence can also compute incidence by specified groups using the groups argument. For instance, we can compute incidence by gender:

We can do the same for hospitals, using the ‘clean’ version of the dataset, with some customization of the legend:

Handling incidence objects

incidence objects can be manipulated easily. The [ operator implements subsetting of dates (first argument) and groups (second argument). For instance, to keep only the peak of the distribution:

Or to keep every other week:

Some temporal subsetting can be even simpler using subset, which permits to retain data within a specified time window:

Subsetting groups can also matter. For instance, let’s try and visualise the incidence based on onset of symptoms by outcome:

By default, incidence treats missing data (NA) as a separate group (see argument na_as_group). We could disable this to retain only known outcomes, but alternatively we can simply subset the object to exclude the last (3rd) group:

Groups can also be collapsed into a single time series using pool:

Modelling incidence

Incidence data, excluding zeros, can be modelled using log-linear regression of the form: log(y) = r x t + b

where y is the incidence, r is the growth rate, t is the number of days since a specific point in time (typically the start of the outbreak), and b is the intercept.

Such model can be fitted to any incidence object using fit. Of course, a single log-linear model is not sufficient for modelling our epidemic curve, as there is clearly an growing and a decreasing phase. As a start, we can calibrate a model on the first 20 weeks of the epidemic:

The resulting objects (known as incidence_fit objects) can be plotted, in which case the prediction and its confidence interval is displayed:

However, a better way to display these predictions is adding them to the incidence plot using the argument fit:

In this case, we would ideally like to fit two models, before and after the peak of the epidemic. This is possible using the following approach, if you know what date to use to split the data in two phases:

This is much better, but the splitting date is not completely optimal. To look for the best possible splitting date (i.e. the one maximizing the average fit of both models), we use:

These models are very good approximation of these data, showing a doubling time of 23.2 days during the first phase, and a halving time of 68.2 days during the second. To access these parameters, you can use the get_info() function.

The possible parameters are:

For “r”, “doubling”, and “halving”, you can also add “.conf” to get the confidence intervals. Here’s how you can get the doubling and halving times of the above epi curve:

Note that fit will also take groups into account if incidence has been computed for several groups:

#> 
#> $split
#>            f            m 
#> "2014-09-22" "2014-09-15" 
#> 
#> $fit
#> <list of incidence_fit objects>
#> 
#> attr(x, 'locations'): list of vectors with the locations of each incidence_fit object
#> 
#> 'f', 'before'
#> 'm', 'before'
#> 'f', 'after'
#> 'm', 'after'
#> 
#> $model: regression of log-incidence over time
#> 
#> $info: list containing the following items:
#>   $r (daily growth rate):
#>    f_before    m_before     f_after     m_after 
#>  0.02570604  0.02883607 -0.01002297 -0.01038307 
#> 
#>   $r.conf (confidence interval):
#>                2.5 %       97.5 %
#> f_before  0.02289333  0.028518743
#> m_before  0.02502254  0.032649606
#> f_after  -0.01102735 -0.009018595
#> m_after  -0.01138910 -0.009377034
#> 
#>   $doubling (doubling time in days):
#> f_before m_before 
#> 26.96437 24.03750 
#> 
#>   $doubling.conf (confidence interval):
#>             2.5 %   97.5 %
#> f_before 24.30497 30.27725
#> m_before 21.22988 27.70091
#> 
#>   $halving (halving time in days):
#>  f_after  m_after 
#> 69.15586 66.75746 
#> 
#>   $halving.conf (confidence interval):
#>            2.5 %   97.5 %
#> f_after 62.85711 76.85756
#> m_after 60.86059 73.91966
#> 
#>   $pred: data.frame of incidence predictions (111 rows, 7 columns)
plot(i.7.sex, fit=best.fit2$fit)
#> Scale for 'colour' is already present. Adding another scale for
#> 'colour', which will replace the existing scale.
#> Scale for 'colour' is already present. Adding another scale for
#> 'colour', which will replace the existing scale.
#> Scale for 'colour' is already present. Adding another scale for
#> 'colour', which will replace the existing scale.
#> Scale for 'colour' is already present. Adding another scale for
#> 'colour', which will replace the existing scale.

Using get_info() on this fit object will return all groups together: