requireDemographics()
filters cohort records, keeping only records where
individuals satisfy the specified demographic criteria.
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.
- indexDate
Variable in cohort that contains the date to compute the demographics characteristics on which to restrict on.
- 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.
- atFirst
If FALSE the requirement will be applied to all records, if TRUE, it will only be required for the first entry of each subject.
- name
Name of the new cohort table created in the cdm object.
- .softValidation
Whether to perform a soft validation of consistency. If set to FALSE four additional checks will be performed: 1) a check that cohort end date is not before cohort start date, 2) a check that there are no missing values in required columns, 3) a check that cohort duration is all within observation period, and 4) that there are no overlapping cohort entries
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor(nPerson = 100)
cdm$cohort1 |>
requireDemographics(indexDate = "cohort_start_date",
ageRange = list(c(18, 65)),
sex = "Female",
minPriorObservation = 365)
#> # Source: table<cohort1> [?? x 4]
#> # Database: DuckDB v1.3.1 [unknown@Linux 6.11.0-1015-azure:R 4.5.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 7 2015-04-04 2018-01-18
#> 2 1 17 1979-09-09 1983-01-12
#> 3 1 27 1999-08-20 2001-01-31
#> 4 1 32 2018-02-22 2019-01-17
#> 5 1 36 2009-08-30 2009-11-12
#> 6 1 37 2017-03-27 2018-07-25
#> 7 1 51 1986-08-18 1991-12-26
#> 8 1 53 2013-05-03 2013-06-06
#> 9 1 63 2000-09-28 2001-10-18
#> 10 1 69 2015-05-09 2015-08-05
#> # ℹ more rows
# }