---
title: "Comparing Comorbidity Mappings"
author:
- Andrew Cooper (original)
- Jack Wasey (minor updates)
date: "March 1, 2018"
output: html_vignette
vignette: >
  %\VignetteIndexEntry{Comparing Comorbidity Mappings}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
  %\VignetteKeyword{comorbidity, comorbidities, biomedical informatics, administrative data, ICD-9, ICD-10, mapping, algorithm}
---
<!--
Copyright (C) 2014 - 2020  Jack O. Wasey

This file is part of icd.

icd is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

icd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with icd. If not, see <http:#www.gnu.org/licenses/>.
-->

```{r, include=FALSE}
library("icd")
```

When deciding which comorbidity mapping to use in research, it might be useful to compare mapping schemes. For instance, it would be useful to know which comorbidities a pair of mapping schemes share, and which comorbidities only exist in only one mapping scheme. For comorbidites that exist in both mapping schemes, how many ICD codes assigned to those comorbidities overlap? In other words, how similar are the mapping schemes structurally?

To answer these questions, we can use the function `diff_comorbid` in the "ICD" package. This function takes in two mapping schemes and outputs a comorbidity-by-comorbidity comparison of the two assignments. The function identifies comorbidities that are shared by both mapping schemes. It then takes each shared comorbidity and returns a list of codes that both mapping schemes assign to that comorbidity. The function returns a list of character lists, and condenses it into a summary of comparisons.

The following example demonstrates the comparison of two different mapping schemes. Say we were interested in comparing the mapping schemes of Elixhauser (1998) and Agency for Healthcare Research and Quality (AHRQ) in classifying ICD-9 codes. We can first use basic set operations to compare the comorbidity names.

```{r setup}
Elix_comor <- names(icd9_map_ahrq)
AHRQ_comor <- names(icd9_map_elix)
```

These comorbidities are shared:

```{r shared}
intersect(AHRQ_comor, Elix_comor)
```

These comorbidities are in AHRQ but not in the Elixhauser sets:

```{r in_ahrq}
setdiff(AHRQ_comor, Elix_comor)
```

Finally, these comorbidities are in Elixhauser but not in the AHRQ sets:

```{r in_elix}
setdiff(Elix_comor, AHRQ_comor)
```

We see that the comorbidity names are almost exactly the same except for Arrhythmia, which exists in the AHRQ mapping but not the Elixhauser mapping.

Now we run the function `diff_comorbid` and input the ICD-9 mappings from Elixhauser and AHRQ that are included in the package. The `all_names` option can be used if one wants to compare only a selection of comorbidities, in which case one can give a list of comorbidity names. By default, the function will compare all comorbiditi.introduces in both mapping schemes. Similarly, `x_names` and `y_names` can be used to specify the comorbidities to compare in the first and second mapping schemes, respectively. Setting the option `show` to `TRUE` tells the function to print out the comparison summary, and setting the option `explain` to `TRUE` tells the function to attempt to combine many low-level ICD codes to form just their parent codes for the output, which can be much more concise.

```{r comparison}
comp <- diff_comorbid(icd9_map_ahrq, icd9_map_elix,
                      show = TRUE, explain = TRUE)
```

The comparison summary provides the size of the asymmetric difference between mapping schemes for each shared comorbidity, along with a list of a few code descriptions in that difference. This summary doesn't provide a very detailed look at the similarities between comorbidity mappings. We can get a more detailed look at a particular comorbidity by specifying it.

```{r justCHF}
comp$CHF
```

In this example we look at the shared comorbidity Congestive Heart Failure (CHF). Note the list first gives us all the ICD codes that exist in both comorbidity mappings. Then it gives a list called `only.x`, followed by a list called `only.y`. `x` and `y` refer to the first and second mappings given to the function call. In this case, `x` refers to the AHRQ ICD-9 mapping, and `y` refers to the Elixhauser original 1998 ICD-9 mapping. So `only.x` lists all the ICD codes in the AHRQ comorbidity but not the Elixhauser comorbidity. Conversely, `only.y` lists all the ICD codes in the Elixhauser comorbidity but not in the AHRQ comorbidity, which in this case is none.

We can see from this comparison that the two mapping schemes are quite similar for this comorbidity. Most of the ICD codes exist in both mappings, and only a handful of mappings exist in the AHRQ mapping but not in the Elixhauser mapping. This makes sense since AHRQ was designed to update the original Elixhauser 1998 comorbidities, and has expanded the comorbidities in annual updates. This means any analysis of CHF that uses either Elixhauser or AHRQ should produce comparable results, since the comorbidity mappings are not wildly different.
