Elixhauser Comorbidities

library(medicalcoder)
packageVersion("medicalcoder")
## [1] '0.6.0'

Introduction

The medicalcoder package implements several variants of the Elixhauser comorbidity algorithm.

IMPORTANT NOTE: Elixhauser 1998 and AHRQ Web used diagnostic related group (DRG) codes as part of the methods. The medicalcoder package does not use DRG codes. This is consistent with the way these methods were implemented in Quan et al. (2005).

ICD Codes and Index Scores

End users may access three lookup tables relevant to Elixhauser variants.

str(get_elixhauser_codes())
## 'data.frame':    10679 obs. of  12 variables:
##  $ icdv                     : int  9 9 9 9 9 9 9 9 9 9 ...
##  $ dx                       : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ full_code                : chr  "042" "070.22" "070.23" "070.32" ...
##  $ code                     : chr  "042" "07022" "07023" "07032" ...
##  $ condition                : chr  "AIDS" "LIVER" "LIVER" "LIVER" ...
##  $ elixhauser_ahrq_web      : int  1 1 1 1 1 1 1 0 0 0 ...
##  $ elixhauser_elixhauser1988: int  1 0 0 1 1 0 1 0 0 0 ...
##  $ elixhauser_quan2005      : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ elixhauser_ahrq2022      : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ elixhauser_ahrq2023      : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ elixhauser_ahrq2024      : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ elixhauser_ahrq2025      : int  NA NA NA NA NA NA NA NA NA NA ...
str(get_elixhauser_index_scores())
## 'data.frame':    112 obs. of  9 variables:
##  $ condition                : chr  "AIDS" "AIDS" "ALCOHOL" "ALCOHOL" ...
##  $ index                    : chr  "mortality" "readmission" "mortality" "readmission" ...
##  $ elixhauser_ahrq_web      : int  0 19 -1 6 -2 9 0 4 NA NA ...
##  $ elixhauser_elixhauser1988: int  0 19 -1 6 -2 9 0 4 NA NA ...
##  $ elixhauser_quan2005      : int  0 19 -1 6 -2 9 0 4 NA NA ...
##  $ elixhauser_ahrq2022      : int  -4 5 -1 3 -3 5 NA NA -1 2 ...
##  $ elixhauser_ahrq2023      : int  -4 5 -1 3 -3 5 NA NA 0 2 ...
##  $ elixhauser_ahrq2024      : int  -4 5 -1 3 -3 5 NA NA 0 2 ...
##  $ elixhauser_ahrq2025      : int  -4 5 -1 3 -3 5 NA NA 0 2 ...
str(get_elixhauser_poa())
## 'data.frame':    43 obs. of  7 variables:
##  $ condition          : chr  "AIDS" "ALCOHOL" "ANEMDEF" "ANEMDEF" ...
##  $ desc               : chr  "Acquired immune deficiency syndrome" "Alcohol abuse" "Anemias due to other nutritional deficiencies" "Deficiency anemias" ...
##  $ poa_required       : int  0 0 1 1 0 1 1 0 0 0 ...
##  $ elixhauser_ahrq2022: int  1 1 NA 1 1 NA 1 1 1 1 ...
##  $ elixhauser_ahrq2023: int  1 1 1 NA 1 1 NA 1 1 1 ...
##  $ elixhauser_ahrq2024: int  1 1 1 NA 1 1 NA 1 1 1 ...
##  $ elixhauser_ahrq2025: int  1 1 1 NA 1 1 NA 1 1 1 ...

Applying Elixhauser

The Elixhauser method considers if the diagnostic codes are for primary or secondary diagnoses. As such, the following call will throw a warning that the primarydx.var or primarydx argument was not set and that all conditions will be assumed to be secondary. To suppress this warning pass an appropriate value for either argument.

# will warn because primarydx and primarydx.var are both NULL
mdcr_results0 <-
  comorbidities(
    data = mdcr,
    id.vars = "patid",
    icdv.var = "icdv",
    icd.codes = "code",
    dx.var = "dx",
    flag.method = "current",
    poa = 1,
    method = "elixhauser_ahrq2025"
  )
## Warning: Assuming all codes provided are secondary diagnostic codes.  Define
## `primarydx.var` or `primarydx` if this assumption is incorrect.

# no warning
mdcr_results <-
  comorbidities(
    data = mdcr,
    id.vars = "patid",
    icdv.var = "icdv",
    icd.codes = "code",
    dx.var = "dx",
    flag.method = "current",
    poa = 1,
    method = "elixhauser_ahrq2025",
    primarydx = 0
  )

