Compute treatment patterns according to the specified parameters within specified cohorts.

computePathways(
  cohorts,
  cohortTableName,
  cdm = NULL,
  connectionDetails = NULL,
  cdmSchema = NULL,
  resultSchema = NULL,
  tempEmulationSchema = NULL,
  includeTreatments = "startDate",
  periodPriorToIndex = 0,
  minEraDuration = 0,
  splitEventCohorts = NULL,
  splitTime = NULL,
  eraCollapseSize = 30,
  combinationWindow = 30,
  minPostCombinationDuration = 30,
  filterTreatments = "First",
  maxPathLength = 5
)

Arguments

cohorts

(data.frame())
Data frame containing the following columns and data types:

cohortId numeric(1)

Cohort ID's of the cohorts to be used in the cohort table.

cohortName character(1)

Cohort names of the cohorts to be used in the cohort table.

type character(1) ["target", "event', "exit"]

Cohort type, describing if the cohort is a target, event, or exit cohort

cohortTableName

(character(1))
Cohort table name.

cdm

(CDMConnector::cdm_from_con(): NULL)
Optional; Ignores connectionDetails, cdmSchema, and resultSchema.

connectionDetails

(DatabaseConnector::createConnectionDetails(): NULL)
Optional; In congruence with cdmSchema and resultSchema. Ignores cdm.

cdmSchema

(character(1): NULL)
Optional; In congruence with connectionDetails and resultSchema. Ignores cdm.

resultSchema

(character(1): NULL)
Optional; In congruence with connectionDetails and cdmSchema. Ignores cdm.

tempEmulationSchema

Schema used to emulate temp tables

includeTreatments

(character(1): "startDate")

"startDate"

Include treatments after the target cohort start date and onwards.

"endDate"

Include treatments before target cohort end date and before.

periodPriorToIndex

(integer(1): 0)
Number of days prior to the index date of the target cohort | that event cohorts are allowed to start

minEraDuration

(integer(1): 0)
Minimum time an event era should last to be included in analysis

splitEventCohorts

(character(n): "")
Specify event cohort to split in acute (< X days) and therapy (>= X days)

splitTime

(integer(1): 30)
Specify number of days (X) at which each of the split event cohorts should be split in acute and therapy

eraCollapseSize

(integer(1): 30)
Window of time between which two eras of the same event cohort are collapsed into one era

combinationWindow

(integer(1): 30)
Window of time two event cohorts need to overlap to be considered a combination treatment

minPostCombinationDuration

(integer(1): 30)
Minimum time an event era before or after a generated combination treatment should last to be included in analysis

filterTreatments

(character(1): "First" ["first", "Changes", "all"])
Select first occurrence of (‘First’); changes between (‘Changes’); or all event cohorts (‘All’).

maxPathLength

(integer(1): 5)
Maximum number of steps included in treatment pathway

Value

(Andromeda::andromeda()) andromeda object containing non-sharable patient level data outcomes.

Examples

# \donttest{
library(TreatmentPatterns)
library(CDMConnector)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

if (require("CirceR", character.only = TRUE, quietly = TRUE)) {
  withr::local_envvar(
    R_USER_CACHE_DIR = tempfile(),
    EUNOMIA_DATA_FOLDER = Sys.getenv("EUNOMIA_DATA_FOLDER", unset = tempfile())
  )

  downloadEunomiaData(overwrite = TRUE)

  con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir())
  cdm <- cdmFromCon(con, cdmSchema = "main", writeSchema = "main")

  cohortSet <- readCohortSet(
    path = system.file(package = "TreatmentPatterns", "exampleCohorts")
  )

  cdm <- generateCohortSet(
    cdm = cdm,
    cohortSet = cohortSet,
    name = "cohort_table"
  )

  cohorts <- cohortSet %>%
    # Remove 'cohort' and 'json' columns
    select(-"cohort", -"json") %>%
    mutate(type = c("event", "event", "event", "event", "exit", "event", "event", "target")) %>%
    rename(
      cohortId = "cohort_definition_id",
      cohortName = "cohort_name",
    ) %>%
    select("cohortId", "cohortName", "type")

  outputEnv <- computePathways(
    cohorts = cohorts,
    cohortTableName = "cohort_table",
    cdm = cdm
  )

  Andromeda::close(outputEnv)
  DBI::dbDisconnect(con, shutdown = TRUE)
}
#> 
#> Download completed!
#>  Generating 8 cohorts
#>  Generating cohort (1/8) - acetaminophen
#>  Generating cohort (1/8) - acetaminophen [225ms]
#> 
#>  Generating cohort (2/8) - amoxicillin
#>  Generating cohort (2/8) - amoxicillin [136ms]
#> 
#>  Generating cohort (3/8) - aspirin
#>  Generating cohort (3/8) - aspirin [113ms]
#> 
#>  Generating cohort (4/8) - clavulanate
#>  Generating cohort (4/8) - clavulanate [124ms]
#> 
#>  Generating cohort (5/8) - death
#>  Generating cohort (5/8) - death [56ms]
#> 
#>  Generating cohort (6/8) - doxylamine
#>  Generating cohort (6/8) - doxylamine [123ms]
#> 
#>  Generating cohort (7/8) - penicillinv
#>  Generating cohort (7/8) - penicillinv [118ms]
#> 
#>  Generating cohort (8/8) - viralsinusitis
#>  Generating cohort (8/8) - viralsinusitis [169ms]
#> 
#> Construct treatment pathways, this may take a while for larger datasets.
#> Original number of rows: 8352
#> After eraCollapseSize: 0
#> Selected 1544 
#> out of 8352 rows
#> Iteration: 1
#> Switches: 8352
#> FRFS Combinations: 4
#> LRFS Combinations: 1527
#> Selected 4 
#> out of 559 rows
#> Iteration: 2
#> Switches: 559
#> FRFS Combinations: 0
#> LRFS Combinations: 4
#> After combinationWindow: 555
#> Time needed to execute combination window 0.0633309006690979
#> Order the combinations.
#> After filterTreatments: 554
#> Adding drug sequence number.
#> After maxPathLength: 554
#> Adding concept names.
#> Ordering the combinations.
#> constructPathways done.
# }