-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimulation_cox.R
More file actions
144 lines (110 loc) · 3.38 KB
/
simulation_cox.R
File metadata and controls
144 lines (110 loc) · 3.38 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#---------------------
#---------------------
# Runs the simulations in which
# data are generated using a Cox model
# data are analysed using a Cox model (development of prediction model)
# measures of predictive performance are calculated
# measures are stored in result matrices an arrays
#---------------------
#---------------------
#----
#seeds
set.seed(1)
seeds<-sample(1:1000000,Nsim)
#----
#storage for simulation results
#descriptives
descriptives_scenario <- matrix(nrow=Nsim, ncol=20)
colnames(descriptives_scenario) <- rep("NA",20)
descr_KM_curves_long <- matrix(nrow = 0, ncol = 4)
colnames(descr_KM_curves_long) = c("sim","time","type","risk")
#calibration
#[ , ,1]: predicted
#[ , ,2]: IPCW observed
#[ , ,3]: counterfactual true
#[ , ,4]: subset predicted
#[ , ,5]: subset observed
calib_risk0<-array(dim=c(Nsim,5,5))
calib_risk1<-array(dim=c(Nsim,5,5))
calib_risk0_group<-array(dim=c(Nsim,10,5))
calib_risk1_group<-array(dim=c(Nsim,10,5))
#discrimination
disc_cindex<-matrix(nrow=Nsim,ncol=10)
disc_auct<-matrix(nrow=Nsim,ncol=10)
#overall prediction error
brier_raw <- matrix(nrow=Nsim, ncol=8)
brier_ipa <- matrix(nrow=Nsim, ncol=8)
#----
#simulation loop
for(i in 1:Nsim){
print(i)
set.seed(seeds[i])
#---
#Simulate development and validation data and counterfactual validation data
if(scenario==1|scenario=="5a"|scenario=="5b"|scenario=="6a"|scenario=="6b"|scenario=="6d"){
source("dat_sim_cox_scenario1.R")
dat.dev<-dat
dat.long.dev<-dat.long
source("dat_sim_cox_scenario1.R")
dat.val<-dat
dat.long.val<-dat.long
}
if(scenario==2){
source("dat_sim_cox_scenario2.R")
dat.dev<-dat
dat.long.dev<-dat.long
source("dat_sim_cox_scenario1.R")
dat.val<-dat
dat.long.val<-dat.long
}
if(scenario==3){
source("dat_sim_cox_scenario1.R")
dat.dev<-dat
dat.long.dev<-dat.long
source("dat_sim_cox_scenario3.R")
dat.val<-dat
dat.long.val<-dat.long
}
if(scenario=="4a"){
source("dat_sim_cox_scenario1.R")
dat.dev<-dat
dat.long.dev<-dat.long
source("dat_sim_cox_scenario4a.R")
dat.val<-dat
dat.long.val<-dat.long
}
if(scenario=="4b"){
source("dat_sim_cox_scenario1.R")
dat.dev<-dat
dat.long.dev<-dat.long
source("dat_sim_cox_scenario4b.R")
dat.val<-dat
dat.long.val<-dat.long
}
if(scenario=="6c"){
source("dat_sim_cox_scenario1.R")
dat.dev<-dat
dat.long.dev<-dat.long
source("dat_sim_cox_scenario6c.R")
dat.val<-dat
dat.long.val<-dat.long
}
#---
#Simulate counterfactual validation data
source("dat_sim_cox_counterfactual_scenario1.R")
#---
#Model development (uses dat.long.dev)
source("analysis_cox_model_development.R")
#---
#Preparation for model validation: obtains quantities used for discrimination, calibration, Brier score (uses dat.val and dat.long.val)
source("analysis_cox_model_validation.R")
#source("analysis_cox_model_validation_weights_misspec.R")
#---
#Estimation of discrimination measures
source("discrimination.R")
#---
#Estimation of calibration measures
source("calibration.R")
#Calculate descriptives for comparison of scenarios
source("descriptives.R")
}