identical(mdcr_results, mdcr_results0)
## [1] TRUE

The return object is a data.frame with 0/1 integer indicator columns for the relevant conditions, the id.vars (if applicable), num_cmrb the number of comorbidities, cmrb_flag a 0/1 indicator for presence of at least one comorbidity, and the mortality and readmission index scores.

str(mdcr_results)
## Classes 'medicalcoder_comorbidities' and 'data.frame':   38262 obs. of  43 variables:
##  $ patid            : int  10000 10002 10005 10006 10008 10010 10014 10015 10017 10018 ...
##  $ AIDS             : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ ALCOHOL          : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ ANEMDEF          : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ AUTOIMMUNE       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ BLDLOSS          : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ CANCER_LEUK      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ CANCER_LYMPH     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ CANCER_METS      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ CANCER_NSITU     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ CANCER_SOLID     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ CBVD             : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ COAG             : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ DEMENTIA         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ DEPRESS          : int  0 1 0 0 0 0 0 0 0 1 ...
##  $ DIAB_CX          : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ DIAB_UNCX        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ DRUG_ABUSE       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ HF               : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ HTN_CX           : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ HTN_UNCX         : int  0 0 0 0 0 0 1 0 0 0 ...
##  $ LIVER_MLD        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ LIVER_SEV        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ LUNG_CHRONIC     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ NEURO_MOVT       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ NEURO_OTH        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ NEURO_SEIZ       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ OBESE            : int  0 1 0 0 0 0 0 0 0 0 ...
##  $ PARALYSIS        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ PERIVASC         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ PSYCHOSES        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ PULMCIRC         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ RENLFL_MOD       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ RENLFL_SEV       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ THYROID_HYPO     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ THYROID_OTH      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ ULCER_PEPTIC     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ VALVE            : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ WGHTLOSS         : int  0 0 0 0 0 0 1 0 0 0 ...
##  $ num_cmrb         : int  0 2 0 0 0 0 2 0 0 1 ...
##  $ cmrb_flag        : int  0 1 0 0 0 0 1 0 0 1 ...
##  $ mortality_index  : int  0 -15 0 0 0 0 13 0 0 -8 ...
##  $ readmission_index: int  0 0 0 0 0 0 6 0 0 2 ...
##  - attr(*, "method")= chr "elixhauser_ahrq2025"
##  - attr(*, "id.vars")= chr "patid"
##  - attr(*, "flag.method")= chr "current"

Call summary() to get a list of summaries which can be used to generate summary tables.

summary(mdcr_results)
## $conditions
##       condition count      percent
## 1          AIDS     3  0.007840677
## 2       ALCOHOL    11  0.028749151
## 3       ANEMDEF   700  1.829491401
## 4    AUTOIMMUNE   170  0.444305055
## 5       BLDLOSS    33  0.086247452
## 6   CANCER_LEUK   381  0.995766034
## 7  CANCER_LYMPH    76  0.198630495
## 8   CANCER_METS   213  0.556688098
## 9  CANCER_NSITU     0  0.000000000
## 10 CANCER_SOLID   609  1.591657519
## 11         CBVD     0  0.000000000
## 12         COAG   877  2.292091370
## 13     DEMENTIA    35  0.091474570
## 14      DEPRESS   321  0.838952485
## 15      DIAB_CX   123  0.321467775
## 16    DIAB_UNCX   193  0.504416915
## 17   DRUG_ABUSE    77  0.201244054
## 18           HF   246  0.642935550
## 19       HTN_CX   286  0.747477915
## 20     HTN_UNCX   406  1.061105013
## 21    LIVER_MLD   206  0.538393184
## 22    LIVER_SEV   159  0.415555904
## 23 LUNG_CHRONIC  1359  3.551826878
## 24   NEURO_MOVT   139  0.363284721
## 25    NEURO_OTH   948  2.477654069
## 26   NEURO_SEIZ  1490  3.894203126
## 27        OBESE   315  0.823271131
## 28    PARALYSIS   767  2.004599864
## 29     PERIVASC   209  0.546233861
## 30    PSYCHOSES    96  0.250901678
## 31     PULMCIRC   332  0.867701636
## 32   RENLFL_MOD   112  0.292718624
## 33   RENLFL_SEV   247  0.645549109
## 34 THYROID_HYPO   371  0.969630443
## 35  THYROID_OTH    36  0.094088129
## 36 ULCER_PEPTIC    23  0.060111860
## 37        VALVE   572  1.494955831
## 38     WGHTLOSS   616  1.609952433
## 39         >= 1  7850 20.516439287
## 40         >= 2  3230  8.441796038
## 41         >= 3  1171  3.060477759
## 42         >= 4   357  0.933040615
## 43         >= 5   116  0.303172861
## 44         >= 6    27  0.070566097
## 45         >= 7     4  0.010454237
## 46         >= 8     2  0.005227118
## 
## $index_summary
##         index min q1 median q3 max
## 1 readmission  -2  0      0  0  42
## 2   mortality -24  0      0  0  85
x <- summary(mdcr_results)$conditions
tab <-
  kableExtra::kbl(
    x = x,
    format = "html",
    caption = "Counts and percentages of patients in the mdcr example data sets with the Elixhauser @quan2005 comorbidities.",
    col.names = c("", "Count", "Percentage"),
    digits = 3
  )
