knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This vignette illustrates how to use the {comorbidity} package to identify comorbid conditions and to compute weighted (or unweighted) comorbidity scores.
For this, we will simulate a dataset with 100 patients and 10000 ICD-10 codes using the sample_diag()
function:
library(comorbidity) set.seed(1) df <- data.frame( id = sample(seq(100), size = 10000, replace = TRUE), code = sample_diag(n = 100) ) # Sort df <- df[order(df$id, df$code), ] str(df)
By default, the sample_diag()
function simulates ICD-10 data; it is however possible to simulate ICD-9 codes too, as we will see later on.
The comorbidity()
function can be used to apply mapping algorithms to a dataset.
Here, for instance, we use the Quan et al. (2005) version of the Charlson Comorbidity Index:
charlson_df <- comorbidity( x = df, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = FALSE ) str(charlson_df)
The resulting data frame has a row per subject, a column for IDs, and a column for each condition included in a given score (e.g. 17 conditions for the Charlson score).
length(unique(df$id)) == nrow(charlson_df)
The different columns are also labelled for compatibility with the RStudio viewer, see e.g. View(charlson_df)
after running the code above on your computer.
To see all supported mapping algorithms, please see the vignette:
vignette("B-comorbidity-scores", package = "comorbidity")
After calculating a data frame of comorbid conditions, that can be used to calculate comorbidity scores using the score()
function.
Say we want to calculate the Charlson comorbidity score, weighted using the Quan et al. (2011) weights:
quan_cci <- score(x = charlson_df, weights = "quan", assign0 = FALSE) table(quan_cci)
This returns a single value per subject:
length(quan_cci) == nrow(charlson_df)
If a pure combination of conditions is required (e.g. an unweighted score), pass the NULL
value to the weights
argument of the score()
function:
unw_cci <- score(x = charlson_df, weights = NULL, assign0 = FALSE) table(unw_cci)
Once again, available weighting systems/algorithms are described in the same vignette that was mentioned above.
Charlson ME et al. A new method of classifying prognostic comorbidity in longitudinal studies: development and validation. Journal of Chronic Diseases 1987; 40:373-383. DOI: 10.1016/0021-9681(87)90171-8
Quan H et al. Coding algorithms for defining comorbidities in ICD-9-CM and ICD-10 administrative data. Medical Care 2005; 43(11):1130-1139. DOI: 10.1097/01.mlr.0000182534.19832.83
Quan H et al. Updating and validating the Charlson Comorbidity Index and score for risk adjustment in hospital discharge abstracts using data from 6 countries. American Journal of Epidemiology 2011;173(6):676-82. DOI: 10.1093/aje/kwq433
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.