This vignette documents to types of conversion which can be made using the incidence class:

  • ‘exports’: conversion from an incidence object to another type of object; this can be useful for processing incidence data in another software, or for reporting results.

  • ‘imports’conversion from already computed incidence into an incidence object; this can be useful for using features of the incidence package for data handling and plotting with incidence data computed elsewhere.


Exporting results

To export results, we first compute semi-weekly incidence (with weeks starting on Sunday, the beginning of the CDC epiweek) by gender from the simulated Ebola data used in the overview vignette:

To export the data to a data.frame, one simply needs:

The first column contains the dates marking the (inclusive) left side of the time intervals used for computing incidence, and the other columns give counts for the different groups. This function also has an option for exporting data as a ‘long’ format, i.e. with a column for ‘groups’ and a column for counts. This format can be useful especially when working with ggplot2, which expect data in this shape:

Finally, note that when ISO weeks are used, these are also reported in the output:


Importing pre-computed incidence

The function as.incidence facilitates the conversion of pre-computed incidences to an incidence object. Typically, the input will be imported into R from a .csv file or other spreadsheet formats.

as.incidence is a generic with methods for several types of objects (see ?as.incidence). The main method is matrix, as other types are coerced to matrix first and then passed to as.incidence.matrix:

The only mandatory argument x is a table of counts, with time intervals in rows and groups in columns; if there are no groups, then the column doesn’t need a name; but if there are several groups, then columns should be named to indicate group labels. Optionally, dates can be provided to indicate the (inclusive) lower bounds of the time intervals, corresponding to the rows of x; most sensible date formats will do; if indicated as a character string, make sure the format is YYYY-mm-dd, e.g. 2017-04-01 for the 1st April 2017.

Let us illustrate the conversion using a simple vector of incidence:

plot(i, border = "white")

Assuming the above incidences are computed weekly, we would then use:

Note that in this case, incidences have been treated as per week, and corresponding dates in days have been computed during the conversion (the first day is always ‘1’), so that the first days of weeks 1, 2, 3… are:

In practice, it is best to provide the actual dates marking the lower bounds of the time intervals. We can illustrate this by a round trip using the example of the previous section: