1
+ # Calibrate simulation ---------------------------------------------------------
2
+ if (file.exists(" sim_settings.rds" )) { # Interested readers can run this
3
+ sim_settings <- readRDS(" sim_settings.rds" )
4
+ } else { # This setting is run for the paper
5
+ data <- readRDS(" data.rds" )
6
+ sim_settings <- calibrate_sim(f_small , data = data , store_x = TRUE )
7
+ }
8
+
9
+ # Save cumulative hazard plot
10
+ ggsave(" figs/sim_calibration_cumhaz.pdf" ,
11
+ sim_settings $ cumhaz_plot ,
12
+ height = 5 , width = 10 )
13
+
14
+ # Example simulated data -------------------------------------------------------
15
+ # No predictors (intercept only model)
16
+ params <- set_params(sim_settings = sim_settings , dist = " weibullPH" )
17
+ simdata <- sim_survdata(params = params , n_pats = 10000 )
18
+ simdata_summary_int <- summarize_simdata(simdata , km_rwd = sim_settings $ os_km $ rc ,
19
+ save = TRUE , name = " int" )
20
+
21
+ # Now include predictors (and hence create informative censoring when
22
+ # using the Kaplan-Meier estimator). The design matrix X and parameters will
23
+ # be used in the simulations that follow
24
+ x_sim <- sim_x(n_pats = 5000 , sim_settings , p_bin = 0 )
25
+ params <- set_params(x_sim , sim_settings , dist = " weibullPH" )
26
+ simdata <- sim_survdata(x_sim , params )
27
+ simdata_summary_p11 <- summarize_simdata(simdata , km_rwd = sim_settings $ os_km $ rc ,
28
+ save = TRUE , name = " p11" )
29
+
30
+ # Run simulation for unpenalized Cox model -------------------------------------
31
+ sim_coxph_p21 <- xfun :: cache_rds({
32
+ run_sim(n_sims = N_SIMS , x = x_sim , params = params , method = " coxph" )
33
+ }, file = " sim_coxph_p21.rds" , rerun = RERUN_CACHE )
34
+ sim_coxph_21_summary <- summarize_sim(sim_coxph_p21 , save = TRUE ,
35
+ model_name = " coxph_p21" )
36
+ rm(sim_coxph_p21 )
37
+
38
+ # Run simulation for lasso model with lambda = 0 and small p -------------------
39
+ # run_sim1(simdata, method = "coxnet", lambda = 0) # For debugging
40
+ sim_coxlasso_lambda0_p21 <- xfun :: cache_rds({
41
+ run_sim(n_sims = N_SIMS , x = x_sim , params = params ,
42
+ method = " coxnet" , lambda = c(1 , 0 ))
43
+ }, file = " sim_coxlasso_lambda0_p21.rds" , rerun = RERUN_CACHE )
44
+ coxlasso_lambda0_p21_summary <- summarize_sim(
45
+ sim_coxlasso_lambda0_p21 , save = TRUE ,
46
+ model_name = " coxlasso_lambda0_p21"
47
+ )
48
+ rm(sim_coxlasso_lambda0_p21 )
49
+
50
+ # Run simulation for lasso model with small p ----------------------------------
51
+ sim_coxlasso_p21 <- xfun :: cache_rds({
52
+ run_sim(n_sims = N_SIMS , x = x_sim , params = params ,
53
+ method = " coxnet" )
54
+ }, file = " sim_coxlasso_p21.rds" , rerun = RERUN_CACHE )
55
+ sim_coxlasso_p21_summary <- summarize_sim(sim_coxlasso_p21 , save = TRUE ,
56
+ model_name = " coxlasso_p21" )
57
+ rm(sim_coxlasso_p21 )
58
+
59
+ # Run simulation for ridge model with small p ----------------------------------
60
+ sim_coxridge_p21 <- xfun :: cache_rds({
61
+ run_sim(n_sims = N_SIMS , x = x_sim , params = params ,
62
+ method = " coxnet" , alpha = 0 )
63
+ }, file = " sim_coxridge_p21.rds" , rerun = RERUN_CACHE )
64
+ sim_coxridge_p21_summary <- summarize_sim(sim_coxridge_p21 , save = TRUE ,
65
+ model_name = " coxridge_p21" )
66
+ rm(sim_coxridge_p21 )
67
+
68
+ # Run simulation for lasso model with large p ----------------------------------
69
+ x_sim <- sim_x(n_pats = 5000 , sim_settings , p_bin = 1000 )
70
+ params <- set_params(x_sim , sim_settings , dist = " weibullPH" )
71
+
72
+ sim_coxlasso_p1011 <- xfun :: cache_rds({
73
+ run_sim(n_sims = N_SIMS , x = x_sim , params = params ,
74
+ method = " coxnet" )
75
+ }, file = " sim_coxlasso_p1011.rds" , rerun = RERUN_CACHE )
76
+ sim_coxlasso_p1011_summary <- summarize_sim(sim_coxlasso_p1011 , save = TRUE ,
77
+ model_name = " coxlasso_p1011" )
78
+ rm(sim_coxlasso_p1011 )
79
+
80
+ # Calibration plot comparing small and large p simulation ----------------------
81
+ sim_coxlasso_calplot <- ggarrange(
82
+ sim_coxlasso_p21_summary $ calibration_plots $ complete +
83
+ ggtitle(" (A) Small p" ) + center_title(),
84
+ sim_coxlasso_p1011_summary $ calibration_plots $ complete +
85
+ ggtitle(" (B) Large p" ) + center_title(),
86
+ nrow = 2 , common.legend = TRUE , legend = " bottom"
87
+ )
88
+ ggsave(" figs/sim_coxlasso_calibration_complete.pdf" , sim_coxlasso_calplot ,
89
+ width = 7 , height = 9 )
0 commit comments