Adjust or subset a line list to account for right truncation
Source:R/truncate_linelist.R
truncate_linelist.RdAdjust or subset the line list <data.frame> by removing cases that
have not been reported by the truncation time and setting hospitalisation
admission or outcome dates that are after the truncation point to NA.
This is to replicate real-time outbreak data where recent cases or outcomes are not yet observed or reported (right truncation). It implies an assumption that symptom onsets are reported with a delay but hospitalisations are reported instantly.
Arguments
- linelist
Line list
<data.frame>output fromsim_linelist().- truncation_day
A single
numericspecifying the number of days (default), weeks, months or years before the end of the outbreak (default) or since the start of the outbreak (seedirectionargument) to truncate the line list at. By default it is 14 days before the end of the outbreak.Alternatively,
truncation_daycan accept a<Date>and this is used as thetruncation_dayand theunitanddirectionis ignored.- unit
A
characterstring, either"days"(default),"weeks","months", or"years", specifying the units of thetruncation_dayargument.Years are assumed to be 365.25 days and months are assumed to be 365.25 / 12 days (same as lubridate).
- direction
A
characterstring, either"backwards"(default) or"forwards".direction = backwardsdefines thetruncation_dayas the time before the end of the outbreak.direction = forwardsdefines thetruncation_dayas the time since the start of the outbreak.
Value
A line list <data.frame>.
The output <data.frame> has the same structure as the input <data.frame>
from sim_linelist(), but can be a subset and dates after truncation set
to NA.
Details
The day on which the line list is truncated is the same for
all individuals in the line list, and is specified by the
truncation_day and unit arguments.
Examples
set.seed(1)
linelist <- sim_linelist()
linelist_trunc <- truncate_linelist(linelist)
# set truncation point 3 weeks before the end of outbreak
linelist_trunc <- truncate_linelist(
linelist,
truncation_day = 3,
unit = "weeks"
)
# set truncation point to 2 months since the start of outbreak
linelist_trunc <- truncate_linelist(
linelist,
truncation_day = 2,
unit = "months",
direction = "forwards"
)
# set truncation point to 2023-03-01
linelist_trunc <- truncate_linelist(
linelist,
truncation_day = as.Date("2023-03-01")
)