Skip to contents

Add 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
)

Arguments

x

Table with individuals in the cdm.

indexDate

Variable in x that contains the window origin.

censorDate

Name of a column to stop followup.

window

window to consider events over.

deathFlagName

name of the new column to be added.

name

Name of the new table, if NULL a temporary table is returned.

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 be: 1 to indicate presence of the intersection, 0 to indicate no intersection or NA if the individual is not in observation at any time of the window.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addDeathFlag()
#> # Source:   table<og_121_1775495295> [?? x 5]
#> # Database: DuckDB 1.5.1 [unknown@Linux 6.17.0-1008-azure:R 4.5.3/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date death
#>                   <int>      <int> <date>            <date>          <dbl>
#>  1                    3          2 1961-04-15        1963-03-29          0
#>  2                    3          6 1930-01-12        1931-06-03          0
#>  3                    3          3 1983-05-14        1992-01-24          0
#>  4                    2          5 1964-08-14        1981-10-16          0
#>  5                    2          8 1937-09-13        1945-12-06          0
#>  6                    3          9 2002-05-10        2003-07-29          0
#>  7                    2          4 1971-03-17        1972-07-17          0
#>  8                    2         10 1971-04-24        1980-03-26          0
#>  9                    3          1 1992-10-21        1999-08-30          0
#> 10                    2          7 1955-02-22        1957-02-21          0

# }