ICD code scoring systems

A common use of ICD codes is calculation as a Charlson score, which gives a measure of how well a patient is, albeit based on the limited available in admission and discharge diagnoses. The Charlson scoring system attributes scores based on presence of diseases falling into any of the Charlson comorbidities. Quan updated the scores given to each comorbidity to better reflect morbidity and mortality in a more recent population. Van Walraven provides a similar scoring methodology for the Elixhauser comorbidities (as used by the US AHRQ).

More complicated scoring systems may use lab values, patient demographic information, and so on. Any contributions to this package for calculations of scoring systems based on comorbidities and other data would be welcome.

Vermont example data, Charlson scores

The Vermont data are actually discharge, not admission diagnoses, but can be used to demonstrate generating Charlson scores.

# typical hospital format data, with many columns for diagnoses
head(vermont_dx)
#>   visit_id   age_group    sex death DRG   DX1   DX2   DX3   DX4   DX5
#> 1        7       40-44   male  TRUE 640 27801 03842 51881 41519 99591
#> 2       10 75 and over female FALSE 470 71526 25000 42830  4280  4019
#> 3       13 75 and over female FALSE 470 71535 59651 78052 27800 V8537
#> 4       16       55-59 female FALSE 470 71535 49390 53081 27800  V140
#> 5       37       70-74   male FALSE 462 71536  4241  2859  2720  4414
#> 6       41       70-74   male FALSE 462 71536 V1259 V1582  V160  V171
#>     DX6   DX7   DX8   DX9  DX10  DX11  DX12  DX13 DX14 DX15  DX16 DX17
#> 1 42842  5849  5609  6826  5853 42731 42732 25542 1533 5693 45340 6822
#> 2  4241   311 49390  2724 73300 41401                                 
#> 3   311  4019 53081 56400                                             
#> 4  V141  V142  V160 V8538                                             
#> 5 53081 V5866                                                         
#> 6                                                                     
#>    DX18  DX19 DX20
#> 1 70712 27803 2767
#> 2                 
#> 3                 
#> 4                 
#> 5                 
#> 6
# convert to long format (could use other tools, but the icd version accounts better for known structure of the data.
head(vermont_dx %>% icd_wide_to_long)
#>   visit_id age_group  sex death DRG icd_code
#> 1        7     40-44 male  TRUE 640    27801
#> 2        7     40-44 male  TRUE 640    03842
#> 3        7     40-44 male  TRUE 640    51881
#> 4        7     40-44 male  TRUE 640    41519
#> 5        7     40-44 male  TRUE 640    99591
#> 6        7     40-44 male  TRUE 640    42842
# calculate charlson scores and summarize
vermont_dx %>% icd_wide_to_long %>% icd_charlson %>% summary
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>   0.000   0.000   1.000   1.573   2.000   9.000
# show the first few actual scores: the names are the patient IDs:
vermont_dx %>% icd_wide_to_long %>% icd_charlson %>% head(25) -> vermont_charlson
vermont_charlson
#>   7  10  13  16  37  41  42  52  68  70  74  78  81  87 120 136 159 167 
#>   5   3   0   1   1   0   0   0   0   0   0   1   2   0   4   0   0   1 
#> 168 169 188 242 299 316 321 
#>   0   0   0   0   1   0   0
names(vermont_charlson)
#>  [1] "7"   "10"  "13"  "16"  "37"  "41"  "42"  "52"  "68"  "70"  "74" 
#> [12] "78"  "81"  "87"  "120" "136" "159" "167" "168" "169" "188" "242"
#> [23] "299" "316" "321"
unname(vermont_charlson)
#>  [1] 5 3 0 1 1 0 0 0 0 0 0 1 2 0 4 0 0 1 0 0 0 0 1 0 0

Behind the scenes, icd calculates the Charlson comorbidities for those ICD codes, applies the Charlson scoring system, and returns the Charlson score for each patient.

Vermont example data, Van Walraven scores

The same principle can be used to calculate the Van Walraven score, which is the Charlson score counterpart for Elixhauser comorbidities.

vermont_dx %>% icd_wide_to_long %>% icd_van_walraven %>% head(25)