episodes {diyar} | R Documentation |
Create temporal links between dated events. Each set of linked records are assigned a unique identifier with relevant group-level information.
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
)
date |
|
case_length |
|
episode_type |
|
recurrence_length |
|
episode_unit |
|
strata |
|
sn |
|
episodes_max |
|
rolls_max |
|
case_overlap_methods |
|
recurrence_overlap_methods |
|
skip_if_b4_lengths |
|
data_source |
|
data_links |
|
custom_sort |
|
skip_order |
|
reference_event |
|
case_for_recurrence |
|
from_last |
|
group_stats |
|
display |
|
case_sub_criteria |
|
recurrence_sub_criteria |
|
case_length_total |
|
recurrence_length_total |
|
skip_unique_strata |
|
episodes()
links dated records (events) that
are within specified durations of each other.
In each iteration, an index event is selected and compared against every other event.
Every event is linked to a unique group (episode; epid
object).
These episodes represent occurrences of interest as defined by the rules and conditions specified in the 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 categorise as;
"Case"
- Index event of the episode (without matching sub_criteria
).
"Case_CR"
- Index event of the episode (with matching sub_criteria
).
"Duplicate_C"
- Duplicate of the index event.
"Recurrent"
- Recurrence of the index event (without matching sub_criteria
).
"Recurrent_CR"
- Recurrence of the index event (with 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.
epid
; list
episodes_wf_splits
; custom_sort
; sub_criteria
; epid_length
; epid_window
; partitions
; links
; overlaps
; number_line
; link_records
; schema
data(infections); db_1 <- infections
data(hospital_admissions) ; db_2 <- hospital_admissions
db_1$patient_id <- c(rep("PID 1",8), rep("PID 2",3))
# Fixed episodes
# One 16-day (15-day difference) episode per patient
db_1$ep1 <- episodes(date = db_1$date,
strata = db_1$patient_id,
case_length = 15,
episodes_max = 1)
# Rolling episodes
# 16-day episodes with recurrence periods of 11 days
db_1$ep2 <- episodes(date = db_1$date,
case_length = 15,
recurrence_length = 10,
episode_type = "rolling")
# Interval grouping
db_2$admin_period <- number_line(db_2$admin_dt,
db_2$discharge_dt)
# Episodes of hospital stays
db_2$ep3 <- episodes(date = db_2$admin_period,
case_length = index_window(db_2$admin_period),
case_overlap_methods = "inbetween")