forked from phcanalytics/coxnet-ltrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-setup.R
63 lines (57 loc) · 2.04 KB
/
01-setup.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# R Packages -------------------------------------------------------------------
library("data.table")
library("doParallel")
library("doRNG") # Reproducible parallel foreach loops
library("dplyr")
library("foreach")
library("glmnet")
library("ggplot2")
library("ggpubr")
library("impute") # From bioconductor
library("knitr")
library("parallel")
library("purrr")
library("rngtools") # Required by dorng
library("rsample")
library("survival")
library("tidyr") # (>= 1.0.0) for pivot_longer() and pivot_wider()
# library("xfun") # We will use xfun::cache_rds() below, but not attach the package here
library("xtable")
# Custom R functions -----------------------------------------------------------
source("R/plot_patient_followup.R")
source("R/impute_genes.R")
source("R/make_xy.R")
source("R/calibrate_sim.R")
source("R/sim.R")
source("R/adjust_surv.R")
source("R/tidycoef.R")
source("R/concordance.R")
source("R/calibrate.R")
# Settings ---------------------------------------------------------------------
set.seed(77)
theme_set(theme_bw())
center_title <- function() theme(plot.title = element_text(hjust = 0.5))
N_SIMS <- 200
# Caching
RERUN_CACHE <- TRUE # Set to TRUE to rerun all cached results
if (!dir.exists("cache")){
dir.create("cache")
}
# Parallel
PARALLEL <- TRUE
if (PARALLEL) {
cl <- parallel::makeCluster(20, setup_strategy = "sequential", outfile = "simout")
registerDoParallel(cl)
}
# Model formula ----------------------------------------------------------------
# This formula is used for both the simulations and the real-world data application
f_small <- formula(
~ PracticeType + index_date_year + Race + age_at_dx + RE_TP53 +
CN_TP53 + SV_TP53 + SV_KRAS + SV_EGFR
)
vars_small <- c("Practice type: community", "Index year", "African American",
"Other race", "White", "Age", "TP53 RE",
"TP53 CN", "TP53 SV", "KRAS SV", "EGFR SV")
# Followup plot ----------------------------------------------------------------
p_followup <- plot_patient_followup()
ggsave("figs/followup.pdf", p_followup, height = 5, width = 7)