Skip to contents

Create cohort based on the death table

Usage

deathCohort(cdm, name, subsetCohort = NULL, subsetCohortId = NULL)

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 the subsetCohort are included.

Value

A cohort table with a death cohort in cdm

Examples

# \donttest{
library(CohortConstructor)

cdm <- mockCohortConstructor(death = TRUE)

# Generate a death cohort
death_cohort <- deathCohort(cdm, name = "death_cohort")
#>  Applying cohort requirements.
#>  Cohort death_cohort created.
death_cohort
#> # Source:   table<death_cohort> [?? x 4]
#> # Database: DuckDB v1.3.2 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          1 2018-02-06        2018-02-06     
#>  2                    1          8 2013-07-25        2013-07-25     
#>  3                    1          2 2012-06-26        2012-06-26     
#>  4                    1          4 2018-02-04        2018-02-04     
#>  5                    1          3 2008-06-03        2008-06-03     
#>  6                    1          6 2015-01-28        2015-01-28     
#>  7                    1          7 2010-10-22        2010-10-22     
#>  8                    1         10 2018-11-23        2018-11-23     
#>  9                    1          5 2016-12-16        2016-12-16     
#> 10                    1          9 2009-04-30        2009-04-30     

# 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              4               4         6 In subset cohort
#> 7                    1              4               4         7 First death rec…
#> # ℹ 2 more variables: excluded_records <int>, excluded_subjects <int>

# }