Quick custom comorbidity maps are helpful

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Many problems with clinical data are best solved using the standard and widely validated comorbidities, mapped to subsets of ICD-9 or ICD-10 codes, as published by authors including Elixhauser, Quan, Deyo and the AHRQ. It is also common to have a pre-defined specific set of ICD codes. Examples of this include:

icd has a simple mechanism to use custom category-ICD maps. A comorbidity map is a list of character vectors. Each list must be named to reflect the ICD codes it contains; the character vector contains the ICD codes themselves.

Let's take a look at the first few items in the Charlson map from Quan and Deyo:

print(icd::icd10_map_quan_deyo, n_comorbidities = 3, n_codes = 8)

Obesity example

Now we can make our own comorbidity map, and apply it to a question on 'Stackoverflow'.

library(icd)
obesity_map <- list(
  "1" = "E663",
  "2" = c("E669", "E668", "E6609"),
  "3" = "E661",
  "4" = "E662")

obesity <- data.frame(
  ICD.10.Code = c("E6601", "E663", "E663", "E6609"),
  Encounter.ID = c("408773", "542207", "358741", "342534")
)

custom_map_result <- icd::icd10_comorbid(
  obesity,
  map = obesity_map)

custom_map_result

# finally, format as requested by the user
apply(custom_map_result, 1, function(x) {
  if (!any(x)) 4 else which(x)[1]
  })

# see also:
icd::icd10_map_ahrq$Obesity
icd::icd10_map_quan_elix$Obesity
icd::icd10_comorbid_quan_elix(
  obesity,
  return_df = TRUE)["Obesity"]

Maps with ranges of codes

Sometimes there are a large number of ICD codes, and they can be defined more succinctly with ranges, then by specifying every single code. In addition, as new codes are added to ICD-10-CM, (especially ICD-10-CM -- it moves much faster than ICD-10 from the WHO) having specific hard-coded ICD-10 codes will miss closely related codes in the future. Using the ranges functions from icd helps with both these problems.

Again, using a Stackoverflow question:

library(icd)
diagnoses <- c("C349", "A219", "B003", "C509", "B700", "A090")
one_pt <- data.frame(id = rep("patient1", length(diagnoses)),
                     diagnoses)
dif_pt <- data.frame(id = paste0("patient", seq_along(diagnoses)),
                     diagnoses)
my_map <- list(c01to17 = expand_range("C01", "C17"),
               a74to75 = expand_range("A748", "A759"),
               b00to33 = expand_range("B001", "B331"),
               b69to72 = expand_range("B69", "B72"),
               c00to94 = expand_range("C000", "C942"))
# optionally use as.comorbidity_map which ensures it is valid, and let's it
# print more pleasantly
my_map <- as.comorbidity_map(my_map)
print(my_map)
icd::comorbid(one_pt, map = my_map)
(six_pts_cmb <- icd::comorbid(dif_pt, map = my_map))
{
  image(t(six_pts_cmb),
        col = c("light blue", "blue"),
        xlab = "Custom disease ranges",
        axes = FALSE
  )
  axis(1,
       at = seq(0, 1, length.out = length(my_map)),
       labels = names(my_map),
       lwd = 0
  )
  axis(2,
       at = seq(0, 1, length.out = nrow(dif_pt)),
       labels = dif_pt$id,
       lwd = 0,
       las = 2
  )
}


Try the icd package in your browser

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

icd documentation built on July 2, 2020, 4:07 a.m.