
Add Charlson Comorbidity Index (CCI) value based on Charlson et al. (1987) (doi:10.1016/0021-9681(87)90171-8 ) and Charlson et al. (1994) (doi:10.1016/0895-4356(94)90129-5 ) (age-adjusted) version.
Source:R/addCharlsonIndex.R
addCharlsonIndex.RdAdd Charlson Comorbidity Index (CCI) value based on Charlson et al. (1987) (doi:10.1016/0021-9681(87)90171-8 ) and Charlson et al. (1994) (doi:10.1016/0895-4356(94)90129-5 ) (age-adjusted) version.
Usage
addCharlsonIndex(
x,
indexDate = "cohort_start_date",
ageAdjusted = TRUE,
conceptSet = getIndexCodelist("charlson"),
nameStyle = "charlson",
categories = NULL,
name = tableName(x)
)Arguments
- x
A
cdm_tablecontaining a person identifier column namedperson_idorsubject_id.- indexDate
A character string naming the
Datecolumn inxthat defines the index date.- ageAdjusted
Logical; whether to include age adjustment in the Charlson Comorbidity Index.
- conceptSet
A named concept set supplied as a
codelist,codelist_with_details,concept_set_expression, or named list of concept IDs. It must containmyocardial_infarction,congestive_heart_failure,peripheral_vascular_disease,cerebrovascular_disease,dementia,chronic_pulmonary_disease,connective_tissue_disease,peptic_ulcer_disease,mild_liver_disease,diabetes_without_complication,hemiplegia,severe_chronic_kidney_disease,diabetes_with_complication,any_malignancy,moderate_or_severe_liver_disease,metastatic_solid_tumor,aidsas concepts. By default, internal codelists are used.- nameStyle
A character string specifying the name of the new column.
- categories
A named list of numeric vectors, each containing the lower and upper bounds of a score interval. An additional column with the suffix
_categoriesis added. Intervals are evaluated in the order supplied, and missing scores are labelledmissing.- name
A character string specifying the name of the output table. If
NULL, a temporary table is created.
Examples
# \donttest{
library(omock)
library(duckdb)
library(OmopIndices)
library(dplyr)
library(CohortConstructor)
cdm <- mockCdmFromDataset(datasetName = "GiBleed", source = "duckdb")
#> ℹ Loading bundled GiBleed tables from package data.
#> ℹ Adding drug_strength table.
#> ℹ Creating local <cdm_reference> object.
#> ℹ Inserting <cdm_reference> into duckdb.
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmplwnqmn/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
cdm$cohort <- conceptCohort(
cdm = cdm,
conceptSet = list(sinusitis = c(257012L, 4283893L, 4294548L, 40481087L)),
name = "cohort"
)
#> ℹ Subsetting table condition_occurrence using 4 concepts with domain:
#> condition.
#> ℹ Combining tables.
#> ℹ Creating cohort attributes.
#> ℹ Applying cohort requirements.
#> ℹ Merging overlapping records.
#> ✔ Cohort cohort created.
# Using the internal concept sets:
cdm$cohort |>
addCharlsonIndex(ageAdjusted = TRUE) |>
select(subject_id, cohort_start_date, charlson) |>
glimpse()
#> Warning: 1559 unique codelist concept IDs are not present in `cdm$concept`.
#> Warning: 1559 unique codelist concept IDs are not present in `cdm$concept`.
#> ! 1562 concept(s) from domain NA eliminated as it is not supported.
#> ℹ Supported domains are: device, specimen, measurement, drug, condition,
#> observation, procedure, episode, and visit.
#> Rows: ??
#> Columns: 3
#> $ subject_id <int> 227, 376, 672, 727, 727, 727, 730, 787, 820, 842, 84…
#> $ cohort_start_date <date> 1972-03-20, 1969-04-29, 1980-10-09, 1932-08-08, 199…
#> $ charlson <dbl> 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1, 3, 0, 4, 0, 0, 0, 0…
# This example uses custom concept sets.
customConceptSet <- list(
myocardial_infarction = 329847L,
congestive_heart_failure = 319835L,
peripheral_vascular_disease = 321052L,
cerebrovascular_disease = 381591L,
dementia = 4182210L,
chronic_pulmonary_disease = 255573L,
connective_tissue_disease = 4134537L,
peptic_ulcer_disease = 4027663L,
mild_liver_disease = 194984L,
moderate_or_severe_liver_disease = 4212540L,
diabetes_without_complication = 201820L,
diabetes_with_complication = 42538715L,
hemiplegia = 374022L,
severe_chronic_kidney_disease = 46271022L,
any_malignancy = 4180914L,
metastatic_solid_tumor = 432851L,
aids = 4267414L
)
cdm$cohort |>
addCharlsonIndex(
conceptSet = customConceptSet,
nameStyle = "charlson_custom"
) |>
select(subject_id, cohort_start_date, charlson_custom) |>
glimpse()
#> Warning: 16 unique codelist concept IDs are not present in `cdm$concept`.
#> Warning: 16 unique codelist concept IDs are not present in `cdm$concept`.
#> ! 16 concept(s) from domain NA eliminated as it is not supported.
#> ℹ Supported domains are: device, specimen, measurement, drug, condition,
#> observation, procedure, episode, and visit.
#> Rows: ??
#> Columns: 3
#> $ subject_id <int> 227, 376, 672, 727, 727, 727, 730, 787, 820, 842, 84…
#> $ cohort_start_date <date> 1972-03-20, 1969-04-29, 1980-10-09, 1932-08-08, 199…
#> $ charlson_custom <dbl> 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 0, 0…
# }