-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ture_Calculation.R
251 lines (161 loc) · 6.11 KB
/
Ture_Calculation.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Calculate the true for Section 5
# For Section 5.1 Evaluation and Comparison with Average Treatment Effect
# and Section 5.2 Evaluation of Multiple Constraints
# Scenario 1
p = 10 # dimension of X
n = 500000
x = matrix(runif(n*p, -2, 2), nrow=n, ncol=p)
# Kernel Density Plot
CX = x[, 1]
CX_den <- density(CX) # returns the density data
plot(CX_den, main='')
sum((CX > 0) * CX) / sum(CX > 0) # \delta = 1, expected selected sample ratio : 50% S1
mean(CX > 0)
# Scenario 2
# Kernel Density Plot
CX = (x[, 1] * x[, 2])
CX_den <- density(CX) # returns the density data
plot(CX_den, main='')
sum((CX > 0) * CX) / sum(CX > 0) # \delta = 1.0 , expected selected sample ratio : 50% S2
mean(CX > 0)
# Scenario 3
# Kernel Density Plot
CX = (x[, 1] + x[, 2])
CX_den <- density(CX) # returns the density data
plot(CX_den, main='')
sum((CX > -0.55) * CX) / sum(CX > -0.55) # \delta = 1.0, expected selected sample ratio : 63% S2
mean(CX > -0.55)
# For Section 5.3 Evaluation of Survival Data
# Scenario 4
set.seed(2333)
# calculate the true:
p = 10 # dimension of X
n = 10000
NN = 1000
x = matrix(runif(n*p, -1, 1), nrow=n, ncol=p)
L = 7
Y1 = exp(0.1 * x[, 1] + 0.2 * x[, 2] + (x[, 1]))
Y0 = exp(0.1 * x[, 1] + 0.2 * x[, 2])
CX_gen = function (x){
epsilon = exp(rnorm(NN, 0, 1)) # L = 12
# epsilon = exp(rlogis(NN)) # L = 21
# epsilon = exp(log(-log(1-runif(NN)))) # L = 8
mean(apply(cbind(x * epsilon, L),1,min))
}
# runif(n, 0, 7) 25% # runif(n, 0, 12) #15% #normal
# runif(n, 0, 10) 25% # runif(n, 0, 21) #15% #logsitic
# runif(n, 0, 4) 25% # runif(n, 0, 8) #15% #extreme
CX_surv1 = apply(as.matrix(Y1), 1, CX_gen) - apply(as.matrix(Y0), 1, CX_gen)
set.seed(2333)
# calculate the true:
p = 10 # dimension of X
n = 10000
NN = 1000
x = matrix(runif(n*p, -1, 1), nrow=n, ncol=p)
L = 12
Y1 = exp(0.1 * x[, 1] + 0.2 * x[, 2] + (x[, 1]))
Y0 = exp(0.1 * x[, 1] + 0.2 * x[, 2])
CX_gen = function (x){
epsilon = exp(rnorm(NN, 0, 1)) # L = 12
# epsilon = exp(rlogis(NN)) # L = 21
# epsilon = exp(log(-log(1-runif(NN)))) # L = 8
mean(apply(cbind(x * epsilon, L),1,min))
}
# runif(n, 0, 7) 25% # runif(n, 0, 12) #15% #normal
# runif(n, 0, 10) 25% # runif(n, 0, 21) #15% #logsitic
# runif(n, 0, 4) 25% # runif(n, 0, 8) #15% #extreme
CX_surv2 = apply(as.matrix(Y1), 1, CX_gen) - apply(as.matrix(Y0), 1, CX_gen)
set.seed(2333)
# calculate the true:
p = 10 # dimension of X
n = 10000
NN = 1000
x = matrix(runif(n*p, -1, 1), nrow=n, ncol=p)
L = 10
Y1 = exp(0.1 * x[, 1] + 0.2 * x[, 2] + (x[, 1]))
Y0 = exp(0.1 * x[, 1] + 0.2 * x[, 2])
CX_gen = function (x){
# epsilon = exp(rnorm(NN, 0, 1)) # L = 12
epsilon = exp(rlogis(NN)) # L = 21
# epsilon = exp(log(-log(1-runif(NN)))) # L = 8
mean(apply(cbind(x * epsilon, L),1,min))
}
# runif(n, 0, 7) 25% # runif(n, 0, 12) #15% #normal
# runif(n, 0, 10) 25% # runif(n, 0, 21) #15% #logsitic
# runif(n, 0, 4) 25% # runif(n, 0, 8) #15% #extreme
CX_surv3 = apply(as.matrix(Y1), 1, CX_gen) - apply(as.matrix(Y0), 1, CX_gen)
set.seed(2333)
# calculate the true:
p = 10 # dimension of X
n = 10000
NN = 1000
x = matrix(runif(n*p, -1, 1), nrow=n, ncol=p)
L = 21
Y1 = exp(0.1 * x[, 1] + 0.2 * x[, 2] + (x[, 1]))
Y0 = exp(0.1 * x[, 1] + 0.2 * x[, 2])
CX_gen = function (x){
# epsilon = exp(rnorm(NN, 0, 1)) # L = 12
epsilon = exp(rlogis(NN)) # L = 21
# epsilon = exp(log(-log(1-runif(NN)))) # L = 8
mean(apply(cbind(x * epsilon, L),1,min))
}
# runif(n, 0, 7) 25% # runif(n, 0, 12) #15% #normal
# runif(n, 0, 10) 25% # runif(n, 0, 21) #15% #logsitic
# runif(n, 0, 4) 25% # runif(n, 0, 8) #15% #extreme
CX_surv4 = apply(as.matrix(Y1), 1, CX_gen) - apply(as.matrix(Y0), 1, CX_gen)
set.seed(2333)
# calculate the true:
p = 10 # dimension of X
n = 10000
NN = 1000
x = matrix(runif(n*p, -1, 1), nrow=n, ncol=p)
L = 4
Y1 = exp(0.1 * x[, 1] + 0.2 * x[, 2] + (x[, 1]))
Y0 = exp(0.1 * x[, 1] + 0.2 * x[, 2])
CX_gen = function (x){
# epsilon = exp(rnorm(NN, 0, 1)) # L = 12
# epsilon = exp(rlogis(NN)) # L = 21
epsilon = exp(log(-log(1-runif(NN)))) # L = 8
mean(apply(cbind(x * epsilon, L),1,min))
}
# runif(n, 0, 7) 25% # runif(n, 0, 12) #15% #normal
# runif(n, 0, 10) 25% # runif(n, 0, 21) #15% #logsitic
# runif(n, 0, 4) 25% # runif(n, 0, 8) #15% #extreme
CX_surv5 = apply(as.matrix(Y1), 1, CX_gen) - apply(as.matrix(Y0), 1, CX_gen)
set.seed(2333)
# calculate the true:
p = 10 # dimension of X
n = 10000
NN = 1000
x = matrix(runif(n*p, -1, 1), nrow=n, ncol=p)
L = 8
Y1 = exp(0.1 * x[, 1] + 0.2 * x[, 2] + (x[, 1]))
Y0 = exp(0.1 * x[, 1] + 0.2 * x[, 2])
CX_gen = function (x){
# epsilon = exp(rnorm(NN, 0, 1)) # L = 12
# epsilon = exp(rlogis(NN)) # L = 21
epsilon = exp(log(-log(1-runif(NN)))) # L = 8
mean(apply(cbind(x * epsilon, L),1,min))
}
# runif(n, 0, 7) 25% # runif(n, 0, 12) #15% #normal
# runif(n, 0, 10) 25% # runif(n, 0, 21) #15% #logsitic
# runif(n, 0, 4) 25% # runif(n, 0, 8) #15% #extreme
CX_surv6 = apply(as.matrix(Y1), 1, CX_gen) - apply(as.matrix(Y0), 1, CX_gen)
CX_den <- density(CX_surv1) # returns the density data
CX_den2 <- density(CX_surv2) # returns the density data
CX_den3 <- density(CX_surv3) # returns the density data
CX_den4 <- density(CX_surv4) # returns the density data
CX_den5 <- density(CX_surv5) # returns the density data
CX_den6 <- density(CX_surv6) # returns the density data
pdf("S2_den.pdf")
plot(CX_den, main='', xlab='Restricted Mean Survival Time', col = 'blue', lty=1, xlim=c(-2,3), ylim = c(0,1.1))
lines(CX_den2, col = 'blue', lty=2)
lines(CX_den3, col = 'green', lty=1)
lines(CX_den4, col = 'green', lty=2)
lines(CX_den5, col = 'red', lty=1)
lines(CX_den6, col = 'red', lty=2)
legend("topright", legend=c('Normal with Censoring 25%','Normal with Censoring 15%',
'Log with Censoring 25%','Log with Censoring 15%',
'Extreme with Censoring 25%','Extreme with Censoring 15%'),
lty = c(1,2,1,2,1,2), col = c("blue","blue",'green','green', "red","red"))
dev.off()