forked from ellessenne/comorbidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
289 lines (220 loc) · 9.22 KB
/
README.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
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
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE
)
options(width = 100)
```
# This is a fork of the {comorbidity} package.
There have been a limited number of people who have used this fork in their own work since I first created it back in 2020. If anyone finds that their code that utlized the `Main` branch of this fork no longer functions, please see the `retired` branch. For thos who have been using the `updated_elixhauser` branch, you may continue to do so. The `Main` branch currently reflects `updated_elixhauser`, but may be changed substantiatlly in the future as I attempt to prepare this fork for possible merging with ellessenne's version.
# The {comorbidity} Package: Computing Comorbidity Scores <img src="man/figures/hex.png" width = "150" align="right" />
Last updated: `r Sys.Date()`
<!-- badges: start -->
[![R build status](https://github.com/ellessenne/comorbidity/workflows/R-CMD-check/badge.svg)](https://github.com/ellessenne/comorbidity/actions)
[![Codecov test coverage](https://codecov.io/gh/ellessenne/comorbidity/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ellessenne/comorbidity?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/comorbidity)](https://cran.r-project.org/package=comorbidity)
[![CRAN_Logs_Badge](http://cranlogs.r-pkg.org/badges/comorbidity)](https://cran.r-project.org/package=comorbidity)
[![CRAN_Logs_Badge_Total](http://cranlogs.r-pkg.org/badges/grand-total/comorbidity)](https://cran.r-project.org/package=comorbidity)
[![JOSS DOI](http://joss.theoj.org/papers/10.21105/joss.00648/status.svg)](https://doi.org/10.21105/joss.00648)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://makeapullrequest.com/)
<!-- badges: end -->
`comorbidity` is an R package for computing comorbidity scores such as the weighted Charlson score and the Elixhauser comorbidity score; both ICD-10 and ICD-9 coding systems are supported.
In addition, this package provides features implementing the 2020, 2021 and 2022 versions of the AHRQ's 'Elixhauser Comorbidity Software' (https://www.hcup-us.ahrq.gov/toolssoftware/comorbidityicd10/comorbidity_icd10.jsp) in R. Simialar to the AHRQ Software, the two following Elixhauser Comorbidity Indices refined for ICD-10-CM could be predicted:
- Risk of in-hospital mortality
- Risk of 30-day, all-cause readmission
## Installation
`comorbidity` is on CRAN. You can install it as usual with:
```{r cran-installation, eval = FALSE}
install.packages("comorbidity")
```
Alternatively, you can install the development version from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("ellessenne/comorbidity")
```
## Simulating ICD-10 codes
The `comorbidity` packages includes a function named `sample_diag()` that allows simulating ICD diagnostic codes in a straightforward way. For instance, we could simulate ICD-10 codes:
```{r simulate-data}
# load the comorbidity package
library(comorbidity)
# set a seed for reproducibility
set.seed(1)
# simulate 50 ICD-10 codes for 5 individuals
x <- data.frame(
id = sample(1:5, size = 50, replace = TRUE),
code = sample_diag(n = 50)
)
x <- x[order(x$id, x$code), ]
print(head(x, n = 15), row.names = FALSE)
```
It is also possible to simulate from two different versions of the ICD-10 coding system. The default is to simulate ICD-10 codes from the 2011 version:
```{r simulate-data-2011}
set.seed(1)
x1 <- data.frame(
id = sample(1:3, size = 30, replace = TRUE),
code = sample_diag(n = 30)
)
set.seed(1)
x2 <- data.frame(
id = sample(1:3, size = 30, replace = TRUE),
code = sample_diag(n = 30, version = "ICD10_2011")
)
# should return TRUE
all.equal(x1, x2)
```
Alternatively, you could use the 2009 version:
```{r simulate-data-2009}
set.seed(1)
x1 <- data.frame(
id = sample(1:3, size = 30, replace = TRUE),
code = sample_diag(n = 30, version = "ICD10_2009")
)
set.seed(1)
x2 <- data.frame(
id = sample(1:3, size = 30, replace = TRUE),
code = sample_diag(n = 30, version = "ICD10_2011")
)
# should not return TRUE
all.equal(x1, x2)
```
## Simulating ICD-9 codes
ICD-9 codes can be easily simulated too:
```{r simulate-data-icd9}
set.seed(2)
x9 <- data.frame(
id = sample(1:3, size = 30, replace = TRUE),
code = sample_diag(n = 30, version = "ICD9_2015")
)
x9 <- x9[order(x9$id, x9$code), ]
print(head(x9, n = 15), row.names = FALSE)
```
## Sample Data of ICD-10 codes, ICD-10 codes squences, MS-DRG, and Present on Admission (POA) status of ICD-10 codes
This data set could be used to test the package specifically the AHRQ Software oriented features.
The data fields of the data set are:
* DischargeFiscalYearNBR (Year of Discharge)
* QuarterNBR (Year Quarter)
* MSDRG (MS-DRG)
* ICD10DiagnosisCD (ICD-10 Code)
* ICD10DiagnosisSEQ (Sequence of ICD-10 Code)
* PresentOnAdmissionCD (POA)
```{r ahrq_section_test_data}
x10 <- as.data.frame(
readRDS(file.path('data', 'ahrq_section_test_data.rds'))
)
print(
x10[x10$ID %in% 1:3, ]
)
```
## Computing comorbidity scores
The main function of the `comorbidity` package is named `comorbidity()`, and it can be used to compute any supported comorbidity score; scores can be specified by setting the `score` argument, which is required.
Say we have 3 individuals with a total of 30 ICD-10 diagnostic codes:
```{r simulate-data-cs}
set.seed(1)
x <- data.frame(
id = sample(1:3, size = 30, replace = TRUE),
code = sample_diag(n = 30)
)
```
We could compute the Charlson comorbidity domains:
```{r charlson}
charlson <- comorbidity(x = x, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = FALSE)
charlson
```
We set the `assign0` argument to `FALSE` to not apply a hierarchy of comorbidity codes, as described in `?comorbidity::comorbidity`.
Alternatively, we could compute the Elixhauser score:
```{r elixhauser}
elixhauser <- comorbidity(x = x, id = "id", code = "code", map = "elixhauser_icd10_quan", assign0 = FALSE)
elixhauser
```
Weighted an unweighted comorbidity scores can be obtained using the `score()` function:
```{r score}
unw_cci <- score(charlson, weights = NULL, assign0 = FALSE)
unw_cci
quan_cci <- score(charlson, weights = "quan", assign0 = FALSE)
quan_cci
all.equal(unw_cci, quan_cci)
```
Code for the Elixhauser score is omitted, but works analogously.
Conversely, say we have 5 individuals with a total of 100 ICD-9 diagnostic codes:
```{r simulate-data-cs-9}
set.seed(3)
x <- data.frame(
id = sample(1:5, size = 100, replace = TRUE),
code = sample_diag(n = 100, version = "ICD9_2015")
)
```
The Charlson and Elixhauser comorbidity codes can be easily computed once again:
```{r charlson-9}
charlson9 <- comorbidity(x = x, id = "id", code = "code", map = "charlson_icd9_quan", assign0 = FALSE)
charlson9
```
```{r elixhauser-9}
elixhauser9 <- comorbidity(x = x, id = "id", code = "code", map = "elixhauser_icd9_quan", assign0 = FALSE)
elixhauser9
```
Comorbidity codes for different versions of the AHRQ’s ‘Elixhauser Comorbidity Software’ could be computed. Accordingly, 'map' argument could take any of the following ones:
- elixhauser_ahrq_2020
- elixhauser_ahrq_2021
- elixhauser_ahrq_2022
The following example calculates the comorbidity codes for the 2020 version.
```{r ahrq_2020}
elixhauser_ahrq_2020 <- comorbidity(
x=x10[x10$ID %in% 1:3, ],
id='ID',
code='ICD10DiagnosisCD',
map='elixhauser_ahrq_2020',
assign0=F,
drg='MSDRG',
icd_rank='ICD10DiagnosisSEQ',
poa='PresentOnAdmissionCD',
year='DischargeFiscalYearNBR',
quarter='QuarterNBR'
)
elixhauser_ahrq_2020
```
The following example calculates the comorbidity codes for the 2022 version.
The 2021 and 2022 versions do not require a specified "drg" argument.
```{r ahrq_2021_2022}
elixhauser_ahrq_2022 <- comorbidity(
x=x10[x10$ID %in% 1:3, ],
id='ID',
code='ICD10DiagnosisCD',
map='elixhauser_ahrq_2022',
assign0=F,
icd_rank='ICD10DiagnosisSEQ',
poa='PresentOnAdmissionCD',
year='DischargeFiscalYearNBR',
quarter='QuarterNBR'
)
elixhauser_ahrq_2022
```
Scores:
```{r score-9}
unw_eci <- score(elixhauser9, weights = NULL, assign0 = FALSE)
vw_eci <- score(elixhauser9, weights = "vw", assign0 = FALSE)
all.equal(unw_eci, vw_eci)
```
To calculate 'Risk of in-hospital mortality' index, 'weights' is set to 'mw'.
```{r score-ahrq}
ahrq_scores <- score(elixhauser_ahrq_2022, weights = "mw", assign0 = FALSE)
ahrq_scores
```
'Risk of 30-day, all-cause readmission' index could be calculated by setting 'weights' to 'rw'.
## Citation
If you find `comorbidity` useful, please cite it in your publications:
```{r citation}
citation("comorbidity")
```
## References
More details on which comorbidity mapping and scoring algorithm are available within the package can be found in the two accompanying vignettes, which can be accessed on CRAN or directly from your R session:
```r
vignette("01-introduction", package = "comorbidity")
vignette("02-comorbidity-scores", package = "comorbidity")
```
## Copyright
The icon for the hex sticker was made by [monkik](https://www.flaticon.com/authors/monkik) from [www.flaticon.com](https://www.flaticon.com), and is licensed by [Creative Commons BY 3.0](https://creativecommons.org/licenses/by/3.0).