Details of the incidence class

Thibaut Jombart


This vignette details the structure of incidence objects, as produced by the incidence function.

Structure of an incidence object.

We generate a toy dataset of dates to examine the content of incidence objects.

dat <- sample(1:50, 200, replace = TRUE, prob = 1 + exp(1:50 * 0.1))
sex <- sample(c("female", "male"), 200, replace = TRUE)

The incidence by 48h period is computed as:

i <- incidence(dat, interval = 2)
#> <incidence object>
#> [200 cases from days 5 to 49]
#> $counts: matrix with 23 rows and 1 columns
#> $n: 200 cases in total
#> $dates: 23 dates marking the left-side of bins
#> $interval: 2 days
#> $timespan: 45 days
#> $cumulative: FALSE

We also compute incidence by gender: <- incidence(dat, interval = 2, group = sex)
#> <incidence object>
#> [200 cases from days 5 to 49]
#> [2 groups: female, male]
#> $counts: matrix with 23 rows and 2 columns
#> $n: 200 cases in total
#> $dates: 23 dates marking the left-side of bins
#> $interval: 2 days
#> $timespan: 45 days
#> $cumulative: FALSE

The object i is a list with the class incidence:

#> [1] "incidence"
#> [1] TRUE
#> [1] "dates"      "counts"     "timespan"   "interval"   "n"         
#> [6] "cumulative"

Items in i can be accessed using the same indexing as any lists:

## use name
#> [1]  5  7  9 11 13 15

## use numeric indexing
#>      [,1]
#> [1,]    3
#> [2,]    0
#> [3,]    1
#> [4,]    0
#> [5,]    1
#> [6,]    0

In the following sections, we examine each of the components of the object.


The $dates component contains all the dates for which incidence have been computed, in the format of the input dataset (e.g. Date, numeric, integer).

The dates correspond to the lower bounds of the time intervals used as bins for the incidence. Bins always include the lower bound and exclude the upper bound. In the example provided above, this means that the first bin counts events that happened at day 5-6, the second bin counts events from 7-8, etc.


The $counts component contains the actual incidence, i.e. counts of events for the defined bins. It is a matrix of integers where rows correspond to time intervals, with one column for each group for which incidence is computed (a single, unamed column if no groups were provided). If groups were provided, columns are named after the groups. We illustrate the difference comparing the two objects i and

Note that a data.frame containing dates and counts can be obtained using

Note that incidence has an argument called na_as_group which is TRUE by default, which will pool all missing groups into a separate group, in which case it will be a separate column in $counts.


The $timespan component stores the length of the time period covered by the object:


The $interval component contains the length of the time interval for the bins:


The $n component stores the total number of events in the data:

Note that to obtain the number of cases by groups, one can use:


The $isoweeks component is optional, and used to store iso weeks whenever they have been used. Iso weeks are used by default when weekly incidence is computed from dates (see argument iso_week in ?incidence).

The correspondence between iso weeks and dates can be derived by comparing the respective items:

Both dates and iso weeks are returned when converting an incidence object to data.frame: