set.seed(1)
x <- data.frame(
id = sample(1:15, size = 200, replace = TRUE),
code = sample_diag(200),
stringsAsFactors = FALSE
)
# Charlson score based on ICD-10 diagnostic codes:
comorbidity(x = x, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = FALSE)
# Elixhauser score based on ICD-10 diagnostic codes:
comorbidity(x = x, id = "id", code = "code", map = "elixhauser_icd10_quan", assign0 = FALSE)
# The following example describes how the `assign0` argument works.
# We create a dataset for a single patient with two codes, one for
# uncomplicated diabetes ("E100") and one for complicated diabetes
# ("E102"):
x2 <- data.frame(
id = 1,
code = c("E100", "E102"),
stringsAsFactors = FALSE
)
# Then, we calculate the Quan-ICD10 Charlson score:
ccF <- comorbidity(x = x2, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = FALSE)
# With `assign0 = FALSE`, both diabetes comorbidities are counted:
ccF[, c("diab", "diabwc")]
# Conversely, with `assign0 = TRUE`, only the more severe diabetes with
# complications is counted:
ccT <- comorbidity(x = x2, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = TRUE)
ccT[, c("diab", "diabwc")]
Run the code above in your browser using DataLab