Add a variable to a drug cohort indicating their presence of a medication cohort in a specified time window.
Arguments
- cohort
A cohort_table object.
- treatmentCohortName
Name of treatment cohort table
- treatmentCohortId
target cohort Id to add treatment
- window
time window of interests.
- indexDate
Name of a column that indicates the date to start the analysis.
- censorDate
Name of a column that indicates the date to stop the analysis, if NULL end of individuals observation is used.
- mutuallyExclusive
Whether to consider mutually exclusive categories (one column per window) or not (one column per window and treatment).
- nameStyle
Name style for the treatment columns. By default: 'treatment_{window_name}' (mutuallyExclusive = TRUE), 'treatment_{window_name}_{cohort_name}' (mutuallyExclusive = FALSE).
- name
Name of the new computed cohort table, if NULL a temporary table will be created.
Examples
# \donttest{
library(DrugUtilisation)
library(dplyr, warn.conflicts = FALSE)
cdm <- mockDrugUtilisation(numberIndividuals = 50)
cdm <- generateIngredientCohortSet(cdm = cdm,
name = "drug_cohort",
ingredient = "acetaminophen")
#> ℹ Subsetting drug_exposure table
#> ℹ Checking whether any record needs to be dropped.
#> ℹ Collapsing overlaping records.
#> ℹ Collapsing records with gapEra = 1 days.
cdm <- generateIngredientCohortSet(cdm = cdm,
name = "treatments",
ingredient = c("metformin", "simvastatin"))
#> ℹ Subsetting drug_exposure table
#> ℹ Checking whether any record needs to be dropped.
#> ℹ Collapsing overlaping records.
#> ℹ Collapsing records with gapEra = 1 days.
cdm$drug_cohort |>
addTreatment("treatments", window = list(c(0, 0), c(1, 30), c(31, 60))) |>
glimpse()
#> ℹ Intersect with medications table (treatments).
#> ℹ Collapse medications to mutually exclusive categories
#> Rows: ??
#> Columns: 7
#> Database: DuckDB v1.2.2 [unknown@Linux 6.11.0-1012-azure:R 4.5.0/:memory:]
#> $ cohort_definition_id <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
#> $ subject_id <int> 28, 28, 23, 30, 41, 33, 44, 12, 43, 3, 14, 14, 39…
#> $ cohort_start_date <date> 1979-08-14, 1982-08-06, 1998-11-17, 2018-08-31, …
#> $ cohort_end_date <date> 1979-10-01, 1982-09-11, 1999-10-01, 2019-08-10, …
#> $ medication_0_to_0 <chr> "metformin", "metformin", "simvastatin", "simvast…
#> $ medication_1_to_30 <chr> "metformin", "metformin", "simvastatin", "simvast…
#> $ medication_31_to_60 <chr> "metformin", "untreated", "simvastatin", "simvast…
# }