Learn R Programming

incidence (version 1.2.1)

incidence: Compute incidence of events from a vector of dates.

Description

This function computes incidence based on dates of events provided in various formats. A fixed interval, provided as numbers of days, is used to define time intervals. Counts within an interval always include the first date, after which they are labelled, and exclude the second. For instance, intervals labelled as 0, 3, 6, ... mean that the first bin includes days 0, 1 and 2, the second interval includes 3, 4 and 5 etc.

Usage

incidence(dates, interval = 1L, ...)

# S3 method for integer incidence(dates, interval = 1L, groups = NULL, na_as_group = TRUE, last_date = NULL, ...)

# S3 method for default incidence(dates, interval = 1L, groups = NULL, na_as_group = TRUE, last_date = NULL, ...)

# S3 method for numeric incidence(dates, interval = 1L, ...)

# S3 method for Date incidence(dates, interval = 1L, iso_week = TRUE, last_date = NULL, ...)

# S3 method for POSIXt incidence(dates, interval = 1L, ...)

# S3 method for incidence print(x, ...)

Arguments

dates

A vector of dates, which can be provided as objects of the class: integer, numeric, Date, POSIXct. Note that decimal numbers will be floored with a warning.

interval

An integer indicating the (fixed) size of the time interval used for computing the incidence; defaults to 1 day.

...

Additional arguments passed to other methods (none are used).

groups

An optional factor defining groups of observations for which incidence should be computed separately.

na_as_group

A logical value indicating if missing group (NA) should be treated as a separate group.

last_date

The last date to be included in the produced epicurve. If NULL (default), the last date will be the most recent provided in dates.

iso_week

A logical value indicating if dates of the weekly incidence should be using ISO week. Only applies when interval = 7. Defaults to be TRUE.

x

An 'incidence' object.

Value

An list with the class incidence, which contains the following items:

  • dates: The dates marking the left side of the bins used for counting events. When ISO week-based weekly incidence is computed, the dates are the first days of corresponding isoweeks.

  • counts: A matrix of incidence counts, which one column per group (and a single column if no groups were used).

  • timespan: The length of the period for which incidence is computed, in days.

  • interval: The bin size, in number of days; e.g. 7 indicates weekly incidence.

  • n: The total number of cases.

  • isoweeks: ISO 8601 week format yyyy-Www, which is returned only when ISO week-based weekly incidence is computed.

Details

For details about the incidence class, see the dedicated vignette: vignette("incidence_class", package = "incidence")

See Also

The main other functions of the package include:

  • fit: Fit log-linear model to computed incidence.

  • fit_optim_split: Find the optimal peak of the epidemic and fits log-linear models on either side of the peak.

  • subset: Handling of incidence objects.

  • pool: Sum incidence over groups.

  • as.data.frame: Convert an incidence object to a data.frame.

The following vignettes are also available:

  • overview: Provides an overview of the package's features.

  • customize_plot: Provides some tips on finer plot customization.

  • incidence_class: Details the content of the incidence class.

Examples

Run this code
# NOT RUN {
## toy example
incidence(c(1, 5, 8, 3, 7, 2, 4, 6, 9, 2))
incidence(c(1, 5, 8, 3, 7, 2, 4, 6, 9, 2), 2)

## example using simulated dataset
if(require(outbreaks)) {
  onset <- ebola_sim$linelist$date_of_onset

  ## daily incidence
  inc <- incidence(onset)
  inc
  plot(inc)

  ## weekly incidence
  inc.week <- incidence(onset, interval = 7, iso_week = FALSE)
  inc.week
  plot(inc.week)
  plot(inc.week, border = "white") # with visible border
  inc.isoweek <- incidence(onset, interval = 7, iso_week = TRUE)
  inc.isoweek
  ## use group information
  sex <- ebola_sim$linelist$gender
  inc.week.gender <- incidence(onset, interval = 7, groups = sex, iso_week = FALSE)
  inc.week.gender
  head(inc.week.gender$counts)
  plot(inc.week.gender)
  inc.isoweek.gender <- incidence(onset, interval = 7, groups = sex, iso_week = TRUE)
  inc.isoweek.gender
}


# }

Run the code above in your browser using DataLab