-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathElixhauser_Supplementary_Table.R
135 lines (104 loc) · 4 KB
/
Elixhauser_Supplementary_Table.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
library(icd)
library(tidyverse)
library(stringi)
first_3 <- function(x) {
# retain first 3 characters of the ICD code
substr(x, 1, 3) %>% unique()
}
# import mapping from icd package
icd10_comorb_map = icd10_map_quan_elix
icd9_comorb_map = icd9_map_quan_elix
# truncate all codes to the first 3 characters
icd10_comorb_map <- lapply(icd10_comorb_map, first_3)
icd9_comorb_map <- lapply(icd9_comorb_map, first_3)
format_comorbs <- function(icd_comorb_map) {
comorb_formatted_list <- list()
# combine hypertension and diabetes
for (i in names(icd_comorb_map)) {
formatted_comorb = stri_join_list(icd_comorb_map[i], sep = ", ") %>%
as.data.frame() %>%
mutate(Comorbidity = paste(i)) %>%
rename("ICD Codes" = ".") %>%
select(Comorbidity, `ICD Codes`)
comorb_formatted_list[[i]] <- formatted_comorb
}
comorbidity_code_table <- bind_rows(comorb_formatted_list)
hypertension_combined <- comorbidity_code_table %>%
filter(Comorbidity == "HTN" | Comorbidity == "HTNcx") %>%
select(`ICD Codes`) %>%
as.list() %>%
sapply(., toString) %>%
as.data.frame() %>%
rename("ICD Codes" = ".") %>%
mutate(Comorbidity = "HTN, combined") %>%
select(Comorbidity, `ICD Codes`)
diabetes_combined <- comorbidity_code_table %>%
filter(Comorbidity == "DM" | Comorbidity == "DMcx") %>%
select(`ICD Codes`) %>%
as.list() %>%
sapply(., toString) %>%
as.data.frame() %>%
rename("ICD Codes" = ".") %>%
mutate(Comorbidity = "DM") %>%
select(Comorbidity, `ICD Codes`)
comorbidity_code_table <- comorbidity_code_table %>%
filter(!Comorbidity %in% c("HTN", "HTNcx", "DM", "DMcx")) %>%
rbind(., diabetes_combined, hypertension_combined)
# create a list of comorbs
# this should the order that the van_walraven_from_comorbid function applies weights
comorb_names <- names(icd10_comorb_map)
# add the weights
# note that hypertension will need to be in the righ oft order ( I manually moved the weights by hand to end for Hypertension and diabetes)
# note that each diabetes code has a weight (of 0), but I removed 1
van_walraven_weights <- c(7, 5, -1, 4, 2, 7, 6, 3, 0, 5, 11,
0, 0, 9, 12, 4, 0, 3, -4, 6, 5, -2, -2, 0, -7, 0, -3, 0, 0)
# should have 29 values
length(van_walraven_weights)
comorbidity_code_table <- comorbidity_code_table %>% cbind(van_walraven_weights)
# add full names for comorbidities to replace abbreviations
# this list was adaptaed from that in mappingNames.R provided by icd package
comorbidity_full <- c(
"Congestive heart failure",
"Cardiac arrhythmias",
"Valvular disease",
"Pulmonary circulation disorders",
"Peripheral vascular disorders",
"Paralysis",
"Other neurological disorders",
"Chronic pulmonary disease",
"Hypothyroidism",
"Renal failure",
"Liver disease",
"Peptic ulcer disease excluding bleeding",
"HIV/AIDS",
"Lymphoma",
"Metastatic cancer",
"Solid tumor without metastasis",
"Rheumatoid arthritis/collagen vascular diseases",
"Coagulopathy",
"Obesity",
"Weight loss",
"Fluid and electrolyte disorders",
"Blood loss anemia",
"Deficiency anemias",
"Alcohol abuse",
"Drug abuse",
"Psychoses",
"Depression",
"Diabetes",
"Hypertension"
)
comorbidity_code_table <- comorbidity_code_table %>%
cbind(comorbidity_full) %>%
arrange(comorbidity_full) %>%
select(comorbidity_full, `ICD Codes`, van_walraven_weights) %>%
rename("Comorbidity" = comorbidity_full,
"Van Walraven Weights" = van_walraven_weights)
return(comorbidity_code_table)
}
comorbidity_code_table10 <- format_comorbs(icd10_comorb_map) %>%
rename("ICD-10 Codes" = `ICD Codes`)
comorbidity_code_table9 <- format_comorbs(icd9_comorb_map) %>%
rename("ICD-9 Codes" = `ICD Codes`)
write.csv(comorbidity_code_table10, "tables/Table_Comorbidity_Mapping_ICD10.csv", row.names = FALSE)
write.csv(comorbidity_code_table9, "tables/Table_Comorbidity_Mapping_ICD9.csv", row.names = FALSE)