
Add flag for death for individuals. Only death within the same observation period than indexDate will be observed.
Source: R/addDeath.R
addDeathFlag.RdAdd flag for death for individuals. Only death within the same observation
period than indexDate will be observed.
Usage
addDeathFlag(
x,
indexDate = "cohort_start_date",
censorDate = NULL,
window = c(0, Inf),
deathFlagName = "death",
name = NULL,
type = "numeric"
)Arguments
- x
A table containing individuals in a CDM reference.
- 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.- window
Window or windows of time relative to
indexDateto consider.- deathFlagName
name of the new column to be added.
- name
Name of the new table. If
NULL, a temporary table is returned.- type
Type of the created column(s). Counts, days, age, and observation durations can be
"numeric"or"integer". Flag columns can also be"logical". Field columns can use"auto"to preserve the source type, or can be converted to"numeric","integer","logical", or"character".
Value
The original table (x) with one added column per window indicating whether the individual's death record intersects that window. The value of the column can either indicate presence (1 or TRUE), no intersection (0 or FALSE), or NA if the individual is not in observation at any time of the window. The representation depends on type.
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
cdm$cohort1 |>
addDeathFlag()
#> # A query: ?? x 5
#> # 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 death
#> <int> <int> <date> <date> <dbl>
#> 1 1 7 1922-07-25 1944-09-27 0
#> 2 1 5 1931-11-01 1933-05-08 0
#> 3 3 3 1955-08-04 1955-12-27 0
#> 4 1 4 1991-07-21 1991-11-10 0
#> 5 1 8 1969-02-27 1974-12-04 0
#> 6 3 1 1943-04-28 1950-03-08 0
#> 7 1 10 1984-11-21 1991-07-27 0
#> 8 2 6 1981-04-10 1997-10-21 0
#> 9 3 2 1955-04-09 1962-08-22 0
#> 10 2 9 1962-08-21 1971-07-14 0
# }