Computes comorbidity scores such as the weighted Charlson score and the Elixhauser comorbidity score.
comorbidity(x, id, code, score, assign0 = TRUE, factorise = FALSE,
labelled = TRUE, tidy.codes = TRUE, parallel = FALSE,
mc.cores = parallel::detectCores())
A tidy data frame with one column containing an individual ID and a column containing all diagnostic codes.
Column of x
containing the individual ID.
Column of x
containing diagnostic codes. Codes must be in upper case with no puctuation in order to be properly recognised.
The comorbidity score to compute. Possible choices are the weighted Charlson score based on ICD-10 codes (charlson_icd10
) and the Elixhauser comorbidity score based on ICD-10 codes (elixhauser_icd10
). Defaults to charlson_icd10
.
Apply a hierarchy of comorbities. If TRUE
, should a comorbidity be present in a patient with different degrees of severity, then the milder form will be assigned to 0 and therefore not counted. By doing this, a type of comorbidity is not counted more than once in each patient.
Return comorbidities as factors rather than numeric, where (1 = presence of comorbidity, 0 = otherwise). Defaults to FALSE
.
Attach labels to each comorbidity, compatible with the RStudio viewer via the utils::View()
function. Defaults to TRUE
.
Tidy diagnostic codes? If TRUE
, all codes are converted to upper case and all non-alphanumeric characters are removed (REGEXPR: [^[:alnum:]]
). Defaults to TRUE
.
Run the computation in parallel? See the Notes
section for more information. Defaults to FALSE
.
The number of cores to use when running the computations in parallel. Defaults to all available cores.
A data frame with id
, columns relative to each comorbidity domain, comorbidity score, weighted comorbidity score, and categorisations of such scores, with one row per individual.
For the Charlson score, the following variables are included in the dataset:
The id
variable as defined by the user;
ami
, for acute myocardial infarction;
chf
, for congestive heart failure;
pvd
, for peripheral vascular disease;
cevd
, for cerebrovascular disease;
dementia
, for dementia;
copd
, chronic obstructive pulmonary disease;
rheumd
, for rheumatoid disease;
pud
, for peptic ulcer disease;
mld
, for mild liver disease;
diab
, for diabetes without complications;
diabwc
, for diabetes with complications;
hp
, for hemiplegia or paraplegia;
rend
, for renal disease;
canc
, for cancer (any malignancy);
msld
, for moderate or severe liver disease;
metacanc
, for metastatic solid tumor;
aids
, for AIDS/HIV;
score
, for the weighted Charlson score;
index
, for the grouped Charlson index.
Conversely, for the Elixhauser score the dataset contains the following variables:
The id
variable as defined by the user;
chf
, for congestive heart failure;
carit
, for cardiac arrhytmias;
valv
, for valvular disease;
pcd
, for pulmonary circulation disorders;
pvd
, for peripheral vascular disorders;
hypunc
, for hypertension, uncomplicated;
hypc
, for hypertension, complicated;
para
, for paralysis;
ond
, for other neurological disorders;
cpd
, for chronic pulmonary disease;
diabunc
, for diabetes, uncomplicated;
diabc
, for diabetes, complicated;
hypothy
, for hypothyroidism;
rf
, for renal failure;
ld
, for liver disease;
pud
, for peptic ulcer disease, excluding bleeding;
aids
, for AIDS/HIV;
lymph
, for lymphoma;
metacanc
, for metastatic cancer;
solidtum
, for solid tumor, without metastasis;
rheumd
, for rheumatoid artritis/collaged vascular disease;
coag
, for coagulopaty;
obes
, for obesity;
wloss
, for weight loss;
fed
, for fluid and electrolyte disorders;
blane
, for blood loss anemia;
dane
, for deficiency anemia;
alcohol
, for alcohol abuse;
drug
, for drug abuse;
psycho
, for psychoses;
depre
, for depression.
Labels are presented to the user when using the RStudio viewer (e.g. via the utils::View()
function) for convenience.
This function is based on the ICD-10-based formulations of the Charlson score and Elixhauser score proposed by Quan et al. in 2005. Weights for the Charlson score are based on the original formulation by Charlson et al. in 1987, while weights for the Elixhauser score are based on work by van Walraven et al. Finally, the categorisation of scores and weighted scores is based on work by Menendez et al.
ICD-10 codes must be in upper case and with no punctuation in order to be properly recognised; set tidy.codes = TRUE
to properly tidy the codes automatically.
To run the calculations in parallel set parallel = TRUE
. This is based on parallel::parLapply()
, and it is possible to set the number of cores to use via the mc.cores
argument, which defaults to using all the cores available.
Quan H, Sundararajan V, Halfon P, Fong A, Burnand B, Luthi J-C, et al. Coding algorithms for defining comorbidities in ICD-9-CM and ICD-10 administrative data. Medical Care 2005; 43(11):1130-1139.
Charlson ME, Pompei P, Ales KL, et al. A new method of classifying prognostic comorbidity in longitudinal studies: development and validation. Journal of Chronic Diseases 1987; 40:373-383.
van Walraven C, Austin PC, Jennings A, Quan H and Forster AJ. A modification of the Elixhauser comorbidity measures into a point system for hospital death using administrative data. Medical Care 2009; 47(6):626-633.
Menendez ME, Neuhaus V, van Dijk CN, Ring D. The Elixhauser comorbidity method outperforms the Charlson index in predicting inpatient death after orthopaedic surgery. Clinical Orthopaedics and Related Research 2014; 472:2878<U+2013>2886.
# NOT RUN {
set.seed(1)
x <- data.frame(
id = sample(1:15, size = 200, replace = TRUE),
code = sample_diag_icd10(200),
stringsAsFactors = FALSE)
# Charlson score based on ICD-10 diagnostic codes:
comorbidity(x = x, id = "id", code = "code", score = "charlson_icd10")
# Elixhauser score based on ICD-10 diagnostic codes:
comorbidity(x = x, id = "id", code = "code", score = "elixhauser_icd10")
# }
Run the code above in your browser using DataLab