Skip to contents

requireDeathFlag() filters a cohort table based on a requirement that an individual is seen (or not seen) to have a death in some time window around an index date.

Usage

requireDeathFlag(
  cohort,
  window,
  cohortId = NULL,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  negate = FALSE,
  name = tableName(cohort)
)

Arguments

cohort

A cohort table in a cdm reference.

window

A list of vectors specifying minimum and maximum days from indexDate to consider events over.

cohortId

Vector identifying which cohorts to modify (cohort_definition_id or cohort_name). If NULL, all cohorts will be used; otherwise, only the specified cohorts will be modified, and the rest will remain unchanged.

indexDate

Name of the column in the cohort that contains the date to use as time 0 for window days.

censorDate

Whether to censor overlap events at a specific date or a column date of the cohort.

negate

If set as TRUE, criteria will be applied as exclusion rather than inclusion (i.e. require absence in another cohort).

name

Name of the new cohort table created in the cdm object.

Value

Cohort table with only those with a death event kept (or without if negate = TRUE)

Examples

# \donttest{
library(CDMConnector)
#> 
#> Attaching package: ‘CDMConnector’
#> The following objects are masked from ‘package:CohortConstructor’:
#> 
#>     intersectCohorts, unionCohorts
library(CohortConstructor)
cdm <- mockCohortConstructor(death = TRUE)
cdm$cohort1 <- cdm$cohort1 |> requireDeathFlag(window = list(c(0, Inf)))
attrition(cdm$cohort1)
#> # A tibble: 2 × 7
#>   cohort_definition_id number_records number_subjects reason_id reason          
#>                  <int>          <int>           <int>     <int> <chr>           
#> 1                    1             10               6         1 Initial qualify…
#> 2                    1             10               6         2 Death between 0…
#> # ℹ 2 more variables: excluded_records <int>, excluded_subjects <int>
# }