Assign unique identifiers to dated events based on case definitions.
episodes(
date,
case_length = Inf,
episode_type = "fixed",
recurrence_length = case_length,
episode_unit = "days",
strata = NULL,
sn = NULL,
episodes_max = Inf,
rolls_max = Inf,
case_overlap_methods = 8,
recurrence_overlap_methods = case_overlap_methods,
skip_if_b4_lengths = FALSE,
data_source = NULL,
data_links = "ANY",
custom_sort = NULL,
skip_order = Inf,
reference_event = "last_record",
case_for_recurrence = FALSE,
from_last = FALSE,
group_stats = FALSE,
display = "none",
case_sub_criteria = NULL,
recurrence_sub_criteria = case_sub_criteria,
case_length_total = 1,
recurrence_length_total = case_length_total,
skip_unique_strata = TRUE
)epid; list
[date|datetime|integer|number_line]. Event date or period.
[integer|number_line]. Duration from index event distinguishing one "Case" from another.
[character]. Options are "fixed" (default), "rolling" or "recursive". See Details.
[integer|number_line]. Duration from an event distinguishing a "Recurrent" event from its index event.
[character]. Time unit for case_length and recurrence_length. Options are "seconds", "minutes", "hours", "days" (default), "weeks", "months" or "years". See diyar::episode_unit.
[atomic]. Subsets of the dataset. Episodes are created separately for each strata.
[integer]. Unique record identifier. Useful in creating familiar epid identifiers.
[integer]. Maximum number of episodes permitted within each strata.
[integer]. Maximum number of times an index event recurs. Only used if episode_type is "rolling" or "recursive".
[character|integer]. Specific ways event-periods most overlap with a "Case" event. See (overlaps).
[character|integer]. Specific ways event-periods most overlap with a "Recurrent" event. See (overlaps).
[logical]. If TRUE (default), events before a lagged case_length or recurrence_length are skipped.
[character]. Source of each record. Used to populate the epid_dataset slot of the epid.
[list|character]. data_source required in each epid. An episode without records from these data_sources will be unlinked. See Details.
[atomic]. Preferential order for selecting index events. See custom_sort.
[integer]. Skip episodes with an index event that is greater than "n" sort order of custom_sort.
[character]. Specifies which events are used as index events for a subsequent case_length or recurrence_length. Options are "last_record" (default), "last_event", "first_record" or "first_event".
[logical]. If TRUE, both "Case" and "Recurrent" events will have a case_length.
If FALSE (default), only case events will have a case window. Only used if episode_type is "rolling" or "recursive".
[logical]. Chronological order of episode tracking i.e. ascending (TRUE) or descending (FALSE).
[logical]. If TRUE (default), episode-specific information like episode start and end dates are returned.
[character]. Display or produce a status update. Options are; "none" (default), "progress", "stats", "none_with_report", "progress_with_report" or "stats_with_report".
[sub_criteria]. Nested matching criteria for events in a case_length.
[sub_criteria]. Nested matching criteria for events in a recurrence_length.
[integer|number_line]. Minimum number of matched case_lengths required for an episode.
[integer|number_line]. Minimum number of matched recurrence_lengths required for an episode.
[logical]. If TRUE, a strata with a single event is skipped.
episodes() links dated records (events) that
are within a set duration of each other.
Every event is linked to a unique group (episode; epid object).
These episodes represent occurrences of interest as defined by the case definition specified through function's arguments.
By default, this process occurs in ascending order; beginning with the earliest event and proceeding to the most recent one.
This can be changed to a descending (from_last) or custom order (custom_sort).
Ties are always broken by the chronological order of events.
In general, three type of episodes are possible;
"fixed" - An episode where all events are within fixed durations of one index event.
"rolling" - An episode where all events are within recurring durations of one index event.
"recursive" - An episode where all events are within recurring durations of multiple index events.
Every event in each episode is categorised as one of the following;
"Case" - Index event of the episode (without a matching sub_criteria).
"Case_CR" - Index event of the episode (with a matching sub_criteria).
"Duplicate_C" - Duplicate of the index event.
"Recurrent" - Recurrence of the index event (without a matching sub_criteria).
"Recurrent_CR" - Recurrence of the index event (with a matching sub_criteria).
"Duplicate_R" - Duplicate of the recurrent event.
"Skipped" - Records excluded from the episode tracking process.
If data_links is supplied, every element of the list must be named "l" (links) or "g" (groups).
Unnamed elements are assumed to be "l".
If named "l", only groups with records from every listed data_source will be unlinked.
If named "g", only groups with records from any listed data_source will be unlinked.
Records with a missing (NA) strata are excluded from the episode tracking process.
See vignette("episodes") for further details.
episodes_wf_splits; custom_sort; sub_criteria; epid_length; epid_window; partitions; links; overlaps; number_line; links_sv_probabilistic; schema
data(infections)
data(hospital_admissions)
# One 16-day (15-day difference) fixed episode per type of infection
episodes(date = infections$date,
strata = infections$infection,
case_length = 15,
episodes_max = 1)
# Mutliple 16-day episodes with an 11-day recurrence period
episodes(date = infections$date,
case_length = 15,
recurrence_length = 10,
episode_type = "rolling")
# Overlapping episodes of hospital stays
hospital_admissions$admin_period <-
number_line(hospital_admissions$admin_dt,
hospital_admissions$discharge_dt)
episodes(date = hospital_admissions$admin_period,
case_overlap_methods = "inbetween")
Run the code above in your browser using DataLab