-
Notifications
You must be signed in to change notification settings - Fork 21
/
README.Rmd
212 lines (160 loc) · 6.32 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
---
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)
```
# The {comorbidity} Package: Computing Comorbidity Scores in R <img src="man/figures/hex.png" width = "150" align="right" alt="Hex sticker of the {comorbidity} R package."/>
Last updated: `r Sys.time()`
<!-- badges: start -->
[![R-CMD-check](https://github.com/ellessenne/comorbidity/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ellessenne/comorbidity/actions/workflows/R-CMD-check.yaml)
[![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.
## 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)
```
## 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
```
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)
```
## 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("A-introduction", package = "comorbidity")
vignette("B-comorbidity-scores", package = "comorbidity")
```
The list of available algorithms can be printed interactively using the `available_algorithms()` function:
```{r}
available_algorithms()
```
## Copyright
The icon for the hex sticker was made by Freepik from <flaticon.com>.