index_fun {coder} | R Documentation |
Calculate index based on classification scheme
Description
This is the third step of codify() %>% classify() %>% index()
.
The function takes classified case data and calculates
(weighted) index sums as specified by weights from a classcodes
object.
Usage
index(classified, ...)
## S3 method for class 'data.frame'
index(classified, ...)
## S3 method for class 'matrix'
index(classified, index = NULL, cc = NULL, ...)
Arguments
classified |
output from |
... |
used internally |
index |
name of column with 'weights' from corresponding
|
cc |
|
Details
Index weights for subordinate hierarchical classes
(as identified by attr(cc, "hierarchy")
) are excluded in presence of
superior classes if index specified with argument index
.
Value
Named numeric index vector with names corresponding to
rownames(classified)
See Also
Other verbs:
categorize()
,
classify()
,
codify()
Examples
# Prepare some codified data with ICD-10 codes during 1 year (365 days)
# before surgery
x <-
codify(
ex_people,
ex_icd10,
id = "name",
code = "icd10",
date = "surgery",
days = c(-365, 0),
code_date = "admission"
)
# Classify those patients by the Charlson comorbidity indices
cl <- classify(x, "charlson")
# Calculate (weighted) index values
head(index(cl)) # Un-weighted sum/no of conditions for each patient
head(index(cl, "quan_original")) # Weighted index (Quan et al. 2005; see `?charlson`)
head(index(cl, "quan_updated")) # Weighted index (Quan et al. 2011; see `?charlson`)
# Tabulate index for all patients.
# As expected, most patients are healthy and have index = 0/NA,
# where NA indicates no recorded hospital visits
# found in `ex_icd10` during codification.
# In practice, those patients might be assumed to have 0 comorbidity as well.
table(index(cl, "quan_original"), useNA = "always")
# If `cl` is a matrix without additional attributes (as imposed by `codify()`)
# an explicit classcodes object must be specified by the `cc` argument
cl2 <- as.matrix(cl)
head(index(cl2, cc = "charlson"))