plotEventDuration

plotEventDuration(
  eventDurations,
  minCellCount = 0,
  treatmentGroups = "both",
  eventLines = NULL,
  includeOverall = TRUE
)

Arguments

eventDurations

(data.frame) Contents of summaryEventDuration.csv file.

minCellCount

(numeric(1): 0) Min Cell Count per event group.

treatmentGroups

(character(1): "both") "group": Only mono-, and combination-events. "individual": Only individual (combination) events. "both": Both mono-, and combination-events, and individual (combination) events.

eventLines

(numeric(n): NULL) Event lines to include, i.e. c(1, 2, 3) includes first (1), second (2), and third (3) lines of events. NULL will include all eventLines.

includeOverall

(logical(1): TRUE) TRUE: Include an overall column with the eventLines. FALSE: Exclude the overall column.

Value

ggplot

Examples

# \donttest{
library(TreatmentPatterns)
library(CDMConnector)
library(dplyr)

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())
  )

  tryCatch({
    if (Sys.getenv("skip_eunomia_download_test") != "TRUE") {
      CDMConnector::downloadEunomiaData(overwrite = TRUE)
    }
  }, error = function(e) NA)

  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
  )

  export(
    andromeda = outputEnv,
    outputPath = tempdir()
  )

  eventDurations <- read.csv(file.path(tempdir(), "summaryEventDuration.csv"))

  plotEventDuration(
    eventDurations = eventDurations,
    minCellCount = 5,
    treatmentGroups = "group",
    eventLines = 1:4,
    includeOverall = FALSE
  )

  Andromeda::close(outputEnv)
  DBI::dbDisconnect(con, shutdown = TRUE)
}
#> 
#> Download completed!
#>  Generating 8 cohorts
#>  Generating cohort (1/8) - acetaminophen
#>  Generating cohort (1/8) - acetaminophen [155ms]
#> 
#>  Generating cohort (2/8) - amoxicillin
#>  Generating cohort (2/8) - amoxicillin [153ms]
#> 
#>  Generating cohort (3/8) - aspirin
#>  Generating cohort (3/8) - aspirin [162ms]
#> 
#>  Generating cohort (4/8) - clavulanate
#>  Generating cohort (4/8) - clavulanate [148ms]
#> 
#>  Generating cohort (5/8) - death
#>  Generating cohort (5/8) - death [104ms]
#> 
#>  Generating cohort (6/8) - doxylamine
#>  Generating cohort (6/8) - doxylamine [148ms]
#> 
#>  Generating cohort (7/8) - penicillinv
#>  Generating cohort (7/8) - penicillinv [155ms]
#> 
#>  Generating cohort (8/8) - viralsinusitis
#>  Generating cohort (8/8) - viralsinusitis [219ms]
#> 
#> Warning: ! 5 casted column in cohort_table (cohort_attrition) as do not match expected
#>   column type:
#>  `number_records` from numeric to integer
#>  `number_subjects` from numeric to integer
#>  `reason_id` from numeric to integer
#>  `excluded_records` from numeric to integer
#>  `excluded_subjects` from numeric to integer
#> Warning: ! 1 column in cohort_table do not match expected column type:
#>  `subject_id` is numeric but expected integer
#> -- Qualifying records for cohort definitions: 1, 2, 3, 4, 5, 6, 7, 8
#> 	Records: 14041
#> 	Subjects: 2693
#> -- Removing records < minEraDuration (0)
#> 	Records: 11386
#> 	Subjects: 2159
#> -- Removing events where index date < target index date + indexDateOffset (0)
#> 	Records: 8381
#> 	Subjects: 2159
#> -- splitEventCohorts
#> 	Records: 8366
#> 	Subjects: 2144
#> -- eraCollapse (30)
#> 	Records: 8366
#> 	Subjects: 2144
#> -- Iteration 1: minPostCombinationDuration (30), combinatinoWindow (30)
#> 	Records: 558
#> 	Subjects: 512
#> -- Iteration 2: minPostCombinationDuration (30), combinatinoWindow (30)
#> 	Records: 554
#> 	Subjects: 512
#> -- After Combination
#> 	Records: 554
#> 	Subjects: 512
#> -- filterTreatments (First)
#> 	Records: 553
#> 	Subjects: 512
#> -- treatment construction done
#> 	Records: 553
#> 	Subjects: 512
#> Writing attrition to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/attrition.csv
#> Writing metadata to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/metadata.csv
#> Writing treatmentPathways to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/treatmentPathways.csv
#> Censoring 1219 pathways with a frequency <5 to 5.
#> Writing summaryStatsTherapyDuration to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/summaryEventDuration.csv
#> Writing countsYearPath to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/countsYear.csv
#> Writing countsAgePath to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/countsAge.csv
#> Writing countsSexPath to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/countsSex.csv
# }