Introduction

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.

Mapping Comorbidities

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")

Comorbidity Scores

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.

References



Try the comorbidity package in your browser

Any scripts or data that you put into this service are public.

comorbidity documentation built on May 1, 2023, 5:19 p.m.