forked from OHDSI/Legend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCohortMethod.R
754 lines (678 loc) · 48.1 KB
/
CohortMethod.R
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# Copyright 2018 Observational Health Data Sciences and Informatics
#
# This file is part of Legend
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#' Run the cohort method package
#'
#' @details
#' Runs the cohort method package to produce propensity scores and outcome models.
#'
#' @param outputFolder Name of local folder to place results; make sure to use forward slashes (/).
#' Do not use a folder on a network drive since this greatly impacts performance.
#' @param indicationId A string denoting the indicationId.
#' @param databaseId A short string for identifying the database (e.g.
#' 'Synpuf').
#' @param maxCores How many parallel cores should be used? If more cores are made available this
#' can speed up the analyses.
#'
#' @export
runCohortMethod <- function(outputFolder, indicationId = "Depression", databaseId, maxCores = 4) {
# Note: we don't want to run all analyses on all TCO pairs. Specifically, analyses that are
# symmetrical (e.g. PS stratification) we only want to do one way, and the interaction analyses we
# don't want to run on the positive controls. To do this, we split up the analyses across several
# CohortMethod runs. We must be careful not to have intermediary files in the different runs with the
# same name but different content.
# Tell CohortMethod to minimize files sizes by dropping unneeded columns:
options("minimizeFileSizes" = TRUE)
indicationFolder <- file.path(outputFolder, indicationId)
cmFolder <- file.path(indicationFolder, "cmOutput")
exposureSummary <- read.csv(file.path(indicationFolder,
"pairedExposureSummaryFilteredBySize.csv"))
pathToCsv <- system.file("settings", "OutcomesOfInterest.csv", package = "Legend")
hois <- read.csv(pathToCsv)
hois <- hois[hois$indicationId == indicationId, ]
pathToCsv <- system.file("settings", "NegativeControls.csv", package = "Legend")
negativeControls <- read.csv(pathToCsv)
negativeControls <- negativeControls[negativeControls$indicationId == indicationId, ]
injectionSummary <- read.csv(file.path(indicationFolder, "signalInjectionSummary.csv"))
createTcos <- function(i, positiveControls = "exclude", reverse = FALSE) {
if (reverse) {
comparatorId <- exposureSummary$targetId[i]
targetId <- exposureSummary$comparatorId[i]
} else {
targetId <- exposureSummary$targetId[i]
comparatorId <- exposureSummary$comparatorId[i]
}
fileName <- file.path(cmFolder,
paste0("CmData_l1_t", targetId, "_c", comparatorId),
"outcomes.rds")
outcomes <- readRDS(fileName)
outcomeIds <- unique(outcomes$outcomeId)
if (positiveControls == "exclude") {
outcomeIds <- outcomeIds[outcomeIds %in% c(hois$cohortId, negativeControls$cohortId)]
} else if (positiveControls == "onlyTarget") {
outcomeIds <- outcomeIds[outcomeIds %in% injectionSummary$newOutcomeId[injectionSummary$exposureId ==
targetId]]
} else if (positiveControls == "onlyComparator") {
outcomeIds <- outcomeIds[outcomeIds %in% injectionSummary$newOutcomeId[injectionSummary$exposureId ==
comparatorId]]
} else if (positiveControls == "excludeComparator") {
outcomeIds <- outcomeIds[!(outcomeIds %in% injectionSummary$newOutcomeId[injectionSummary$exposureId ==
comparatorId])]
} else {
stop("Unknown positive control setting: ", positiveControls)
}
if (length(outcomeIds) == 0) {
ParallelLogger::logDebug("No outcome IDs for target ", targetId, " and comparator ", comparatorId)
return(NULL)
} else {
tco <- CohortMethod::createTargetComparatorOutcomes(targetId = targetId,
comparatorId = comparatorId,
outcomeIds = outcomeIds)
return(tco)
}
}
cmAnalysisListFile <- system.file("settings",
sprintf("cmAnalysisList%s.json", indicationId),
package = "Legend")
cmAnalysisList <- CohortMethod::loadCmAnalysisList(cmAnalysisListFile)
cmAnalysisListFile <- system.file("settings",
sprintf("cmAnalysisListAsym%s.json", indicationId),
package = "Legend")
cmAnalysisListAsym <- CohortMethod::loadCmAnalysisList(cmAnalysisListFile)
cmAnalysisListFile <- system.file("settings",
sprintf("cmAnalysisListInteractions%s.json", indicationId),
package = "Legend")
cmAnalysisListInteractions <- CohortMethod::loadCmAnalysisList(cmAnalysisListFile)
if ((databaseId == "CCAE" || databaseId == "Optum" || databaseId == "Panther") && indicationId == "Hypertension") {
# ParallelLogger::logInfo("*** Skipping matching and interactions for CCAE, Optum, and Panther (Hypertension) ***")
ParallelLogger::logInfo("*** Skipping interactions for CCAE, Optum, and Panther (Hypertension) ***")
# cmAnalysisListAsym <- list()
cmAnalysisListInteractions <- list()
}
# First run: Forward pairs only, no positive controls ---------------------------------
tcos <- lapply(1:nrow(exposureSummary), createTcos, positiveControls = "exclude", reverse = FALSE)
tcos <- plyr::compact(tcos)
cmAnalyses <- c(cmAnalysisList, cmAnalysisListAsym, cmAnalysisListInteractions)
CohortMethod::runCmAnalyses(connectionDetails = NULL,
cdmDatabaseSchema = NULL,
exposureDatabaseSchema = NULL,
exposureTable = NULL,
outcomeDatabaseSchema = NULL,
outcomeTable = NULL,
outputFolder = cmFolder,
oracleTempSchema = NULL,
cmAnalysisList = cmAnalyses,
cdmVersion = 5,
targetComparatorOutcomesList = tcos,
getDbCohortMethodDataThreads = 1,
createStudyPopThreads = min(4, maxCores),
createPsThreads = max(1, round(maxCores/10)),
psCvThreads = min(10, maxCores),
trimMatchStratifyThreads = min(10, maxCores),
prefilterCovariatesThreads = min(5, maxCores),
fitOutcomeModelThreads = min(10, maxCores),
outcomeCvThreads = min(10, maxCores),
refitPsForEveryOutcome = FALSE,
refitPsForEveryStudyPopulation = FALSE,
prefilterCovariates = TRUE,
outcomeIdsOfInterest = hois$cohortId)
file.rename(from = file.path(indicationFolder, "cmOutput", "outcomeModelReference.rds"),
to = file.path(indicationFolder, "cmOutput", "outcomeModelReference1.rds"))
# Second run: Forward pairs only, only target positive controls ---------------------------------
tcos <- lapply(1:nrow(exposureSummary),
createTcos,
positiveControls = "onlyTarget",
reverse = FALSE)
tcos <- plyr::compact(tcos)
cmAnalyses <- c(cmAnalysisList, cmAnalysisListAsym)
CohortMethod::runCmAnalyses(connectionDetails = NULL,
cdmDatabaseSchema = NULL,
exposureDatabaseSchema = NULL,
exposureTable = NULL,
outcomeDatabaseSchema = NULL,
outcomeTable = NULL,
outputFolder = cmFolder,
oracleTempSchema = NULL,
cmAnalysisList = cmAnalyses,
cdmVersion = 5,
targetComparatorOutcomesList = tcos,
getDbCohortMethodDataThreads = 1,
createStudyPopThreads = min(4, maxCores),
createPsThreads = max(1, round(maxCores/10)),
psCvThreads = min(10, maxCores),
trimMatchStratifyThreads = min(10, maxCores),
prefilterCovariatesThreads = min(5, maxCores),
fitOutcomeModelThreads = min(10, maxCores),
outcomeCvThreads = min(2, maxCores),
refitPsForEveryOutcome = FALSE,
refitPsForEveryStudyPopulation = FALSE,
prefilterCovariates = TRUE,
outcomeIdsOfInterest = hois$cohortId)
file.rename(from = file.path(indicationFolder, "cmOutput", "outcomeModelReference.rds"),
to = file.path(indicationFolder, "cmOutput", "outcomeModelReference2.rds"))
# Third run: Forward pairs only, only comparator positive controls ----------------
tcos <- lapply(1:nrow(exposureSummary),
createTcos,
positiveControls = "onlyComparator",
reverse = FALSE)
tcos <- plyr::compact(tcos)
cmAnalyses <- c(cmAnalysisList)
CohortMethod::runCmAnalyses(connectionDetails = NULL,
cdmDatabaseSchema = NULL,
exposureDatabaseSchema = NULL,
exposureTable = NULL,
outcomeDatabaseSchema = NULL,
outcomeTable = NULL,
outputFolder = cmFolder,
oracleTempSchema = NULL,
cmAnalysisList = cmAnalyses,
cdmVersion = 5,
targetComparatorOutcomesList = tcos,
getDbCohortMethodDataThreads = 1,
createStudyPopThreads = min(4, maxCores),
createPsThreads = max(1, round(maxCores/10)),
psCvThreads = min(10, maxCores),
trimMatchStratifyThreads = min(10, maxCores),
prefilterCovariatesThreads = min(5, maxCores),
fitOutcomeModelThreads = min(10, maxCores),
outcomeCvThreads = min(2, maxCores),
refitPsForEveryOutcome = FALSE,
refitPsForEveryStudyPopulation = FALSE,
prefilterCovariates = TRUE,
outcomeIdsOfInterest = hois$cohortId)
file.rename(from = file.path(indicationFolder, "cmOutput", "outcomeModelReference.rds"),
to = file.path(indicationFolder, "cmOutput", "outcomeModelReference3.rds"))
# Fourth run: Reverse pairs, exclude comparator controls ------------------------------------
if (length(cmAnalysisListAsym) != 0) {
# Create reverse (comparator-target) cohortMethodData and ps objects: Warning: cohortMethodData will
# not have covariate and covariateRef data, since we won't need them (PS is already computed)
pathToRds <- file.path(indicationFolder, "cmOutput", "outcomeModelReference1.rds")
reference <- readRDS(pathToRds)
reference <- reference[order(reference$cohortMethodDataFolder), ]
reference <- reference[!duplicated(reference$cohortMethodDataFolder), ]
ParallelLogger::logInfo("Making cohortMethodData and ps objects symmetrical")
addOtherHalf <- function(i) {
sourceFolder <- file.path(cmFolder, reference$cohortMethodDataFolder[i])
targetFolder <- gsub(paste0("_t", reference$targetId[i]),
paste0("_t", reference$comparatorId[i]),
gsub(paste0("_c", reference$comparatorId[i]),
paste0("_c", reference$targetId[i]),
sourceFolder))
if (!file.exists(targetFolder)) {
cohortMethodData <- CohortMethod::loadCohortMethodData(sourceFolder)
idx <- ff::as.ff(1:2)
cohortMethodData$covariates <- cohortMethodData$covariates[idx, ]
cohortMethodData$covariateRef <- cohortMethodData$covariateRef[idx, ]
cohortMethodData$analysisRef <- cohortMethodData$analysisRef[idx, ]
cohortMethodData$cohorts$treatment <- 1 - cohortMethodData$cohorts$treatment
metaData <- attr(cohortMethodData$cohorts, "metaData")
temp <- metaData$attrition$targetPersons
metaData$attrition$targetPersons <- metaData$attrition$comparatorPersons
metaData$attrition$comparatorPersons <- temp
metaData$targetId <- reference$comparatorId[i]
metaData$comparatorId <- reference$targetId[i]
attr(cohortMethodData$cohorts, "metaData") <- metaData
CohortMethod::saveCohortMethodData(cohortMethodData, targetFolder)
}
sourceFile <- file.path(cmFolder, reference$sharedPsFile[i])
targetFile <- gsub(paste0("_t", reference$targetId[i]),
paste0("_t", reference$comparatorId[i]),
gsub(paste0("_c", reference$comparatorId[i]),
paste0("_c", reference$targetId[i]),
sourceFile))
if (!file.exists(targetFile)) {
ps <- readRDS(sourceFile)
ps$propensityScore <- 1 - ps$propensityScore
ps$preferenceScore <- 1 - ps$preferenceScore
ps$treatment <- 1 - ps$treatment
metaData <- attr(ps, "metaData")
temp <- metaData$attrition$targetPersons
metaData$attrition$targetPersons <- metaData$attrition$comparatorPersons
metaData$attrition$comparatorPersons <- temp
metaData$targetId <- reference$comparatorId[i]
metaData$comparatorId <- reference$targetId[i]
if (!is.null(metaData$psModelCoef)) {
metaData$psModelCoef <- -metaData$psModelCoef
}
attr(ps, "metaData") <- metaData
saveRDS(ps, targetFile)
}
return(NULL)
}
plyr::llply(1:nrow(reference), addOtherHalf, .progress = "text")
tcos <- lapply(1:nrow(exposureSummary),
createTcos,
positiveControl = "excludeComparator",
reverse = TRUE)
tcos <- plyr::compact(tcos)
cmAnalyses <- c(cmAnalysisListAsym)
CohortMethod::runCmAnalyses(connectionDetails = NULL,
cdmDatabaseSchema = NULL,
exposureDatabaseSchema = NULL,
exposureTable = NULL,
outcomeDatabaseSchema = NULL,
outcomeTable = NULL,
outputFolder = cmFolder,
oracleTempSchema = NULL,
cmAnalysisList = cmAnalyses,
cdmVersion = 5,
targetComparatorOutcomesList = tcos,
getDbCohortMethodDataThreads = 1,
createStudyPopThreads = min(4, maxCores),
createPsThreads = max(1, round(maxCores/10)),
psCvThreads = min(10, maxCores),
trimMatchStratifyThreads = min(4, maxCores),
fitOutcomeModelThreads = min(8, maxCores),
outcomeCvThreads = min(2, maxCores),
refitPsForEveryOutcome = FALSE,
refitPsForEveryStudyPopulation = FALSE,
prefilterCovariates = TRUE,
outcomeIdsOfInterest = hois$cohortId)
file.rename(from = file.path(indicationFolder, "cmOutput", "outcomeModelReference.rds"),
to = file.path(indicationFolder, "cmOutput", "outcomeModelReference4.rds"))
}
# Create analysis summaries -------------------------------------------------------------------
outcomeModelReference1 <- readRDS(file.path(indicationFolder,
"cmOutput",
"outcomeModelReference1.rds"))
outcomeModelReference2 <- readRDS(file.path(indicationFolder,
"cmOutput",
"outcomeModelReference2.rds"))
outcomeModelReference3 <- readRDS(file.path(indicationFolder,
"cmOutput",
"outcomeModelReference3.rds"))
if (file.exists(file.path(indicationFolder,
"cmOutput",
"outcomeModelReference4.rds"))) {
outcomeModelReference4 <- readRDS(file.path(indicationFolder,
"cmOutput",
"outcomeModelReference4.rds"))
} else {
outcomeModelReference4 <- NULL
}
# Check to make sure no file names were used twice:
if (any(outcomeModelReference1$studyPopFile != "" & outcomeModelReference1$studyPopFile %in% outcomeModelReference2$studyPopFile)) {
stop("Overlapping studyPop files detected between run 1 and 2")
}
if (any(outcomeModelReference1$studyPopFile != "" & outcomeModelReference1$studyPopFile %in% outcomeModelReference3$studyPopFile)) {
stop("Overlapping studyPop files detected between run 1 and 3")
}
if (any(outcomeModelReference2$studyPopFile != "" & outcomeModelReference2$studyPopFile %in% outcomeModelReference3$studyPopFile)) {
stop("Overlapping studyPop files detected between run 2 and 3")
}
if (any(outcomeModelReference1$strataFile != "" & outcomeModelReference1$strataFile %in% outcomeModelReference2$strataFile)) {
stop("Overlapping strataFile files detected between run 1 and 2")
}
if (any(outcomeModelReference1$strataFile != "" & outcomeModelReference1$strataFile %in% outcomeModelReference3$strataFile)) {
stop("Overlapping strata files detected between run 1 and 3")
}
if (any(outcomeModelReference2$strataFile != "" & outcomeModelReference2$strataFile %in% outcomeModelReference3$strataFile)) {
stop("Overlapping strata files detected between run 2 and 3")
}
if (!is.null(outcomeModelReference4)) {
if (any(outcomeModelReference1$studyPopFile != "" & outcomeModelReference1$studyPopFile %in% outcomeModelReference4$studyPopFile)) {
stop("Overlapping studyPop files detected between run 1 and 4")
}
if (any(outcomeModelReference2$studyPopFile != "" & outcomeModelReference2$studyPopFile %in% outcomeModelReference4$studyPopFile)) {
stop("Overlapping studyPop files detected between run 2 and 4")
}
if (any(outcomeModelReference3$studyPopFile != "" & outcomeModelReference3$studyPopFile %in% outcomeModelReference4$studyPopFile)) {
stop("Overlapping studyPop files detected between run 3 and 4")
}
if (any(outcomeModelReference1$strataFile != "" & outcomeModelReference1$strataFile %in% outcomeModelReference4$strataFile)) {
stop("Overlapping strata files detected between run 1 and 4")
}
if (any(outcomeModelReference2$strataFile != "" & outcomeModelReference2$strataFile %in% outcomeModelReference4$strataFile)) {
stop("Overlapping strata files detected between run 2 and 4")
}
if (any(outcomeModelReference3$strataFile != "" & outcomeModelReference3$strataFile %in% outcomeModelReference4$strataFile)) {
stop("Overlapping strata files detected between run 3 and 4")
}
}
ParallelLogger::logInfo("Summarizing results")
analysesSum <- CohortMethod::summarizeAnalyses(referenceTable = outcomeModelReference1,
outputFolder = cmFolder)
write.csv(analysesSum, file.path(indicationFolder, "analysisSummary1.csv"), row.names = FALSE)
analysesSum <- CohortMethod::summarizeAnalyses(referenceTable = outcomeModelReference2,
outputFolder = cmFolder)
write.csv(analysesSum, file.path(indicationFolder, "analysisSummary2.csv"), row.names = FALSE)
analysesSum <- CohortMethod::summarizeAnalyses(referenceTable = outcomeModelReference3,
outputFolder = cmFolder)
write.csv(analysesSum, file.path(indicationFolder, "analysisSummary3.csv"), row.names = FALSE)
if (!is.null(outcomeModelReference4)) {
analysesSum <- CohortMethod::summarizeAnalyses(referenceTable = outcomeModelReference4,
outputFolder = cmFolder)
write.csv(analysesSum, file.path(indicationFolder, "analysisSummary4.csv"), row.names = FALSE)
}
}
#' Create the analyses details
#'
#' @details
#' This function creates files specifying the analyses that will be performed.
#'
#' @param outputFolder Name of local folder to place results; make sure to use forward slashes (/)
#'
#' @export
createAnalysesDetails <- function(outputFolder) {
# Depression --------------------------------------------------------------
# dummy args, will never be used because data objects have already been created:
getDbCmDataArgs <- CohortMethod::createGetDbCohortMethodDataArgs(covariateSettings = FeatureExtraction::createCovariateSettings())
# Note: censoring at new risk window will only affect depression, as hypertension cannot
# have subsequent first-time user exposure.
# The censoring is to prevent bias towards the null, which occurs when exposure time
# of one exposure overlaps with the other.
createStudyPopArgsOnTreatment <- CohortMethod::createCreateStudyPopulationArgs(removeDuplicateSubjects = "keep first",
removeSubjectsWithPriorOutcome = TRUE,
riskWindowStart = 1,
riskWindowEnd = 0,
addExposureDaysToEnd = TRUE,
minDaysAtRisk = 1,
censorAtNewRiskWindow = TRUE)
createStudyPopArgsItt <- CohortMethod::createCreateStudyPopulationArgs(removeDuplicateSubjects = "keep first",
removeSubjectsWithPriorOutcome = TRUE,
riskWindowStart = 1,
riskWindowEnd = 9999,
addExposureDaysToEnd = FALSE,
minDaysAtRisk = 1)
subgroupCovariateIds <- c(1998, 2998, 3998, 4998, 5998, 6998, 7998, 8998)
createPsArgs <- CohortMethod::createCreatePsArgs(control = Cyclops::createControl(noiseLevel = "silent",
cvType = "auto",
tolerance = 2e-07,
cvRepetitions = 1,
startingVariance = 0.01,
seed = 123),
stopOnError = FALSE,
excludeCovariateIds = subgroupCovariateIds,
maxCohortSizeForFitting = 1e+05)
stratifyByPsArgs <- CohortMethod::createStratifyByPsArgs(numberOfStrata = 10,
baseSelection = "all")
fitOutcomeModelArgs1 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox")
cmAnalysis1 <- CohortMethod::createCmAnalysis(analysisId = 1,
description = "PS stratification, on-treatment",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgs1)
cmAnalysis2 <- CohortMethod::createCmAnalysis(analysisId = 2,
description = "PS stratification, intent-to-treat",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgs1)
cmAnalysisList <- list(cmAnalysis1, cmAnalysis2)
CohortMethod::saveCmAnalysisList(cmAnalysisList,
file.path(outputFolder, "cmAnalysisListDepression.json"))
matchOnPsArgs <- CohortMethod::createMatchOnPsArgs(caliper = 0.2,
caliperScale = "standardized logit",
maxRatio = 100)
cmAnalysis3 <- CohortMethod::createCmAnalysis(analysisId = 3,
description = "PS matching, on-treatment",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
matchOnPs = TRUE,
matchOnPsArgs = matchOnPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgs1)
cmAnalysis4 <- CohortMethod::createCmAnalysis(analysisId = 4,
description = "PS matching, intent-to-treat",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
matchOnPs = TRUE,
matchOnPsArgs = matchOnPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgs1)
cmAnalysisListAsym <- list(cmAnalysis3, cmAnalysis4)
CohortMethod::saveCmAnalysisList(cmAnalysisListAsym,
file.path(outputFolder, "cmAnalysisListAsymDepression.json"))
fitOutcomeModelArgsI1998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 1998)
cmAnalysis5 <- CohortMethod::createCmAnalysis(analysisId = 5,
description = "PS stratification, on-treatment, renal impairment interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI1998)
cmAnalysis6 <- CohortMethod::createCmAnalysis(analysisId = 6,
description = "PS stratification, intent-to-treat, renal impairment interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI1998)
fitOutcomeModelArgsI2998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 2998)
cmAnalysis7 <- CohortMethod::createCmAnalysis(analysisId = 7,
description = "PS stratification, on-treatment, hepatic impairment interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI2998)
cmAnalysis8 <- CohortMethod::createCmAnalysis(analysisId = 8,
description = "PS stratification, intent-to-treat, hepatic impairment interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI2998)
fitOutcomeModelArgsI3998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 3998)
cmAnalysis9 <- CohortMethod::createCmAnalysis(analysisId = 9,
description = "PS stratification, on-treatment, pregnancy interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI3998)
cmAnalysis10 <- CohortMethod::createCmAnalysis(analysisId = 10,
description = "PS stratification, intent-to-treat, pregnancy interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI3998)
fitOutcomeModelArgsI4998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 4998)
cmAnalysis11 <- CohortMethod::createCmAnalysis(analysisId = 11,
description = "PS stratification, on-treatment, children interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI4998)
cmAnalysis12 <- CohortMethod::createCmAnalysis(analysisId = 12,
description = "PS stratification, intent-to-treat, children interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI4998)
fitOutcomeModelArgsI5998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 5998)
cmAnalysis13 <- CohortMethod::createCmAnalysis(analysisId = 13,
description = "PS stratification, on-treatment, elderly interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI5998)
cmAnalysis14 <- CohortMethod::createCmAnalysis(analysisId = 14,
description = "PS stratification, intent-to-treat, elderly interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI5998)
fitOutcomeModelArgsI6998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 6998)
cmAnalysis15 <- CohortMethod::createCmAnalysis(analysisId = 15,
description = "PS stratification, on-treatment, female interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI6998)
cmAnalysis16 <- CohortMethod::createCmAnalysis(analysisId = 16,
description = "PS stratification, intent-to-treat, female interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI6998)
cmAnalysisListInteractions <- list(cmAnalysis5,
cmAnalysis6,
cmAnalysis7,
cmAnalysis8,
cmAnalysis9,
cmAnalysis10,
cmAnalysis11,
cmAnalysis12,
cmAnalysis13,
cmAnalysis14,
cmAnalysis15,
cmAnalysis16)
CohortMethod::saveCmAnalysisList(cmAnalysisListInteractions,
file.path(outputFolder,
"cmAnalysisListInteractionsDepression.json"))
# Hypertension --------------------------------------------------------------
# Main analyses: just use same as depression
CohortMethod::saveCmAnalysisList(cmAnalysisList,
file.path(outputFolder, "cmAnalysisListHypertension.json"))
CohortMethod::saveCmAnalysisList(cmAnalysisListAsym,
file.path(outputFolder, "cmAnalysisListAsymHypertension.json"))
# Interactions: add type 2 diabetes mellitus subgroup
fitOutcomeModelArgsI7998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 7998)
cmAnalysis17 <- CohortMethod::createCmAnalysis(analysisId = 17,
description = "PS stratification, on-treatment, T2DM interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI7998)
cmAnalysis18 <- CohortMethod::createCmAnalysis(analysisId = 18,
description = "PS stratification, intent-to-treat, T2DM interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI7998)
# Interactions: add black or african american subgroup
fitOutcomeModelArgsI8998 <- CohortMethod::createFitOutcomeModelArgs(stratified = TRUE,
modelType = "cox",
interactionCovariateIds = 8998)
cmAnalysis19 <- CohortMethod::createCmAnalysis(analysisId = 19,
description = "PS stratification, on-treatment, black or african american interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsOnTreatment,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI8998)
cmAnalysis20 <- CohortMethod::createCmAnalysis(analysisId = 20,
description = "PS stratification, intent-to-treat, black or african american interactions",
getDbCohortMethodDataArgs = getDbCmDataArgs,
createStudyPopArgs = createStudyPopArgsItt,
createPs = TRUE,
createPsArgs = createPsArgs,
stratifyByPs = TRUE,
stratifyByPsArgs = stratifyByPsArgs,
fitOutcomeModel = TRUE,
fitOutcomeModelArgs = fitOutcomeModelArgsI8998)
cmAnalysisListInteractions <- list(cmAnalysis5,
cmAnalysis6,
cmAnalysis7,
cmAnalysis8,
cmAnalysis9,
cmAnalysis10,
cmAnalysis11,
cmAnalysis12,
cmAnalysis13,
cmAnalysis14,
cmAnalysis15,
cmAnalysis16,
cmAnalysis17,
cmAnalysis18,
cmAnalysis19,
cmAnalysis20)
CohortMethod::saveCmAnalysisList(cmAnalysisListInteractions,
file.path(outputFolder,
"cmAnalysisListInteractionsHypertension.json"))
}