Code
library("ettbc")
people <- data.frame(
chf = c(0, 1, 0),
dementia = c(0, 0, 1),
metastatic_cancer = c(0, 0, 1)
)
w <- c(chf = 2, dementia = 2, metastatic_cancer = 5)
comorbidity_score(people, w)[1] 0 2 7
Computes a weighted comorbidity score for each person from a set of binary condition indicators and a named vector of per-condition weights. This is the general scoring engine behind the Gagne combined comorbidity score (see gagne_weights()); supplying a different weights vector computes any other additive comorbidity index from the same condition flags.
comorbidity_score(data, weights = gagne_weights(), na_rm = FALSE)
data
|
A data frame with one row per person and a 0/1 (or logical) indicator column for each condition named in weights.
|
weights
|
A named numeric vector mapping condition column names to their weights. Defaults to gagne_weights() (the Gagne combined comorbidity score); data must then contain all 20 Gagne condition columns.
|
na_rm
|
Logical; if TRUE, missing indicator values are treated as 0 (condition absent). If FALSE (the default), any NA in a scored column is an error.
|
The score for a person is the sum, over the conditions named in weights, of the weight times the person’s 0/1 indicator for that condition. The comorbidity-mapping step (turning ICD diagnosis codes into the condition indicators) is out of scope here; map codes to flags first — for example with the comorbidity package — then pass the resulting indicator columns to this function.
A numeric vector with one weighted score per row of data.
Gagne JJ, Glynn RJ, Avorn J, Levin R, Schneeweiss S. A combined comorbidity score predicted mortality in elderly patients better than existing scores. J Clin Epidemiol. 2011;64(7):749-759. doi:10.1016/j.jclinepi.2010.10.004
gagne_weights() for the García-Albéniz / Gagne weight set.
library("ettbc")
people <- data.frame(
chf = c(0, 1, 0),
dementia = c(0, 0, 1),
metastatic_cancer = c(0, 0, 1)
)
w <- c(chf = 2, dementia = 2, metastatic_cancer = 5)
comorbidity_score(people, w)[1] 0 2 7