comorbidity

2018-01-06

AppVeyor Build Status Travis-CI Build Status Coverage Status CRAN_Status_Badge

comorbidity is an R package for computing comorbidity scores such as the weighted Charlson score and the Elixhauser comorbidity score, assuming ICD-10 diagnostic codes.

Installation

You can install comorbidity from GitHub with:

# install.packages("devtools")
devtools::install_github("ellessenne/comorbidity")

Simulating ICD-10 codes

With comorbidity it is possible to simulate ICD-10 diagnostic codes in a straightforward way:

# load the comorbidity package
library(comorbidity)
# set a seed for reproducibility
set.seed(1)
# simulate 50 codes for 5 individuals
x <- data.frame(
  id = sample(1:5, size = 50, replace = TRUE),
  code = sample_diag_icd10(n = 50),
  stringsAsFactors = FALSE
)
x <- x[order(x$id, x$code), ]
head(x, n = 15)
#>    id code
#> 38  1 C838
#> 12  1  H30
#> 34  1 I260
#> 24  1 I469
#> 10  1 K611
#> 47  1 L949
#> 27  1  V09
#> 5   2 B677
#> 19  2 C081
#> 14  2 I446
#> 28  2 K225
#> 25  2  M41
#> 1   2 M430
#> 22  2 T635
#> 2   2 U016

It is also possible to simulate from two different versions of the ICD-10 coding system. The default is to simulate from the 2011 version:

set.seed(1)
x1 <- data.frame(
  id = sample(1:3, size = 30, replace = TRUE),
  code = sample_diag_icd10(n = 30),
  stringsAsFactors = FALSE
)
set.seed(1)
x2 <- data.frame(
  id = sample(1:3, size = 30, replace = TRUE),
  code = sample_diag_icd10(n = 30, version = "2011"),
  stringsAsFactors = FALSE
)
# 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_icd10(n = 30, version = "2009"),
  stringsAsFactors = FALSE
)
set.seed(1)
x2 <- data.frame(
  id = sample(1:3, size = 30, replace = TRUE),
  code = sample_diag_icd10(n = 30, version = "2011"),
  stringsAsFactors = FALSE
)
# should not return TRUE
all.equal(x1, x2)
#> [1] "Component \"code\": 29 string mismatches"

Computing comorbidity scores

Say we have 3 individuals with a total of 30 diagnostic codes:

set.seed(1)
x <- data.frame(
  id = sample(1:3, size = 30, replace = TRUE),
  code = sample_diag_icd10(n = 30),
  stringsAsFactors = FALSE
)

We could compute the Charlson score, index, and each comorbidity domain:

charlson <- comorbidity(x = x, id = "id", code = "code", score = "charlson_icd10")
charlson
#>   id ami chf pvd cevd dementia copd rheumd pud mld diab diabwc hp rend
#> 1  1   0   0   0    0        0    0      0   0   1    0      0  0    0
#> 2  2   0   0   0    0        0    0      0   0   0    0      0  0    1
#> 3  3   0   0   0    0        0    0      0   0   0    0      0  0    0
#>   canc msld metacanc aids score index wscore windex
#> 1    0    0        0    0     1   1-2      1    1-2
#> 2    1    0        0    0     2   1-2      4    3-4
#> 3    0    0        0    0     0     0      0      0

Alternatively, we could compute the Elixhauser score:

elixhauser <- comorbidity(x = x, id = "id", code = "code", score = "elixhauser_icd10")
elixhauser
#>   id chf carit valv pcd pvd hypunc hypc para ond cpd diabunc diabc hypothy
#> 1  1   0     0    0   0   0      0    0    0   0   0       0     0       0
#> 2  2   0     0    0   0   0      0    0    0   0   0       0     0       0
#> 3  3   0     0    0   0   0      0    0    0   0   0       0     0       0
#>   rf ld pud aids lymph metacanc solidtum rheumd coag obes wloss fed blane
#> 1  0  1   0    0     0        0        0      0    0    0     0   0     0
#> 2  1  0   0    0     0        0        1      0    0    0     0   0     0
#> 3  0  0   0    0     0        0        0      0    0    0     0   0     0
#>   dane alcohol drug psycho depre score index wscore windex
#> 1    0       0    0      0     0     1   1-4     11    >=5
#> 2    0       0    0      0     0     2   1-4      9    >=5
#> 3    0       0    0      0     0     0     0      0      0

References

This package is based on the ICD-10-based formulations of the Charlson score and Elixhauser score proposed by Quan et al. in 2005. Weights for the Charlson score are based on the original formulation by Charlson et al. in 1987, while weights for the Elixhauser score are based on work by van Walraven et al. Finally, the categorisation of scores and weighted scores is based on work by Menendez et al.