
Query to add demographic characteristics at a certain date
Source:R/addDemographicsQuery.R
addDemographicsQuery.RdSame as addDemographics(), except query is not computed to a table.
Usage
addDemographicsQuery(
x,
indexDate = "cohort_start_date",
age = TRUE,
ageName = "age",
ageMissingMonth = 1,
ageMissingDay = 1,
ageImposeMonth = FALSE,
ageImposeDay = FALSE,
ageUnit = "years",
ageGroup = NULL,
missingAgeGroupValue = "None",
sex = TRUE,
sexName = "sex",
missingSexValue = "None",
priorObservation = TRUE,
priorObservationName = "prior_observation",
priorObservationType = "days",
futureObservation = TRUE,
futureObservationName = "future_observation",
futureObservationType = "days",
dateOfBirth = FALSE,
dateOfBirthName = "date_of_birth"
)Arguments
- x
Table with individuals in the cdm.
- indexDate
Variable in x that contains the date to compute the demographics characteristics.
- age
TRUE or FALSE. If TRUE, age will be calculated relative to indexDate.
- ageName
Age variable name.
- ageMissingMonth
Month of the year assigned to individuals with missing month of birth.
- ageMissingDay
day of the month assigned to individuals with missing day of birth.
- ageImposeMonth
TRUE or FALSE. Whether the month of the date of birth will be considered as missing for all the individuals.
- ageImposeDay
TRUE or FALSE. Whether the day of the date of birth will be considered as missing for all the individuals.
- ageUnit
Unit for age it can either be 'years', 'months' or 'days'.
- ageGroup
if not NULL, a list of ageGroup vectors.
- missingAgeGroupValue
Value to include if missing age.
- sex
TRUE or FALSE. If TRUE, sex will be identified.
- sexName
Sex variable name.
- missingSexValue
Value to include if missing sex.
- priorObservation
TRUE or FALSE. If TRUE, days of between the start of the current observation period and the indexDate will be calculated.
- priorObservationName
Prior observation variable name.
- priorObservationType
Whether to return a "date" or the number of "days".
- futureObservation
TRUE or FALSE. If TRUE, days between the indexDate and the end of the current observation period will be calculated.
- futureObservationName
Future observation variable name.
- futureObservationType
Whether to return a "date" or the number of "days".
- dateOfBirth
TRUE or FALSE, if true the date of birth will be return.
- dateOfBirthName
dateOfBirth column name.
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
#> Warning: There are observation period end dates after the current date: 2026-04-06
#> ℹ The latest max observation period end date found is 2032-09-28
cdm$cohort1 |>
addDemographicsQuery()
#> # Source: SQL [?? x 8]
#> # Database: DuckDB 1.5.1 [unknown@Linux 6.17.0-1008-azure:R 4.5.3/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date age sex
#> <int> <int> <date> <date> <int> <chr>
#> 1 2 1 1982-10-17 1985-06-07 31 Fema…
#> 2 3 2 1991-10-18 1997-07-27 28 Fema…
#> 3 1 3 1980-10-13 1984-02-14 4 Fema…
#> 4 3 4 1943-10-24 1945-02-03 0 Male
#> 5 1 5 1987-11-19 1997-05-26 20 Male
#> 6 2 6 1971-08-20 2002-03-13 2 Fema…
#> 7 1 7 1978-04-24 1983-06-12 14 Fema…
#> 8 1 8 2004-02-26 2012-12-01 26 Male
#> 9 3 9 1915-06-22 1916-06-27 9 Male
#> 10 1 10 1945-08-11 1949-07-19 14 Male
#> # ℹ 2 more variables: prior_observation <int>, future_observation <int>
# }