addCohortEventDate() finds the first or last event in each window.
When no event is observed before the applicable boundary, the event is
reported as "end_of_observation" if the observation period boundary is
reached or "censor" if the window boundary or censorDate is reached. The
date value represents that boundary.
Usage
addCohortEventDate(
x,
targetCohortTable,
targetCohortId = NULL,
indexDate = "cohort_start_date",
censorDate = NULL,
targetDate = "cohort_start_date",
order = "first",
window = c(0, Inf),
multipleEvents = NULL,
nameStyle = "{value}_{window_name}",
name = NULL
)Arguments
- x
A table containing individuals in a CDM reference.
- targetCohortTable
Name of the cohort table to intersect with.
- targetCohortId
Cohort definition IDs to include from
targetCohortTable. IfNULL, all cohorts are included.- indexDate
Name of a date column in
x, or a single date to use for all rows, used as the reference date.- censorDate
Date or name of a date column in
xon which to censor follow-up. IfNULL, no censoring is applied.- targetDate
Name or names of date columns in the target tables to use for the intersection.
- order
Which record to use when multiple records occur in a window:
"first"or"last".- window
Window or windows of time relative to
indexDateto consider.- multipleEvents
How events occurring on the same date are handled. If
NULL, the first event in the original event order is returned. IfTRUE, all simultaneous event names are sorted alphabetically and joined with"; ". A character vector gives priority to the specified event names; the first matching name is returned, with unspecified names following in alphabetical order. Boundary labels ("censor"and"end_of_observation") are never combined with event names.- nameStyle
Naming pattern for the added columns. It must contain
{value}and can also contain{window_name}.- name
Name of the new table. If
NULL, a temporary table is returned.
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
#> Warning: There are observation period end dates after the current date: 2026-07-24
#> ℹ The latest max observation period end date found is 2028-06-07
cdm$cohort1 |>
addCohortEventDate(targetCohortTable = "cohort2")
#> # A query: ?? x 6
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 3 1 1905-10-07 1907-05-27
#> 2 1 5 1947-07-09 1952-12-30
#> 3 2 7 1967-03-03 1984-04-18
#> 4 3 9 1915-02-23 1937-06-25
#> 5 2 2 2022-11-11 2026-07-30
#> 6 3 3 1907-01-04 1918-05-07
#> 7 1 4 1989-01-23 1992-05-29
#> 8 1 6 1953-01-10 1956-11-18
#> 9 2 8 1986-05-22 1988-07-08
#> 10 2 10 1946-11-14 1950-05-11
#> # ℹ 2 more variables: event_0_to_inf <chr>, date_0_to_inf <date>
# }
