ICD-10 comorbidities

    loadNamespace("knitr") # for opts_chunk only
  collapse = TRUE,
  comment = "#>"


The icd package for R includes ICD-10-CM definitions, sample ICD-10-CM data, and very fast comorbidity calculations from ICD-10 diagnostic and procedure codes (and ICD-9, or other schemes) to the standard comorbidities defined in the literature following Charlson [@charlson_new_1987], Quan, Deyo [@quan_coding_2005], Elixhauser [@elixhauser_comorbidity_1998], pediatric complex chronic conditions [@Feudtner_Pediatriccomplexchronic_2014] and the US AHRQ [@AgencyforHealthcareResearchandQuality_Elixhausercomorbiditysoftware_2018]. There are also 2018 ICD-10-CM procedure codes, and a mapping to categorize these. The sample data are from the US Transuranium and Uranium Registries where deidentified diagnoses are given for a few hundred pathology cases relating to uranium exposure.

The sample data is in the 'long' format, i.e., multiple rows per case.

uranium_pathology[1:10, ]

Pick a code, and see what it means.


We can convert the date from long to wide format easily, accounting for the most common features of medical coding data. You may be happier using \pkg{dplyr} and friends for this manipulation, and you will find that 'icd' functions work well with \pkg{magrittr} and the 'tidyverse' packages, although none are used internally.

uranium_pathology %>% long_to_wide %>% head

Now map these diagnoses to disease groups as defined by Quan et al:

quan_comorbidities <- comorbid(uranium_pathology, icd10_map_quan_elix)
# see the first few rows and columns:
quan_comorbidities[1:6, 3:10]

The ICD-10-CM mappings are recorded a bit differently from the ICD-9-CM mappings in this package. The ICD-9 mappings included all possible permutations of child codes. Since ICD-10 codes contain letters, and are seven characters long, this became impractical. Therefore, the current mappings include only codes for the most recent update of ICD-10-CM. The code which assigns comorbidities for ICD-10 therefore doesn't rely on all the possible codes being listed in the mappings, so it will (more slowly) search for each possible parent of the given code, up to the three digit 'major' (e.g. if Cholera was in the comorbidity mapping, then A0034212647 would eventually match A00)

# create trivial comorbidity map:
cholera_typhoid_map <- list(cholera = "A00", typhoid = "A01")
patients <- data.frame(patient = c("0001", "0001", "0002"), 
                       code = c("A001234567", "A01", "A019"))
comorbid(patients , map = cholera_typhoid_map)

Here are the codes for hypertension with complications from Quan et al. Note that the vector has class icd10 and has the attribute icd_short_diag indicating there are no decimal point delimiters in the codes.


Procedure codes

The AHRQ publishes an annually updated categorization of ICD-10-CM procedure codes into four classes, representing diagnostic and therapeutic procedures, each being either minor or major.

pts <- data.frame(id = sample(LETTERS, 10),
                  pc = sample(icd10_pcs[["2018"]]$code, 10))
res <- icd10_comorbid(pts,
                      map = icd10_map_ahrq_pcs, 
                      icd_name = "pc",
                      return_binary = TRUE)

For more information on working with ICD-10 codes, see the introduction vignette, and function examples. E.g.



Try the icd package in your browser

Any scripts or data that you put into this service are public.

icd documentation built on Nov. 19, 2018, 1:05 a.m.