Skip to contents

trimDemographics() resets the cohort start and end date based on the specified demographic criteria is satisfied.

Usage

trimDemographics(
  cohort,
  cohortId = NULL,
  ageRange = NULL,
  sex = NULL,
  minPriorObservation = NULL,
  minFutureObservation = NULL,
  name = tableName(cohort)
)

Arguments

cohort

A cohort table in a cdm reference.

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.

ageRange

A list of vectors specifying minimum and maximum age.

sex

Can be "Both", "Male" or "Female".

minPriorObservation

A minimum number of continuous prior observation days in the database.

minFutureObservation

A minimum number of continuous future observation days in the database.

name

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

Value

The cohort table with only records for individuals satisfying the demographic requirements

Examples

# \donttest{
library(CohortConstructor)

cdm <- mockCohortConstructor(nPerson = 100)

cdm$cohort1 |> trimDemographics(ageRange = list(c(10, 30)))
#>  Building new trimmed cohort
#> Adding demographics information
#> Creating initial cohort
#> Trim age
#>  Cohort trimmed
#> # Source:   table<main.cohort1> [?? x 4]
#> # Database: DuckDB v1.1.3 [unknown@Linux 6.8.0-1017-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          4 1998-12-14        2002-02-14     
#>  2                    1          9 2011-12-30        2012-04-02     
#>  3                    1         21 1985-08-16        1986-09-10     
#>  4                    1         26 1984-05-16        1989-03-22     
#>  5                    1         35 2007-05-13        2010-07-22     
#>  6                    1         39 2000-03-07        2009-03-17     
#>  7                    1         41 2000-11-22        2000-12-09     
#>  8                    1         69 2003-01-14        2003-05-28     
#>  9                    1         71 2009-02-01        2009-09-05     
#> 10                    1         83 2007-05-29        2008-05-01     
#> # ℹ more rows
# }