Description Usage Arguments Details Value Author(s) Examples
ll2incidence
takes individual dates of infections and returns
population incidences by a specified time step.
1 | ll2incidence(x, unit = c("day", "week", "month", "quarter", "year"))
|
x |
either a vector or a 1-column data frame of dates of |
unit |
a character string (one of |
The date
variable of the output is defined with a regular time step as
defined by the unit
argument. In absence of cases between two steps, a
zero incidence is explicitly displayed.
ll2incidence
returns a data frame of 4 variables:
start
, middle
, end
and incidence
. The first 3
variables are respectively the dates of the beginning, the middle and the end
of the time period over which the incidence is defined and are of class
POSIXct
with time zone UTC. The HH:MM:SS of the start
and
end
variables are 00:00:00.
Marc Choisy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # Four different data sets of infections dates:
infection_date_v <- infections_dates
infection_posixct_v <- as.POSIXct(infection_date_v)
infection_date_df <- as.data.frame(infection_date_v)
infection_posixct_df <- as.data.frame(infection_posixct_v)
data_sets <- list(infection_date_v, # vector of Date class
infection_date_df, # data frame of Date class
infection_posixct_v, # vector of POSIXct class
infection_posixct_df) # data frame of POSIXct class
lapply(data_sets, head)
# Five time resolutions we want to consider for incidence calculations:
steps <- c("day", "week", "month", "quarter", "year")
# Calculating of the 4 x 5 = 20 incidence data sets:
incidences <- lapply(steps,
function(y) lapply(data_sets, function(x)
ll2incidence(x, y)))
# Comparing the results:
n <- length(incidences[[1]])
any(!unlist(lapply(1:n,
function(x) sapply(1:(n - 1),
function(y) sapply((y + 1):n, function(z)
identical(incidences[[c(x, y)]],
incidences[[c(x, z)]]))))))
# Showing the results:
for(i in 1:5) print(head(incidences[[c(i, 1)]]))
# Checking that the number of cases is the same whatever the data type:
any(!as.vector(sapply(1:4,
function(x) sapply(1:5,
function(y) sum(incidences[[c(y, x)]]$incidence)))) ==
length(infections_dates))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.