Restrict cohort on patient demographics
trimDemographics.Rd
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.
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.0.0 [unknown@Linux 6.5.0-1025-azure:R 4.4.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 43 2014-10-05 2015-09-27
#> 2 1 48 1970-07-29 1974-01-28
#> 3 1 64 1993-05-18 2001-05-18
#> 4 1 75 1974-01-17 1974-10-19
#> 5 1 43 2014-07-21 2014-10-04
#> 6 1 29 2006-11-24 2008-03-21
#> 7 1 43 2014-07-06 2014-07-20
#> 8 1 29 2006-10-02 2006-11-23
#> 9 1 29 2006-07-07 2006-10-01
#> 10 1 10 2019-12-04 2019-12-14
#> # ℹ more rows
# }