
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",
type = "numeric"
)Arguments
- x
A table containing individuals in a CDM reference.
- indexDate
Name of a date column in
x, or a single date to use for all rows, used as the reference date.- age
If
TRUE, age is calculated relative toindexDate.- ageName
Name of the age column to add.
- ageMissingMonth
Month of the year assigned when month of birth is missing.
- ageMissingDay
Day of the month assigned when day of birth is missing.
- ageImposeMonth
If
TRUE, month of birth is treated as missing for all individuals.- ageImposeDay
If
TRUE, day of birth is treated as missing for all individuals.- ageUnit
Unit in which to express age:
"years","months", or"days".- ageGroup
If not
NULL, a list of age-group vectors.- missingAgeGroupValue
Value to use when age is missing.
- sex
If
TRUE, sex is identified.- sexName
Name of the sex column to add.
- missingSexValue
Value to use when sex is missing.
- priorObservation
If
TRUE, the time between the start of the current observation period andindexDateis calculated.- priorObservationName
Name of the prior-observation column to add.
- priorObservationType
Whether to return a
"date"or a number of"days".- futureObservation
If
TRUE, the time betweenindexDateand the end of the current observation period is calculated.- futureObservationName
Name of the future-observation column to add.
- futureObservationType
Whether to return a
"date"or a number of"days".- dateOfBirth
If
TRUE, date of birth is returned.- dateOfBirthName
Name of the date-of-birth column to add.
- type
Type of the created column(s). Counts, days, age, and observation durations can be
"numeric"or"integer". Flag columns can also be"logical". Field columns can use"auto"to preserve the source type, or can be converted to"numeric","integer","logical", or"character".
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
cdm$cohort1 |>
addDemographicsQuery()
#> # A query: ?? x 8
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date age sex
#> <int> <int> <date> <date> <dbl> <chr>
#> 1 3 1 1943-07-28 1952-12-25 13 Fema…
#> 2 3 2 1957-02-07 1962-10-04 8 Male
#> 3 2 3 1981-06-17 1993-05-18 3 Fema…
#> 4 3 4 1929-11-03 1933-11-29 11 Male
#> 5 1 5 1917-05-08 1921-04-22 16 Male
#> 6 3 6 1974-09-22 1980-10-20 21 Fema…
#> 7 2 7 1980-06-16 1991-06-23 0 Male
#> 8 2 8 1975-08-23 1983-11-29 5 Fema…
#> 9 2 9 1972-05-16 1972-06-26 35 Fema…
#> 10 1 10 1929-12-27 1934-09-28 3 Fema…
#> # ℹ 2 more variables: prior_observation <dbl>, future_observation <dbl>
# }