knitr::opts_chunk$set( collapse = TRUE ) options(width = 100)
Last updated: r Sys.time()
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.
comorbidity
is on CRAN. You can install it as usual with:
install.packages("comorbidity")
Alternatively, you can install the development version from GitHub with:
# install.packages("remotes") remotes::install_github("ellessenne/comorbidity")
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:
# 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:
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:
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)
ICD-9 codes can be easily simulated too:
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)
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:
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:
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:
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:
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:
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:
charlson9 <- comorbidity(x = x, id = "id", code = "code", map = "charlson_icd9_quan", assign0 = FALSE) charlson9
elixhauser9 <- comorbidity(x = x, id = "id", code = "code", map = "elixhauser_icd9_quan", assign0 = FALSE) elixhauser9
Scores:
unw_eci <- score(elixhauser9, weights = NULL, assign0 = FALSE) vw_eci <- score(elixhauser9, weights = "vw", assign0 = FALSE) all.equal(unw_eci, vw_eci)
If you find comorbidity
useful, please cite it in your publications:
citation("comorbidity")
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:
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:
available_algorithms()
The icon for the hex sticker was made by Freepik from
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.