Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
jinseob2kim committed Feb 17, 2022
1 parent 1fc89ce commit 2274ae4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion code/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ out
sapply(1:nrow(mat), function(x){mean(mat[x, ])}) ## Return vector
lapply(1:nrow(mat), function(x){mean(mat[x, ])}) ## Return list type
unlist(lapply(1:nrow(mat), function(x){mean(mat[x, ])})) ## Same to sapply

#parallel::mclapply(1:nrow(mat), function(x){mean(mat[x, ])}, mc.cores = 4) ## Multicore

apply(mat, 1, mean) ## 1: 행
rowMeans(mat) ## 동일
Expand Down
7 changes: 4 additions & 3 deletions code/datatable-2-inclusion.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bnc <- fread("data/nsc2_bnc_1000.csv")
bnd <- fread("data/nsc2_bnd_1000.csv")[, Deathdate := (lubridate::ym(DTH_YYYYMM) %>% lubridate::ceiling_date(unit = "month") - 1)][]
m20 <- fread("data/nsc2_m20_1000.csv")
m30 <- fread("data/nsc2_m30_1000.csv")
m40 <- fread("data/nsc2_m40_1000.csv")[SICK_CLSF_TYPE %in% c(1, 2, NA)]
m40 <- fread("data/nsc2_m40_1000.csv")[SICK_CLSF_TYPE %in% c(1, 2, NA)] ## Exclude 3
m60 <- fread("data/nsc2_m60_1000.csv")
g1e_0915 <- fread("data/nsc2_g1e_0915_1000.csv")

Expand All @@ -21,8 +21,9 @@ code.HTN <- paste(paste0("I", 10:15), collapse = "|")
data.start <- m20[like(SICK_SYM1, code.HTN) & (MDCARE_STRT_DT >= 20060101), .(Indexdate = min(MDCARE_STRT_DT)), keyby = "RN_INDI"]

## Previous disease: Among all sick code
excl <- m40[like(MCEX_SICK_SYM, code.HTN) & (MDCARE_STRT_DT < 20060101), .SD[1], .SDcols = c("MDCARE_STRT_DT"), keyby = "RN_INDI"]
excl <- m40[(MCEX_SICK_SYM %like% code.HTN) & (MDCARE_STRT_DT < 20060101), .SD[1], .SDcols = c("MDCARE_STRT_DT"), keyby = "RN_INDI"]

## Merge: left anti join
data.incl <- data.start[!excl, on = "RN_INDI"][, Indexdate := as.Date(as.character(Indexdate), format = "%Y%m%d")][]
#data.incl <- data.start[!(RN_INDI %in% excl$RN_INDI)]

Expand All @@ -32,7 +33,7 @@ data.asd <- merge(bnd, bnc[, .(SEX = SEX[1]), keyby = "RN_INDI"], by = "RN_INDI"
merge(data.incl, by = "RN_INDI") %>%
.[, `:=`(Age = year(Indexdate) - as.integer(substr(BTH_YYYY, 1, 4)),
Death = as.integer(!is.na(DTH_YYYYMM)),
Day_FU = as.integer(pmin(as.Date("2015-12-31"), Deathdate, na.rm =T) - Indexdate))] %>% .[, -c("BTH_YYYY", "DTH_YYYYMM", "Deathdate")]
Day_FU = as.integer(pmin(as.Date("2015-12-31"), Deathdate, na.rm =T) - Indexdate))] %>% .[, -c("BTH_YYYY", "DTH_YYYYMM", "Deathdate")]



5 changes: 4 additions & 1 deletion code/table1_ps.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ cc <- matchit(as.formula(paste0("SEX ~", paste(vars.mat, collapse = "+"))), data

data.mat <- match.data(cc)
data.final[, ps := cc$distance][, w := ifelse(SEX == "2", 1/ps, 1/(1 - ps))]
data.final[, w := ifelse(w > 10, 10, w)]
data.final[, w := ifelse(w > 10, 10, w)] ## Weight limit 10
data.design <- survey::svydesign(ids = ~1, weights = ~w, data = data.final)

CreateTableOne(vars.tb1, strata = "SEX", data = data.mat) %>%
print(showAllLevels = T, nonnormal = c("Day_FU", "MIday"), exact = "MI", smd = T)

svyCreateTableOne(vars.tb1, strata = "SEX", data = data.design) %>%
print(showAllLevels = T, nonnormal = c("Day_FU", "MIday"), exact = "MI", smd = T)



0 comments on commit 2274ae4

Please sign in to comment.