# NOT RUN {
library(icd)
vermont_dx[1:5, 1:10]
# get first few rows and columns of Charlson comorbidities using Quan/Deyo
# mapping of ICD-9 or ICD-10 codes Charlson categories
comorbid_quan_deyo(vermont_dx)[1:5, 1:14]
# Note that the comorbidity calculations automatically finds the ICD code
# columns, and uses 'wide' or 'long' format data.
stopifnot(
identical(
comorbid_quan_deyo(vermont_dx),
comorbid_quan_deyo(wide_to_long(vermont_dx))
)
)
# get summary AHRQ (based on Elixhauser) comorbidities for the Uranium data:
summary(comorbid_ahrq(uranium_pathology))
pts <- icd_long_data(
visit_name = c("2", "1", "2", "3", "3"),
icd9 = c("39891", "40110", "09322", "41514", "39891")
)
comorbid(pts, icd9_map_ahrq, short_code = TRUE) # visit_name is now sorted
pts <- icd_long_data(
visit_name = c("1", "2", "3", "4", "4"),
icd_name = c("20084", "1742", "30410", "41514", "95893"),
date = as.Date(c(
"2011-01-01", "2011-01-02", "2011-01-03",
"2011-01-04", "2011-01-04"
))
)
pt_hccs <- comorbid_hcc(pts, date_name = "date")
head(pt_hccs)
pts10 <- icd_long_data(
visit_name = c("a", "b", "c", "d", "e"),
icd_name = c("I058", NA, "T82817A", "", "I69369"),
date = as.Date(
c("2011-01-01", "2011-01-02", "2011-01-03", "2011-01-03", "2011-01-03")
)
)
icd10_comorbid(pts10, map = icd10_map_ahrq)
# or if library(icd) hasn't been called first:
icd::icd10_comorbid(pts10, map = icd::icd10_map_ahrq)
# or most simply:
icd::icd10_comorbid_ahrq(pts10)
# specify a simple custom comorbidity map:
my_map <- list(
"malady" = c("100", "2000"),
"ailment" = c("003", "040")
)
two_pts <- data.frame(
visit_id = c("v01", "v01", "v02", "v02"),
icd9 = as.icd9(c("040", "000", "100", "000")),
stringsAsFactors = FALSE
)
comorbid(two_pts, map = my_map)
# not pediatric data, but let's look for this example
head(icd9_comorbid_pccc_dx(vermont_dx))
# Six random codes from each PCCC procedure code map. 'icd' will use
# an heuristic to guess whether ICD-9 or ICD-10:
pts <- data.frame(
encounters = c(10, 11, 12),
icd9_pcs = c("0152", "304", "0050"),
icd10_pcs = c("0B110Z4", "02YA0Z2", "031209D")
)
comorbid_pccc_pcs(pts, icd_name = "icd9_pcs", return_binary = TRUE)
comorbid_pccc_pcs(pts, icd_name = "icd10_pcs", return_binary = TRUE)
# All ICD-9 procedure codes are numeric, some ICD-10 procedure codes
# are numeric, so best to call functions directly:
pts <- data.frame(encounters = c(100), icd10_pcs = c("0016070"))
icd10_comorbid_pccc_pcs(pts, icd_name = "icd10_pcs")
# }
Run the code above in your browser using DataLab