-
Notifications
You must be signed in to change notification settings - Fork 0
/
monthlytemporalVariability.Rmd
232 lines (191 loc) · 7.55 KB
/
monthlytemporalVariability.Rmd
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
---
title: 'Monthly Temporal Variability in Pediatric population: SITEID'
output:
html_document:
code_folding: show
toc: yes
toc_float: yes
pdf_document:
toc: yes
word_document:
toc: yes
---
```{r libraries, message=FALSE, warning=FALSE, results='hide'}
# Install packages
paket <- function(pak){
new_pak <- pak[!(pak %in% rownames(installed.packages()))]
if (length(new_pak))
install.packages(new_pak, dependencies = TRUE,repos="https://cloud.r-project.org/")
sapply(pak, library, character.only = TRUE)
}
listOfPackages <- c("EHRtemporalVariability", "dplyr", "tidyr", "tidyverse", "tableone", "plotly", "DT")
paket(listOfPackages)
```
```{r}
theme_set(theme_bw() +
theme(legend.title = element_blank(),
panel.grid.minor = element_blank()))
```
## Data read-in
Read the functions and data needed for the analysis.
```{r suppData, message=FALSE}
source("R/readInputFiles.R")
source("R/summaryTableOne.R")
source("R/tempVariability.R")
source("R/countsPerPatientMonth.R")
source("R/countsPerAgeGroup.R")
mentalDisorder <- read.delim('public-data/icd10_categories_mentalDisorders.txt')
icdCategory <- read.delim("public-data/icd10Codes.txt", header = FALSE, colClasses = "character")
```
Read the input files.
```{r message=FALSE, warning=FALSE}
### Read the CSV input files
#change to the path where your phase 2.1 data files are located
myinputFiles <- "/4ceData/Input/"
files <- readInputFiles( path = myinputFiles,
separator = ",",
skip = 0,
verbose = FALSE )
### Extract the patient summary and observation information.
demo_raw <- files[[1]]
obs_raw <- files[[2]]
clinical_raw <- files[[3]]
### Select only pediatric subset
demo_raw <- demo_raw[ demo_raw$age_group %in% c("00to02", "03to05", "06to11","12to17"), ]
obs_raw <- obs_raw[ obs_raw$patient_num %in% demo_raw$patient_num, ]
clinical_raw <- clinical_raw[ clinical_raw$patient_num %in% demo_raw$patient_num, ]
### Determine the obfuscation threshold (FALSE if no obfuscation, the numeric value of the obfuscation threshold if any)
obfuscation = FALSE
#obfuscation = 3
### Determine if you don't want to visualize counts
absoluteValue = TRUE
### Determine the analysis period
period = "month"
```
```{r}
counts_all <- countsPerPatientMonth( observationFile = obs_raw, clinicalFile = clinical_raw, type = "diagnosis", obfuscation = obfuscation)
counts_all[[1]] %>% ggplot() +
geom_line(aes(x = year_month,y = distinct_patients, group=1), color = "red",linetype = "dotted") +
labs(x = "calendar months", y = "number patients consulting for condition")+
theme_bw()+
theme(strip.text.x = element_text(size = 7), text = element_text(size=9),
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
```
# Mental Disorders
ICD10 codes extracted from: The ICD-10 Classification of Mental and Behavioural Disorders Clinical descriptions and diagnostic guidelines by the World Health Organization https://www.who.int/classifications/icd/en/bluebook.pdf
Suidice related codes added from: https://www.cdc.gov/nchs/data/nhsr/nhsr108.pdf
```{r}
DT::datatable( mentalDisorder, rownames = FALSE )
```
```{r message=FALSE, warning=FALSE}
probmaps_md <- tempVariability( VarSelection = "mental",
observations = obs_raw,
clinical = clinical_raw,
demographics = demo_raw,
period = period,
obfuscation = obfuscation,
absoluteValue = absoluteValue)
plotDataTemporalMap(
dataTemporalMap = probmaps_md[["mentaldescriptionShort"]],
startValue = 1,
endValue = 20,
startDate = "2020-04-01",
colorPalette = "Magma",
absolute = absoluteValue)
```
# Aggregated by PheWAS category
PheCode mapping file downloaded from: https://phewascatalog.org/phecodes_icd10
```{r message=FALSE, warning=FALSE}
probmaps_pc <- tempVariability( VarSelection = "phecodes",
observations = obs_raw,
clinical = clinical_raw,
demographics = demo_raw,
period = period,
obfuscation = obfuscation,
absoluteValue = absoluteValue)
plotDataTemporalMap(
dataTemporalMap = probmaps_pc[["phecodesdescriptionShort"]],
startValue = 1,
endValue = 20,
startDate = "2020-04-01",
colorPalette = "Magma",
absolute = absoluteValue)
```
# All ICD codes
```{r message=FALSE, warning=FALSE}
probmaps_all <- tempVariability( VarSelection = "all",
observations = obs_raw,
clinical = clinical_raw,
demographics = demo_raw,
period = period,
obfuscation = obfuscation,
absoluteValue = absoluteValue)
plotDataTemporalMap(
dataTemporalMap = probmaps_all$allconcept_code,
startValue = 1,
endValue = 20,
startDate = "2020-03-01",
colorPalette = "Magma",
absolute = absoluteValue)
```
# Higher general categories
```{r}
DT::datatable( icdCategory, rownames = FALSE )
```
```{r}
probmaps_category <- tempVariability( VarSelection = "category",
observations = obs_raw,
clinical = clinical_raw,
demographics = demo_raw,
period = period,
obfuscation = obfuscation,
absoluteValue = absoluteValue)
plotDataTemporalMap(
dataTemporalMap = probmaps_category$categoryDescription,
startValue = 1,
endValue = 20,
startDate = "2020-03-01",
colorPalette = "Magma",
absolute = absoluteValue)
```
```{r}
counts <- countsPerAgeGroup( observationFile = obs_raw, clinicalFile = clinical_raw, demogFile = demo_raw, obfuscation = FALSE)
```
# Medication
```{r}
countsMeds <- countsPerPatientMonth( observationFile = obs_raw, clinicalFile = clinical_raw, type = "medication", obfuscation = obfuscation)
countsMeds[[1]]%>% ggplot() +
geom_line(aes(x = year_month,y = distinct_patients, group=1), color = "red",linetype = "dotted") +
labs(x = "calendar months", y = "number patients consulting for condition")+
theme_bw()+
theme(strip.text.x = element_text(size = 7), text = element_text(size=9),
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
```
```{r message=FALSE, warning=FALSE}
probmaps_meds <- tempVariability( VarSelection = "medication",
observations = obs_raw,
clinical = clinical_raw,
demographics = demo_raw,
period = period,
obfuscation = obfuscation,
absoluteValue = absoluteValue)
plotDataTemporalMap(
dataTemporalMap = probmaps_meds[["medicationconcept_code"]],
startValue = 1,
endValue = 20,
colorPalette = "Magma",
absolute = absoluteValue)
```
# Save the RData file.
If the RData file is not correctly generated, you can try to change the extension to .rda, uncomment the last line of code in this chunk.
```{r}
probMaps <- c(probmaps_md, probmaps_all, probmaps_pc, probmaps_category, probmaps_meds)
igtProjs <- sapply ( probMaps, estimateIGTProjection )
countsDf <- c( counts_all, counts, countsMeds)
save(probMaps, igtProjs, countsDf, file = paste0("myExport_", period, ".RData"))
#save(probMaps, igtProjs, file = paste0("myExport_", period, ".rda"))
```
# R session information
```{r}
sessionInfo()
```