MyNixOS website logo
Description

Computing Comorbidity Scores.

Computing comorbidity indices and scores such as the weighted Charlson score (Charlson, 1987 <doi:10.1016/0021-9681(87)90171-8>) and the Elixhauser comorbidity score (Elixhauser, 1998 <doi:10.1097/00005650-199801000-00004>) using ICD-9-CM or ICD-10 codes (Quan, 2005 <doi:10.1097/01.mlr.0000182534.19832.83>). Australian and Swedish modifications of the Charlson Comorbidity Index are available as well (Sundararajan, 2004 <doi:10.1016/j.jclinepi.2004.03.012> and Ludvigsson, 2021 <doi:10.2147/CLEP.S282475>), together with different weighting algorithms for both the Charlson and Elixhauser comorbidity scores.

The {comorbidity} Package: Computing Comorbidity Scores in R Hex sticker of the {comorbidity} R package.

Last updated: 2024-07-13 21:12:35.086616

R-CMD-check Codecov testcoverage CRAN_Status_Badge CRAN_Logs_Badge CRAN_Logs_Badge_Total JOSSDOI PRsWelcome

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:

install.packages("comorbidity")

Alternatively, you can install the development version from GitHub with:

# 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:

# 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)
##  id code
##   1  B02
##   1 B582
##   1 I749
##   1 J450
##   1 L893
##   1 Q113
##   1  Q26
##   1 Q978
##   1 T224
##   1 V101
##   1 V244
##   1  V46
##   2 A665
##   2 C843
##   2 D838

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)
## [1] TRUE

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)
## [1] "Component \"code\": 30 string mismatches"

Simulating ICD-9 codes

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)
##  id  code
##   1 01130
##   1 01780
##   1 30151
##   1  3073
##   1 36907
##   1 37845
##   1 64212
##   1 66704
##   1 72633
##   1  9689
##   1  V289
##   2  0502
##   2 09169
##   2 20046
##   2 25082

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:

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
##   id mi chf pvd cevd dementia cpd rheumd pud mld diab diabwc hp rend canc msld metacanc aids
## 1  1  0   0   0    0        0   0      0   0   0    0      0  0    0    1    0        0    1
## 2  2  0   0   0    0        0   0      0   0   0    0      0  0    0    1    0        0    0
## 3  3  0   0   0    0        0   0      0   0   0    0      0  0    0    0    0        0    0

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
##   id chf carit valv pcd pvd hypunc hypc para ond cpd diabunc diabc hypothy rf ld pud aids lymph
## 1  1   0     0    0   0   0      0    0    0   0   0       0     0       0  0  0   0    1     0
## 2  2   0     0    1   0   0      0    0    0   0   0       0     0       0  0  0   0    0     0
## 3  3   0     0    0   0   0      0    0    0   1   0       0     0       0  0  0   0    0     0
##   metacanc solidtum rheumd coag obes wloss fed blane dane alcohol drug psycho depre
## 1        0        1      0    0    0     0   0     0    0       0    0      0     0
## 2        0        1      0    0    0     0   0     0    0       0    0      0     0
## 3        0        0      0    0    0     0   0     0    0       0    0      0     0

Weighted an unweighted comorbidity scores can be obtained using the score() function:

unw_cci <- score(charlson, weights = NULL, assign0 = FALSE)
unw_cci
## [1] 2 1 0
## attr(,"map")
## [1] "charlson_icd10_quan"

quan_cci <- score(charlson, weights = "quan", assign0 = FALSE)
quan_cci
## [1] 6 2 0
## attr(,"map")
## [1] "charlson_icd10_quan"
## attr(,"weights")
## [1] "quan"

all.equal(unw_cci, quan_cci)
## [1] "Attributes: < Length mismatch: comparison on first 1 components >"
## [2] "Mean relative difference: 1.666667"

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
##   id mi chf pvd cevd dementia cpd rheumd pud mld diab diabwc hp rend canc msld metacanc aids
## 1  1  0   0   1    0        0   0      0   0   0    0      0  0    0    1    0        0    0
## 2  2  0   0   0    1        0   0      0   0   0    0      0  0    0    0    0        0    0
## 3  3  0   0   0    0        0   0      0   1   0    0      0  0    0    0    0        0    0
## 4  4  0   0   1    1        0   0      0   0   0    0      0  0    0    1    0        0    0
## 5  5  0   0   0    0        0   0      0   0   0    0      0  0    0    1    0        0    0
elixhauser9 <- comorbidity(x = x, id = "id", code = "code", map = "elixhauser_icd9_quan", assign0 = FALSE)
elixhauser9
##   id chf carit valv pcd pvd hypunc hypc para ond cpd diabunc diabc hypothy rf ld pud aids lymph
## 1  1   0     0    0   0   1      0    0    0   0   0       0     0       0  0  0   0    0     0
## 2  2   0     0    0   0   0      0    0    0   1   0       0     0       0  0  0   0    0     0
## 3  3   0     0    0   0   0      0    0    0   0   0       0     0       0  0  0   0    0     0
## 4  4   0     0    0   1   1      0    0    0   0   0       0     0       0  0  0   0    0     0
## 5  5   0     0    0   0   0      0    0    0   0   0       0     0       0  0  0   0    0     0
##   metacanc solidtum rheumd coag obes wloss fed blane dane alcohol drug psycho depre
## 1        0        0      0    0    0     0   0     0    0       0    0      0     0
## 2        0        0      0    0    0     0   0     0    0       0    0      0     0
## 3        0        0      0    0    0     0   0     0    0       0    0      1     0
## 4        0        0      0    0    0     0   0     0    0       0    0      0     0
## 5        0        0      1    0    0     0   0     0    0       0    0      0     0

Scores:

unw_eci <- score(elixhauser9, weights = NULL, assign0 = FALSE)
vw_eci <- score(elixhauser9, weights = "vw", assign0 = FALSE)
all.equal(unw_eci, vw_eci)
## [1] "Attributes: < Length mismatch: comparison on first 1 components >"
## [2] "Mean relative difference: 2"

Citation

If you find comorbidity useful, please cite it in your publications:

citation("comorbidity")
## To cite package 'comorbidity' in publications use:
## 
##   Gasparini, (2018). comorbidity: An R package for computing comorbidity scores. Journal
##   of Open Source Software, 3(23), 648, https://doi.org/10.21105/joss.00648
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     author = {Alessandro Gasparini},
##     title = {comorbidity: An R package for computing comorbidity scores},
##     journal = {Journal of Open Source Software},
##     year = {2018},
##     volume = {3},
##     issue = {23},
##     pages = {648},
##     doi = {10.21105/joss.00648},
##     url = {https://doi.org/10.21105/joss.00648},
##   }

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:

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()
## Supported comorbidity mapping algorithms:
##  * charlson_icd9_quan 
##  * charlson_icd10_quan 
##  * charlson_icd10_se 
##  * charlson_icd10_am 
##  * charlson_icd10_am_ucodes 
##  * elixhauser_icd9_quan 
##  * elixhauser_icd10_quan 
## 
## Supported scoring weights algorithms:
##  * For charlson_icd9_quan: charlson, quan 
##  * For charlson_icd10_quan: charlson, quan 
##  * For charlson_icd10_se: charlson, quan 
##  * For charlson_icd10_am: charlson, quan 
##  * For charlson_icd10_am_ucodes: charlson, quan 
##  * For elixhauser_icd9_quan: vw, swiss 
##  * For elixhauser_icd10_quan: vw, swiss

Copyright

The icon for the hex sticker was made by Freepik from \\.

Metadata

Version

1.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows