Skip to content

Commit

Permalink
Merge pull request #7 from jmjmfasdf/main
Browse files Browse the repository at this point in the history
lecture slide, code edit
  • Loading branch information
jinseob2kim authored Dec 11, 2024
2 parents 599cd83 + 2efae1b commit ea784e9
Show file tree
Hide file tree
Showing 56 changed files with 4,306 additions and 4,155 deletions.
17 changes: 11 additions & 6 deletions code/datatable-3-CCI.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ code.cci <- list(
cciscore <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 6, 6, 2)
names(cciscore) <- names(code.cci)

# info.cci <- mclapply(names(code.cci), function(x){
# merge(data.asd[, .(RN_INDI, Indexdate)],
# m40[like(MCEX_SICK_SYM, paste(code.cci[[x]], collapse = "|"))][order(MDCARE_STRT_DT), .SD[1], keyby = "RN_INDI"][, .(RN_INDI, inidate = MDCARE_STRT_DT)],
# by = "RN_INDI", all.x = T)[, ev := as.integer(Indexdate >= as.Date(as.character(inidate), format = "%Y%m%d"))][, ev := ifelse(is.na(ev), 0, ev)][]$ev * cciscore[x]
# }, mc.cores = 4) %>% do.call(cbind, .) %>% cbind(rowSums(.))
# colnames(info.cci) <- c(paste0("Prev_", names(code.cci)), "CCI")


# rolling merge in 365 days 위의 결과와 같게 하려면 roll=Inf, 365일 내로 보려면 roll=365
info.cci <- mclapply(names(code.cci), function(x){
merge(data.asd[, .(RN_INDI, Indexdate)],
m40[like(MCEX_SICK_SYM, paste(code.cci[[x]], collapse = "|"))][order(MDCARE_STRT_DT), .SD[1], keyby = "RN_INDI"][, .(RN_INDI, inidate = MDCARE_STRT_DT)],
by = "RN_INDI", all.x = T)[, ev := as.integer(Indexdate > as.Date(as.character(inidate), format = "%Y%m%d"))][, ev := ifelse(is.na(ev), 0, ev)][]$ev * cciscore[x]
}, mc.cores = 4) %>% do.call(cbind, .) %>% cbind(rowSums(.))
data.asd[, MDCARE_STRT_DT := Indexdate]
dt <- m40[like(MCEX_SICK_SYM, paste(code.cci[[x]], collapse = "|"))][, MDCARE_STRT_DT := as.Date(as.character(MDCARE_STRT_DT), format = "%Y%m%d")][, .(RN_INDI, MDCARE_STRT_DT, Incidate = MDCARE_STRT_DT)]
dt[, .SD[1], keyby = c("RN_INDI", "MDCARE_STRT_DT")][data.asd, on = c("RN_INDI", "MDCARE_STRT_DT"), roll = 365][, ev := as.integer(!is.na(Incidate))][]$ev * cciscore[x]
}, mc.cores = 4) %>% do.call(cbind, .) %>% cbind(rowSums(.))
colnames(info.cci) <- c(paste0("Prev_", names(code.cci)), "CCI")

16 changes: 12 additions & 4 deletions code/datatable-4-prevdrug.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ code.drug <- list(
)


# info.prevmed <- mclapply(code.drug, function(x){
# merge(data.asd,
# m60[GNL_NM_CD %in% x][order(MDCARE_STRT_DT), .SD[1], keyby = "RN_INDI"][, .(RN_INDI, inidate = MDCARE_STRT_DT)],
# by = "RN_INDI", all.x = T)[, ev := as.integer(Indexdate >= as.Date(as.character(inidate), format = "%Y%m%d"))][, ev := ifelse(is.na(ev), 0, ev)][]$ev
# }, mc.cores = 3) %>% do.call(cbind, .)
# colnames(info.prevmed) <- paste0("Prev_", names(code.drug))

