Create cohort based on the death table
Arguments
- cdm
A cdm reference.
- name
Name of the new cohort table created in the cdm object.
- subsetCohort
A character refering to a cohort table containing individuals for whom cohorts will be generated. Only individuals in this table will appear in the generated cohort.
- subsetCohortId
Optional. Specifies cohort IDs from the
subsetCohort
table to include. If none are provided, all cohorts from thesubsetCohort
are included.
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor()
# Generate a death cohort
death_cohort <- deathCohort(cdm, name = "death_cohort")
#> ℹ Applying cohort requirements.
#> ✔ Cohort death_cohort created.
death_cohort
#> # A tibble: 10 × 4
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 82 1994-03-28 1994-03-28
#> 2 1 1 2004-02-19 2004-02-19
#> 3 1 41 2004-05-06 2004-05-06
#> 4 1 93 2009-04-06 2009-04-06
#> 5 1 7 2011-06-22 2011-06-22
#> 6 1 43 2014-02-07 2014-02-07
#> 7 1 85 2015-02-15 2015-02-15
#> 8 1 70 2019-05-04 2019-05-04
#> 9 1 67 2019-07-18 2019-07-18
#> 10 1 57 2019-08-27 2019-08-27
# Create a death cohort for females aged over 50 years old.
# Create a demographics cohort with age range and sex filters
cdm$my_cohort <- demographicsCohort(cdm, "my_cohort", ageRange = c(50,100), sex = "Female")
#> ℹ Building new trimmed cohort
#> Adding demographics information
#> Creating initial cohort
#> Trim sex
#> Trim age
#> ✔ Cohort trimmed
# Generate a death cohort, restricted to individuals in 'my_cohort'
death_cohort <- deathCohort(cdm, name = "death_cohort", subsetCohort = "my_cohort")
#> ℹ Applying cohort requirements.
#> ✔ Cohort death_cohort created.
death_cohort |> attrition()
#> # A tibble: 7 × 7
#> cohort_definition_id number_records number_subjects reason_id reason
#> <int> <int> <int> <int> <chr>
#> 1 1 10 10 1 Initial qualify…
#> 2 1 10 10 2 Record in obser…
#> 3 1 10 10 3 Not missing rec…
#> 4 1 10 10 4 Non-missing sex
#> 5 1 10 10 5 Non-missing yea…
#> 6 1 1 1 6 In subset cohort
#> 7 1 1 1 7 First death rec…
#> # ℹ 2 more variables: excluded_records <int>, excluded_subjects <int>
# }