tab <- kableExtra::pack_rows(tab, group_label = "Comorbidity", start_row = 1, end_row = 39)
tab <- kableExtra::pack_rows(tab, group_label = "Total Comorbidities", start_row = 39, end_row = nrow(x))
tab
Counts and percentages of patients in the mdcr example data sets with the Elixhauser Quan et al. (2005) comorbidities.
Count Percentage
Comorbidity
AIDS 3 0.008
ALCOHOL 11 0.029
ANEMDEF 700 1.829
AUTOIMMUNE 170 0.444
BLDLOSS 33 0.086
CANCER_LEUK 381 0.996
CANCER_LYMPH 76 0.199
CANCER_METS 213 0.557
CANCER_NSITU 0 0.000
CANCER_SOLID 609 1.592
CBVD 0 0.000
COAG 877 2.292
DEMENTIA 35 0.091
DEPRESS 321 0.839
DIAB_CX 123 0.321
DIAB_UNCX 193 0.504
DRUG_ABUSE 77 0.201
HF 246 0.643
HTN_CX 286 0.747
HTN_UNCX 406 1.061
LIVER_MLD 206 0.538
LIVER_SEV 159 0.416
LUNG_CHRONIC 1359 3.552
NEURO_MOVT 139 0.363
NEURO_OTH 948 2.478
NEURO_SEIZ 1490 3.894
OBESE 315 0.823
PARALYSIS 767 2.005
PERIVASC 209 0.546
PSYCHOSES 96 0.251
PULMCIRC 332 0.868
RENLFL_MOD 112 0.293
RENLFL_SEV 247 0.646
THYROID_HYPO 371 0.970
THYROID_OTH 36 0.094
ULCER_PEPTIC 23 0.060
VALVE 572 1.495
WGHTLOSS 616 1.610
Total Comorbidities
>= 1 7850 20.516
>= 2 3230 8.442
>= 3 1171 3.060
>= 4 357 0.933
>= 5 116 0.303
>= 6 27 0.071
>= 7 4 0.010
>= 8 2 0.005

References

Cost, Healthcare, and Utilization Project (HCUP). 2017. “Elixhauser Comorbidity Software for ICD-9-CM.” https://hcup-us.ahrq.gov/toolssoftware/comorbidity/comorbidity.jsp.
Elixhauser, Anne, Claudia Steiner, D Robert Harris, and Rosanna M Coffey. 1998. “Comorbidity Measures for Use with Administrative Data.” Medical Care 36 (1): 8–27. https://doi.org/10.1097/00005650-199801000-00004.
Healthcare Research, Agency for, and Quality (AHRQ). 2025. “Elixhauser Comorbidity Software Refined for ICD-10-CM Healthcare Cost and Utilization Project (HCUP).” https://hcup-us.ahrq.gov/toolssoftware/comorbidityicd10/comorbidity_icd10.jsp.
Quan, Hude, Vijaya Sundararajan, Patricia Halfon, Andrew Fong, Bernard Burnand, Jean-Christophe Luthi, L Duncan Saunders, Catherine A. Beck, Thomas E. Feasby, and William A. Ghali. 2005. “Coding Algorithms for Defining Comorbidities in ICD-9-CM and ICD-10 Administrative Data.” Medical Care 43 (11): 1130–39. https://doi.org/10.1097/01.mlr.0000182534.19832.83.