-
Notifications
You must be signed in to change notification settings - Fork 7
/
DefaultCovariateSettings.R
148 lines (143 loc) · 6.86 KB
/
DefaultCovariateSettings.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
# Copyright 2022 Observational Health Data Sciences and Informatics
#
# This file is part of PheValuator
#
# 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.
#' Create the default covariate settings
#'
#' @description
#' Create the default covariate settings for acute or chronic diseases
#'
#' @details
#' Function to create the default covariate settings for acute or chronic diseases
#'
#' @param excludedCovariateConceptIds A list of conceptIds to exclude from featureExtraction. These
#' should include all concept_ids that were used to define the
#' xSpec model (default=NULL)
#' @param includedCovariateIds A list of covariate IDs that should be restricted to.
#' @param includedCovariateConceptIds A list of covariate concept IDs that should be restricted to.
#' @param addDescendantsToExclude Should descendants of excluded concepts also be excluded?
#' (default=FALSE)
#' @param startDayWindow1 The day to start time window 1 for feature extraction
#' @param endDayWindow1 The day to end time window 1 for feature extraction
#' @param startDayWindow2 The day to start time window 2 for feature extraction
#' @param endDayWindow2 The day to end time window 2 for feature extraction
#' @param startDayWindow3 The day to start time window 3 for feature extraction
#' @param endDayWindow3 The day to end time window 3 for feature extraction #'
#'
#' @export
createDefaultCovariateSettings <- function(excludedCovariateConceptIds = c(),
includedCovariateIds = c(),
includedCovariateConceptIds = c(),
addDescendantsToExclude = FALSE,
startDayWindow1 = 0,
endDayWindow1 = 9999,
startDayWindow2 = NULL,
endDayWindow2 = NULL,
startDayWindow3 = NULL,
endDayWindow3 = NULL) {
covariateSettings1 <- FeatureExtraction::createCovariateSettings(
useDemographicsGender = TRUE,
useDemographicsAgeGroup = TRUE,
useDemographicsRace = TRUE,
useDemographicsEthnicity = TRUE,
useConditionGroupEraLongTerm = TRUE,
useDrugGroupEraLongTerm = TRUE,
useProcedureOccurrenceLongTerm = TRUE,
useDeviceExposureLongTerm = TRUE,
useMeasurementLongTerm = TRUE,
useMeasurementValueLongTerm = TRUE,
useMeasurementRangeGroupLongTerm = TRUE,
useObservationLongTerm = TRUE,
useDistinctConditionCountLongTerm = TRUE,
useDistinctIngredientCountLongTerm = TRUE,
useDistinctProcedureCountLongTerm = TRUE,
useDistinctMeasurementCountLongTerm = TRUE,
useVisitCountLongTerm = TRUE,
useVisitConceptCountLongTerm = TRUE,
longTermStartDays = startDayWindow1,
shortTermStartDays = startDayWindow1,
mediumTermStartDays = startDayWindow1,
endDays = endDayWindow1,
includedCovariateConceptIds = c(includedCovariateConceptIds),
addDescendantsToInclude = addDescendantsToExclude,
excludedCovariateConceptIds = excludedCovariateConceptIds,
addDescendantsToExclude = addDescendantsToExclude,
includedCovariateIds = c(includedCovariateIds)
)
if (!(is.null(startDayWindow2))) {
covariateSettings2 <- FeatureExtraction::createCovariateSettings(
useConditionGroupEraShortTerm = TRUE,
useDrugGroupEraShortTerm = TRUE,
useProcedureOccurrenceShortTerm = TRUE,
useDeviceExposureShortTerm = TRUE,
useMeasurementShortTerm = TRUE,
useMeasurementValueShortTerm = TRUE,
useMeasurementRangeGroupShortTerm = TRUE,
useObservationShortTerm = TRUE,
useDistinctConditionCountShortTerm = TRUE,
useDistinctIngredientCountShortTerm = TRUE,
useDistinctProcedureCountShortTerm = TRUE,
useDistinctMeasurementCountShortTerm = TRUE,
useVisitCountShortTerm = TRUE,
useVisitConceptCountShortTerm = TRUE,
longTermStartDays = startDayWindow2,
shortTermStartDays = startDayWindow2,
mediumTermStartDays = startDayWindow2,
endDays = endDayWindow2,
includedCovariateConceptIds = c(includedCovariateConceptIds),
addDescendantsToInclude = addDescendantsToExclude,
excludedCovariateConceptIds = excludedCovariateConceptIds,
addDescendantsToExclude = addDescendantsToExclude,
includedCovariateIds = c(includedCovariateIds)
)
}
if (!(is.null(startDayWindow3))) {
covariateSettings3 <- FeatureExtraction::createCovariateSettings(
useConditionGroupEraMediumTerm = TRUE,
useDrugGroupEraMediumTerm = TRUE,
useProcedureOccurrenceMediumTerm = TRUE,
useDeviceExposureMediumTerm = TRUE,
useMeasurementMediumTerm = TRUE,
useMeasurementValueMediumTerm = TRUE,
useMeasurementRangeGroupMediumTerm = TRUE,
useObservationMediumTerm = TRUE,
useDistinctConditionCountMediumTerm = TRUE,
useDistinctIngredientCountMediumTerm = TRUE,
useDistinctProcedureCountMediumTerm = TRUE,
useDistinctMeasurementCountMediumTerm = TRUE,
useVisitCountMediumTerm = TRUE,
useVisitConceptCountMediumTerm = TRUE,
longTermStartDays = startDayWindow3,
shortTermStartDays = startDayWindow3,
mediumTermStartDays = startDayWindow3, endDays = endDayWindow3,
includedCovariateConceptIds = c(includedCovariateConceptIds),
addDescendantsToInclude = addDescendantsToExclude,
excludedCovariateConceptIds = excludedCovariateConceptIds,
addDescendantsToExclude = addDescendantsToExclude,
includedCovariateIds = c(includedCovariateIds)
)
}
if (is.null(startDayWindow1)) {
stop("The first time window must not be null")
} else if (is.null(startDayWindow2) & is.null(startDayWindow3)) {
covariateSettings <- list(covariateSettings1)
} else if (!(is.null(startDayWindow2)) & is.null(startDayWindow3)) {
covariateSettings <- list(covariateSettings1, covariateSettings2)
} else if (!(is.null(startDayWindow3)) & is.null(startDayWindow2)) {
covariateSettings <- list(covariateSettings1, covariateSettings3)
} else {
covariateSettings <- list(covariateSettings1, covariateSettings2, covariateSettings3)
}
return(covariateSettings)
}