-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateStrategusAnalysisSpecification.R
More file actions
163 lines (142 loc) · 6.06 KB
/
Copy pathCreateStrategusAnalysisSpecification.R
File metadata and controls
163 lines (142 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
################################################################################
# INSTRUCTIONS: Make sure you have downloaded your cohorts using
# DownloadCohorts.R and that those cohorts are stored in the "inst" folder
# of the project. This script is written to use the sample study cohorts
# located in "inst/sampleStudy/Eunomia" so you will need to modify this in the code
# below.
#
# See the Create analysis specifications section
# of the UsingThisTemplate.md for more details.
#
# More information about Strategus HADES modules can be found at:
# https://ohdsi.github.io/Strategus/reference/index.html#omop-cdm-hades-modules.
# This help page also contains links to the corresponding HADES package that
# further details.
# ##############################################################################
library(dplyr)
library(Strategus)
# Time-at-risks (TARs) for the outcomes of interest in your study
timeAtRisks <- tibble(
label = c("30d"),
riskWindowStart = c(1),
startAnchor = c("cohort start"),
riskWindowEnd = c(30),
endAnchor = c("cohort start")
)
# If you are not restricting your study to a specific time window,
# please make these strings empty
studyStartDate <- '20100101' #start year
studyEndDate <- '' #present
# Some of the settings require study dates with hyphens
studyStartDateWithHyphens <- gsub("(\\d{4})(\\d{2})(\\d{2})", "\\1-\\2-\\3", studyStartDate)
studyEndDateWithHyphens <- gsub("(\\d{4})(\\d{2})(\\d{2})", "\\1-\\2-\\3", studyEndDate)
# Consider these settings for estimation ----------------------------------------
useCleanWindowForPriorOutcomeLookback <- FALSE # If FALSE, lookback window is all time prior, i.e., including only first events
# Shared Resources -------------------------------------------------------------
# Get the list of cohorts - NOTE: you should modify this for your
# study to retrieve the cohorts you downloaded as part of
# DownloadCohorts.R
cohortDefinitionSet <- CohortGenerator::getCohortDefinitionSet(
settingsFileName = "inst/Cohorts.csv",
jsonFolder = "inst/cohorts",
sqlFolder = "inst/sql/sql_server"
)
# Subset Operators
subsetOperators <- list()
subsetOperators[[length(subsetOperators) + 1]] <-
CohortGenerator::createLimitSubset(
name = 'prepandemic',
calendarStartDate = '2010-01-01',
calendarEndDate = '2019-12-31'
)
subsetOperators[[length(subsetOperators) + 1]] <-
CohortGenerator::createLimitSubset(
name = 'pandemic',
calendarStartDate = '2020-01-01',
calendarEndDate = '2022-12-31'
)
subsetOperators[[length(subsetOperators) + 1]] <-
CohortGenerator::createLimitSubset(
name = 'postpandemic',
#priorTime = 0,
#followUpTime = 0,
#limitTo = "all",
calendarStartDate = '2023-01-01',
calendarEndDate = '2025-06-06'
)
for (i in 1:length(subsetOperators)) {
subsetDefs <-
CohortGenerator::createCohortSubsetDefinition(
name = "",
definitionId = i,
subsetOperators = subsetOperators[i]
)
cohortDefinitionSet <- cohortDefinitionSet |>
CohortGenerator::addCohortSubsetDefinition(cohortSubsetDefintion = subsetDefs, targetCohortIds = c(1, 2))
}
knitr::kable(cohortDefinitionSet[, names(cohortDefinitionSet)[which(!names(cohortDefinitionSet) %in% c("json", "sql"))]])
if (any(duplicated(cohortDefinitionSet$cohortId))) {
stop("*** Error: duplicate cohort IDs found ***")
}
# Create some data frames to hold the cohorts we'll use in each analysis ---------------
# Outcomes: The outcome for this study is cohort_id >= 3
oList <- cohortDefinitionSet %>%
filter(.data$cohortId > 2 & .data$cohortId <= 22) %>%
mutate(outcomeCohortId = cohortId, outcomeCohortName = cohortName) %>%
select(outcomeCohortId, outcomeCohortName) %>%
mutate(cleanWindow = 0)
# Df for TP
cohorts <- cohortDefinitionSet %>%
select (cohortId, cohortName)
cohorts$type <- ifelse(cohorts$cohortId %in% oList$outcomeCohortId, 'event', 'target')
# temp remove 1 and 2 to try to overcome stuck
cohorts = cohorts%>%filter(cohortId>2)
# CohortGeneratorModule --------------------------------------------------------
cgModuleSettingsCreator <- CohortGeneratorModule$new()
cohortDefinitionShared <- cgModuleSettingsCreator$createCohortSharedResourceSpecifications(cohortDefinitionSet)
cohortGeneratorModuleSpecifications <- cgModuleSettingsCreator$createModuleSpecifications(
generateStats = TRUE
)
# CharacterizationModule Settings ---------------------------------------------
cModuleSettingsCreator <- CharacterizationModule$new()
characterizationModuleSpecifications <- cModuleSettingsCreator$createModuleSpecifications(
targetIds = cohortDefinitionSet$cohortId, # NOTE: This is all T/C/I/O
outcomeIds = oList$outcomeCohortId,
outcomeWashoutDays = oList$cleanWindow ,
minPriorObservation = 0,
dechallengeStopInterval = 30,
dechallengeEvaluationWindow = 30,
riskWindowStart = timeAtRisks$riskWindowStart,
startAnchor = timeAtRisks$startAnchor,
riskWindowEnd = timeAtRisks$riskWindowEnd,
endAnchor = timeAtRisks$endAnchor,
minCharacterizationMean = .01
)
# treatmentPatternsModule Settings ---------------------------------------------
tModuleSettingsCreator <- TreatmentPatternsModule$new()
treatmentPatternsModuleSpecifications <- tModuleSettingsCreator$createModuleSpecifications(
cohorts,
includeTreatments = "startDate",
indexDateOffset = 0,
minEraDuration = 1,
splitEventCohorts = NULL,
splitTime = NULL,
eraCollapseSize = 7,
combinationWindow = 1,
minPostCombinationDuration = 1,
filterTreatments = "All",
maxPathLength = 7,
ageWindow = 10,
minCellCount = 5,
censorType = "minCellCount"
)
# Create the analysis specifications ------------------------------------------
analysisSpecifications <- Strategus::createEmptyAnalysisSpecificiations() |>
Strategus::addSharedResources(cohortDefinitionShared) |>
Strategus::addModuleSpecifications(cohortGeneratorModuleSpecifications) |>
Strategus::addModuleSpecifications(characterizationModuleSpecifications) |>
Strategus::addModuleSpecifications(treatmentPatternsModuleSpecifications)
ParallelLogger::saveSettingsToJson(
analysisSpecifications,
file.path("inst", "CAPAnalysisSpecification.json")
)