This is the main function which extracts comorbidities from a set of ICD-9
codes. Some comorbidity schemes have rules, for example, what to do when both
'hypertension' and 'hypertension with complications' are present. These rules
are applied by default; if the exact fields from the original mappings are
needed, use hierarchy = FALSE
. For comorbidity counting, Charlson or
Van Walraven scores the default should be used to apply the rules. For more
about computing Hierarchical Condition Codes (HCC), see
comorbid_hcc
For more about comorbidities following the
Clinical Classification Software (CCS) rules from AHRQ, see
comorbid_ccs
.
comorbid( x, map, visit_name = NULL, icd_name = NULL, short_code = guess_short(x, icd_name = icd_name), short_map = guess_short(map), return_df = FALSE, return_binary = FALSE, categorize_fun = categorize_simple, ... ) icd10_comorbid( x, map, visit_name = NULL, icd_name = NULL, short_code = NULL, short_map = guess_short(map), return_df = FALSE, return_binary = FALSE, icd10_comorbid_fun = icd10_comorbid_reduce, ... ) icd9_comorbid( x, map, visit_name = NULL, icd_name = NULL, short_code = guess_short(x, icd_name = icd_name), short_map = guess_short(map), return_df = FALSE, return_binary = FALSE, preclean = FALSE, categorize_fun = categorize_simple, comorbid_fun = comorbid_mat_mul_wide, ... ) icd9_comorbid_ahrq(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd10_comorbid_ahrq(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd9_comorbid_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd10_comorbid_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd9_comorbid_quan_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd10_comorbid_quan_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd9_comorbid_quan_deyo(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd10_comorbid_quan_deyo(x, ..., abbrev_names = TRUE, hierarchy = TRUE) icd9_comorbid_charlson(...) icd10_comorbid_charlson(...) comorbid_ccs(x, icd_name = get_icd_name(x), ...) icd9_comorbid_ccs( x, ..., single = TRUE, lvl = NULL, map = icd::icd9_map_single_ccs, short_map = TRUE ) icd10_comorbid_ccs(x, ..., single = TRUE, lvl = NULL) comorbid_ahrq(x, ...) comorbid_elix(x, ...) comorbid_quan_elix(x, ...) comorbid_quan_deyo(x, ...) comorbid_charlson(...) comorbid_pccc_dx( x, visit_name = get_visit_name(x), icd_name = get_icd_name(x), short_code = guess_short(x, icd_name = icd_name), return_df = FALSE, return_binary = FALSE, ... ) comorbid_pccc_pcs( x, visit_name = get_visit_name(x), icd_name, return_df = FALSE, return_binary = FALSE, ... ) icd9_comorbid_pccc_dx( x, visit_name = NULL, icd_name = NULL, short_code = guess_short(x, icd_name = icd_name), return_df = FALSE, return_binary = FALSE, ..., abbrev_names = TRUE ) icd10_comorbid_pccc_dx( x, visit_name = NULL, icd_name = NULL, short_code = guess_short(x, icd_name = icd_name), return_df = FALSE, return_binary = FALSE, ..., abbrev_names = TRUE ) icd9_comorbid_pccc_pcs( x, visit_name = get_visit_name(x), icd_name = get_icd_pc_name(x), return_df = FALSE, return_binary = FALSE, ..., abbrev_names = TRUE ) icd10_comorbid_pccc_pcs( x, visit_name = get_visit_name(x), icd_name, return_df = FALSE, return_binary = FALSE, ..., abbrev_names = TRUE )
x |
|
---|---|
map | A named list of the comorbidities with each list item containing a
vector of decimal ICD-9 codes. icd includes a number of these, e.g.,
|
visit_name | The name of the column in the data frame which contains the
patient or visit identifier. Typically this is the visit identifier, since
patients come leave and enter hospital with different ICD-9 codes. It is a
character vector of length one. If left empty, or |
icd_name | The name of the column in the |
short_code | single logical value which determines whether the ICD-9
code provided is in short ( |
short_map | Same as short, but applied to |
return_df | single logical value, if |
return_binary | Single logical value, if |
categorize_fun | Internal. Function used for the categorization problem. |
... | Arguments passed through to |
icd10_comorbid_fun | Internal function Default will be fast and accurate. A function which calculates comorbidities for ICD-10 codes, in which the comorbidity map only specifies parent codes, not every possible child. |
preclean | single logical value, which, if |
comorbid_fun | Internal. Function used inside categorization. |
abbrev_names | single logical value that defaults to |
hierarchy | single logical value that defaults to |
single | a logical value, if |
lvl | If multiple level CCS, then level must be selected as a number between one and four. |
The order of visits may change depending on the original sequence,
and the underlying algorithm used. Usually this would be the order of the
first occurrence of each visit/patient identifier, but this is not
guaranteed unless restore_id_order
is set to TRUE
.
data.frame
s of patient data may have columns within them
which are of class icd9
, icd10
etc., but do not themselves
have a class: therefore, the S3 mechanism for dispatch is not suitable. I
may add a wrapper function which looks inside a data.frame
of
comorbidities, and dispatches to the appropriate function, but right now
the user must call the icd9_
or icd10_
prefixed function
directly.
icd10_comorbid
: ICD-10 comorbidities
icd9_comorbid
: Get comorbidities from data.frame
of ICD-9
codes
icd9_comorbid_ahrq
: AHRQ comorbidities for ICD-9 codes
icd10_comorbid_ahrq
: AHRQ comorbidities for ICD-10 codes
icd9_comorbid_elix
: Elixhauser comorbidities for ICD-9 codes
icd10_comorbid_elix
: Elixhauser comorbidities for ICD-10 codes
icd9_comorbid_quan_elix
: Quan's Elixhauser comorbidities for ICD-9 codes
icd10_comorbid_quan_elix
: Quan's Elixhauser comorbidities for ICD-10 codes
icd9_comorbid_quan_deyo
: Quan's Deyo (Charlson) comorbidities for ICD-9 codes
icd10_comorbid_quan_deyo
: Quan's Deyo (Charlson) comorbidities for ICD-10 codes
icd9_comorbid_charlson
: Currently synonym for icd9_comorbid_quan_deyo
icd10_comorbid_charlson
: Currently synonym for icd10_comorbid_quan_deyo
comorbid_ccs
: Use AHRQ CCS for comorbidity classification
icd9_comorbid_ccs
: Compute AHRQ Clinical Classifications Software (CCS)
scores from ICD-9 codes
icd10_comorbid_ccs
: Compute AHRQ Clinical Classifications Software (CCS)
scores from ICD-10 codes
comorbid_ahrq
: AHRQ comorbidities, infers whether to use ICD-9 or
ICD-10 codes
comorbid_elix
: Elixhauser comorbidities, infers whether to use ICD-9 or
ICD-10 codes
comorbid_quan_elix
: Quan's Elixhauser comorbidities, infers whether to use
ICD-9 or ICD-10 codes
comorbid_quan_deyo
: Quan's Deyo (Charlson) comorbidities, infers whether to
use ICD-9 or ICD-10 codes
comorbid_charlson
: Calculate comorbidities using Charlson categories
according to Quan/Deyo ICD categories. Synonymous with
link{comorbid_quan_deyo}
in this release.
comorbid_pccc_dx
: Calculate pediatric complex chronic conditions (PCCC) comorbidities
Unlike with ICD-9 and ICD-10 diagnostic codes, 'icd' doesn't
currently have a method for guessing which fields are procedure
codes, so icd_name
must be specified for the _pcs
functions.
comorbid_pccc_pcs
: Calculate the PCCC comorbidities based
on procedure codes,
icd9_comorbid_pccc_dx
: Calculate PCCC comorbidities from ICD-9
diagnosis codes
icd10_comorbid_pccc_dx
: Calculate PCCC comorbidities from ICD-10
diagnosis codes
icd9_comorbid_pccc_pcs
: Calculate PCCC comorbidities from ICD-9
procedure codes
icd10_comorbid_pccc_pcs
: Calculate PCCC comorbidities from ICD-10
procedure codes
Consider using comorbid_ahrq
instead of
comorbid_elix
for more recently updated mappings based on the
Elixhauser scheme.
Other comorbidity computations:
comorbid_hcc()
Other comorbidities:
comorbid_hcc()
,
icd10_map_ahrq_pcs
,
icd9_map_ahrq
,
icd9_map_elix
,
icd9_map_hcc
,
icd9_map_pccc
,
icd9_map_quan_deyo
,
icd9_map_quan_elix
,
icd9_map_single_ccs
Other comorbidity computations:
comorbid_hcc()
Other comorbidities:
comorbid_hcc()
,
icd10_map_ahrq_pcs
,
icd9_map_ahrq
,
icd9_map_elix
,
icd9_map_hcc
,
icd9_map_pccc
,
icd9_map_quan_deyo
,
icd9_map_quan_elix
,
icd9_map_single_ccs
#> 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# get first few rows and columns of Charlson comorbidities using Quan/Deyo # mapping of ICD-9 or ICD-10 codes Charlson categories comorbid_quan_deyo(vermont_dx)[1:5, 1:14]#> MI CHF PVD Stroke Dementia Pulmonary Rheumatic PUD LiverMild DM #> 7 FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 10 FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE #> 13 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 16 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE #> 37 FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> DMcx Paralysis Renal Cancer #> 7 FALSE FALSE TRUE TRUE #> 10 FALSE FALSE FALSE FALSE #> 13 FALSE FALSE FALSE FALSE #> 16 FALSE FALSE FALSE FALSE #> 37 FALSE FALSE FALSE FALSE# Note that the comorbidity calculations automatically finds the ICD code # columns, and uses 'wide' or 'long' format data. stopifnot( identical( comorbid_quan_deyo(vermont_dx), comorbid_quan_deyo(wide_to_long(vermont_dx)) ) ) # get summary AHRQ (based on Elixhauser) comorbidities for the Uranium data: summary(comorbid_ahrq(uranium_pathology))#> CHF Valvular PHTN PVD #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:331 FALSE:305 FALSE:330 FALSE:264 #> TRUE :3 TRUE :29 TRUE :4 TRUE :70 #> HTN Paralysis NeuroOther Pulmonary #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:225 FALSE:334 FALSE:304 FALSE:220 #> TRUE :109 TRUE :30 TRUE :114 #> DM DMcx Hypothyroid Renal #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:331 FALSE:334 FALSE:334 FALSE:328 #> TRUE :3 TRUE :6 #> Liver PUD HIV Lymphoma #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:300 FALSE:330 FALSE:334 FALSE:334 #> TRUE :34 TRUE :4 #> Mets Tumor Rheumatic Coagulopathy #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:270 FALSE:287 FALSE:330 FALSE:331 #> TRUE :64 TRUE :47 TRUE :4 TRUE :3 #> Obesity WeightLoss FluidsLytes BloodLoss #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:328 FALSE:326 FALSE:333 FALSE:334 #> TRUE :6 TRUE :8 TRUE :1 #> Anemia Alcohol Drugs Psychoses #> Mode :logical Mode :logical Mode :logical Mode :logical #> FALSE:332 FALSE:334 FALSE:334 FALSE:333 #> TRUE :2 TRUE :1 #> Depression #> Mode :logical #> FALSE:334 #>pts <- icd_long_data( visit_name = c("2", "1", "2", "3", "3"), icd9 = c("39891", "40110", "09322", "41514", "39891") ) comorbid(pts, icd9_map_ahrq, short_code = TRUE) # visit_name is now sorted#> CHF Valvular PHTN PVD HTN HTNcx Paralysis NeuroOther Pulmonary DM #> 2 TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 1 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE #> 3 TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> DMcx Hypothyroid Renal Liver PUD HIV Lymphoma Mets Tumor Rheumatic #> 2 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 3 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Coagulopathy Obesity WeightLoss FluidsLytes BloodLoss Anemia Alcohol Drugs #> 2 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 3 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Psychoses Depression #> 2 FALSE FALSE #> 1 FALSE FALSE #> 3 FALSE FALSEpts <- icd_long_data( visit_name = c("1", "2", "3", "4", "4"), icd_name = c("20084", "1742", "30410", "41514", "95893"), date = as.Date(c( "2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04", "2011-01-04" )) ) pt_hccs <- comorbid_hcc(pts, date_name = "date") head(pt_hccs)#> visit_name date hcc #> 1 1 2011-01-01 9 #> 2 2 2011-01-02 10 #> 3 3 2011-01-03 52 #> 4 4 2011-01-04 164pts10 <- icd_long_data( visit_name = c("a", "b", "c", "d", "e"), icd_name = c("I058", NA, "T82817A", "", "I69369"), date = as.Date( c("2011-01-01", "2011-01-02", "2011-01-03", "2011-01-03", "2011-01-03") ) ) icd10_comorbid(pts10, map = icd10_map_ahrq)#> CHF Valvular PHTN PVD HTN HTNcx Paralysis NeuroOther Pulmonary DM #> a FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE #> DMcx Hypothyroid Renal Liver PUD HIV Lymphoma Mets Tumor Rheumatic #> a FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Coagulopathy Obesity WeightLoss FluidsLytes BloodLoss Anemia Alcohol Drugs #> a FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Psychoses Depression #> a FALSE FALSE #> b FALSE FALSE #> c FALSE FALSE #> d FALSE FALSE #> e FALSE FALSE# or if library(icd) hasn't been called first: icd::icd10_comorbid(pts10, map = icd::icd10_map_ahrq)#> CHF Valvular PHTN PVD HTN HTNcx Paralysis NeuroOther Pulmonary DM #> a FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE #> DMcx Hypothyroid Renal Liver PUD HIV Lymphoma Mets Tumor Rheumatic #> a FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Coagulopathy Obesity WeightLoss FluidsLytes BloodLoss Anemia Alcohol Drugs #> a FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Psychoses Depression #> a FALSE FALSE #> b FALSE FALSE #> c FALSE FALSE #> d FALSE FALSE #> e FALSE FALSE# or most simply: icd::icd10_comorbid_ahrq(pts10)#> CHF Valvular PHTN PVD HTN Paralysis NeuroOther Pulmonary DM DMcx #> a FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE #> Hypothyroid Renal Liver PUD HIV Lymphoma Mets Tumor Rheumatic #> a FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Coagulopathy Obesity WeightLoss FluidsLytes BloodLoss Anemia Alcohol Drugs #> a FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> b FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> c FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> d FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> e FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Psychoses Depression #> a FALSE FALSE #> b FALSE FALSE #> c FALSE FALSE #> d FALSE FALSE #> e FALSE FALSE# specify a simple custom comorbidity map: my_map <- list( "malady" = c("100", "2000"), "ailment" = c("003", "040") ) two_pts <- data.frame( visit_id = c("v01", "v01", "v02", "v02"), icd9 = as.icd9(c("040", "000", "100", "000")), stringsAsFactors = FALSE ) comorbid(two_pts, map = my_map)#> malady ailment #> v01 FALSE TRUE #> v02 TRUE FALSE#> Neuromusc CVD Respiratory Renal GI HematoImmu Metabolic CongeniGenetic #> 7 FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE #> 10 FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE #> 13 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 16 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> 37 FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE #> 41 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Malignancy Neonatal TechDep Transplant #> 7 TRUE FALSE FALSE FALSE #> 10 FALSE FALSE FALSE FALSE #> 13 FALSE FALSE FALSE FALSE #> 16 FALSE FALSE FALSE FALSE #> 37 FALSE FALSE FALSE FALSE #> 41 FALSE FALSE FALSE FALSE# Six random codes from each PCCC procedure code map. 'icd' will use # an heuristic to guess whether ICD-9 or ICD-10: pts <- data.frame( encounters = c(10, 11, 12), icd9_pcs = c("0152", "304", "0050"), icd10_pcs = c("0B110Z4", "02YA0Z2", "031209D") ) comorbid_pccc_pcs(pts, icd_name = "icd9_pcs", return_binary = TRUE)#> Neuromusc CVD Respiratory Renal GI HematoImmu Metabolic CongeniGenetic #> 10 1 0 0 0 0 0 0 0 #> 11 0 0 1 0 0 0 0 0 #> 12 0 1 0 0 0 0 0 0 #> Malignancy Neonatal TechDep Transplant #> 10 0 0 0 0 #> 11 0 0 0 0 #> 12 0 0 1 0comorbid_pccc_pcs(pts, icd_name = "icd10_pcs", return_binary = TRUE)#> Neuromusc CVD Respiratory Renal GI HematoImmu Metabolic CongeniGenetic #> 10 0 0 1 0 0 0 0 0 #> 11 0 1 0 0 0 0 0 0 #> 12 0 0 0 1 0 0 0 0 #> Malignancy Neonatal TechDep Transplant #> 10 0 0 0 0 #> 11 0 0 0 1 #> 12 0 0 1 0# All ICD-9 procedure codes are numeric, some ICD-10 procedure codes # are numeric, so best to call functions directly: pts <- data.frame(encounters = c(100), icd10_pcs = c("0016070")) icd10_comorbid_pccc_pcs(pts, icd_name = "icd10_pcs")#> Neuromusc CVD Respiratory Renal GI HematoImmu Metabolic CongeniGenetic #> 100 TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> Malignancy Neonatal TechDep Transplant #> 100 FALSE FALSE FALSE FALSE