# rolling merge in 365 days 위의 결과와 같게 하려면 roll=Inf, 365일 내로 보려면 roll=365
info.prevmed <- mclapply(code.drug, function(x){
merge(data.asd,
m60[GNL_NM_CD %in% x][order(MDCARE_STRT_DT), .SD[1], keyby = "RN_INDI"][, .(RN_INDI, inidate = MDCARE_STRT_DT)],
by = "RN_INDI", all.x = T)[, ev := as.integer(Indexdate > as.Date(as.character(inidate), format = "%Y%m%d"))][, ev := ifelse(is.na(ev), 0, ev)][]$ev
data.asd[, MDCARE_STRT_DT := Indexdate]
dt <- m60[GNL_NM_CD %in% x][, MDCARE_STRT_DT := as.Date(as.character(MDCARE_STRT_DT), format = "%Y%m%d")][, .(RN_INDI, MDCARE_STRT_DT, inidate = MDCARE_STRT_DT)]
dt[, .SD[1], keyby = c("RN_INDI", "MDCARE_STRT_DT")][data.asd, on = c("RN_INDI", "MDCARE_STRT_DT"), roll = 365][, ev := as.integer(!is.na(inidate))][]$ev
}, mc.cores = 3) %>% do.call(cbind, .)
colnames(info.prevmed) <- paste0("Prev_", names(code.drug))
colnames(info.prevmed) <- paste0("Prev_", names(code.drug))
18 changes: 12 additions & 6 deletions code/datatable-5-outcome.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
## MI after indexdate

source("code/inclusion.R")
info.MI <- merge(data.asd[, .(RN_INDI, Indexdate)],
m40[like(MCEX_SICK_SYM, paste(code.cci[["MI"]], collapse = "|"))][, .(RN_INDI, MIdate = MDCARE_STRT_DT)], by = "RN_INDI", all.x = T) %>%
.[Indexdate < as.Date(as.character(MIdate), format = "%Y%m%d")] %>%
.[order(MIdate), .(MI = 1, MIday = as.integer(as.Date(as.character(MIdate), format = "%Y%m%d") - Indexdate)[1]), keyby = "RN_INDI"]


# info.MI <- merge(data.asd[, .(RN_INDI, Indexdate)],
# m40[like(MCEX_SICK_SYM, paste(code.cci[["MI"]], collapse = "|"))][, .(RN_INDI, MIdate = MDCARE_STRT_DT)], by = "RN_INDI", all.x = T) %>%
# .[Indexdate <= as.Date(as.character(MIdate), format = "%Y%m%d")] %>%
# .[order(MIdate), .(MI = 1, MIday = as.integer(as.Date(as.character(MIdate), format = "%Y%m%d") - Indexdate)[1]), keyby = "RN_INDI"]

# rolling merge 위의 결과와 같게 하려면 roll=-Inf, 365일 내로 보려면 roll=365
data.asd[, MDCARE_STRT_DT := Indexdate]
info.MI <- m40 %>%
.[like(MCEX_SICK_SYM, paste(code.cci[["MI"]], collapse = "|")), .(RN_INDI, MDCARE_STRT_DT = as.Date(as.character(MDCARE_STRT_DT), format = "%Y%m%d"), MIdate = as.Date(as.character(MDCARE_STRT_DT), format = "%Y%m%d"))] %>%
.[data.asd, on = c("RN_INDI", "MDCARE_STRT_DT"), roll = -Inf] %>%
.[Indexdate <= MIdate] %>%
.[order(MIdate), .(MI = 1, MIday = as.integer(MIdate - Indexdate)[1]), keyby = "RN_INDI"]


data.final <- cbind(data.asd, info.cci, info.prevmed) %>% merge(info.MI, by = "RN_INDI", all.x = T) %>% .[, `:=`(MI = as.integer(!is.na(MI)),
Expand Down
Loading

0 comments on commit ea784e9

Please sign in to comment.