Skip to contents

Compute demographic characteristics at a certain date

Usage

addDemographics(
  x,
  indexDate = "cohort_start_date",
  age = TRUE,
  ageName = "age",
  ageMissingMonth = 1,
  ageMissingDay = 1,
  ageImposeMonth = FALSE,
  ageImposeDay = FALSE,
  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.

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.

Value

cohort table with the added demographic information columns.

Examples

# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles()
cdm$cohort1 %>%
  addDemographics()
#> # Source:   table<og_111_1715898454> [10 x 8]
#> # Database: DuckDB v0.10.2 [unknown@Linux 6.5.0-1021-azure:R 4.4.0/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date   age sex  
#>                   <int>      <int> <date>            <date>          <int> <chr>
#>  1                    2          8 1907-01-02        1913-08-29          0 Male 
#>  2                    3          4 2099-10-18        2110-09-26         92 Male 
#>  3                    2          1 1959-05-14        1966-08-26         57 Male 
#>  4                    1          5 1992-01-25        2013-08-17         19 Male 
#>  5                    2          6 1924-04-15        1970-10-14         12 Fema…
#>  6                    2          7 2108-04-02        2145-01-10         93 Male 
#>  7                    2          2 1957-04-30        1993-06-18         10 Male 
#>  8                    1          3 1995-09-08        2015-03-23         65 Male 
#>  9                    3         10 2007-07-25        2017-12-23         45 Fema…
#> 10                    2          9 1999-06-09        2035-09-17         14 Fema…
#> # ℹ 2 more variables: prior_observation <int>, future_observation <int>
mockDisconnect(cdm = cdm)
# }