-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditive_boundary_functions.R
238 lines (227 loc) · 7.38 KB
/
additive_boundary_functions.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
# Boundary function for the first subfamily
## Input
### x: boundary value to be solved
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Difference between alpha and the actual type I error
boundary_F1_function <- function(x, alpha, t, gamma){
if (gamma < 0.5 | gamma >= 1) {
stop("gamma should be between [0.5, 1)")
} else {
K <- length(t)
cr <- cr_function(t)
y <- 1 - alpha - pmvnorm(upper = (x - qnorm(1 - gamma) * sqrt(1 - t)) / sqrt(t),
corr = cr, algorithm = Miwa(steps = 128))
return(y)
}
}
# Boundary function for the second subfamily
## Input
### x: boundary value to be solved
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Difference between alpha and the actual type I error
boundary_F2_function <- function(x, alpha, t, gamma){
if (gamma < 1 - pnorm(qnorm(1 - alpha / 2) / 2) | gamma >= 1) {
stop(paste0("gamma should be between (",
round(1 - pnorm(qnorm(1 - alpha / 2)/2), 3), ", 1)"))
} else {
K <- length(t)
cr <- cr_function(t)
y <- 1 - alpha - pmvnorm(upper = (x - qnorm(1 - gamma) * (1 - t)) / sqrt(t),
corr = cr, algorithm = Miwa(steps = 128))
return(y)
}
}
# Boundary function for the third subfamily
## Input
### x: boundary value to be solved
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Difference between alpha and the actual type I error
boundary_F3_function <- function(x, alpha, t, gamma){
if (gamma <= alpha / 2 | gamma >= 1) {
stop(paste0("gamma should be between (", alpha / 2, ", 1)"))
} else {
K <- length(t)
cr <- cr_function(t)
y <- 1 - alpha - pmvnorm(upper = (x - qnorm(1 - gamma) * (1 - sqrt(t))) / sqrt(t),
corr = cr, algorithm = Miwa(steps = 128))
return(y)
}
}
# Boundary function for the combined subfamily of the first and the second subfamilies
## Input
### x: boundary value to be solved
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Difference between alpha and the actual type I error
boundary_combine_function <- function(x, alpha, t, gamma){
if (gamma < 1 - pnorm(qnorm(1 - alpha / 2) / 2) | gamma >= 1) {
stop(paste0("gamma should be between (",
round(1 - pnorm(qnorm(1 - alpha / 2)/2), 3), ", 1)"))
} else {
K <- length(t)
cr <- cr_function(t)
if (gamma >= 0.5 & gamma < 1) {
y <- 1 - alpha - pmvnorm(upper = (x - qnorm(1 - gamma) * sqrt(1 - t)) / sqrt(t),
corr = cr, algorithm = Miwa(steps = 128))
} else {
y <- 1 - alpha - pmvnorm(upper = (x - qnorm(1 - gamma) * (1 - t)) / sqrt(t),
corr = cr, algorithm = Miwa(steps = 128))
}
return(y)
}
}
# Error spending function for the first subfamily
## Input
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Vector of cumulative error spent
esf_F1_function <- function(alpha, t, gamma) {
if (gamma < 0.5 | gamma >= 1) {
stop("gamma should be between [0.5, 1)")
} else {
y <- 2 - 2 * pnorm((qnorm(1 - alpha / 2) -
qnorm(1 - gamma) * sqrt(1 - t)) / sqrt(t))
return(y)
}
}
# Error spending function for the second subfamily
## Input
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Vector of cumulative error spent
esf_F2_function <- function(alpha, t, gamma) {
if (gamma < 1 - pnorm(qnorm(1 - alpha / 2) / 2) | gamma >= 1) {
stop(paste0("gamma should be between (",
round(1 - pnorm(qnorm(1 - alpha / 2)/2), 3), ", 1)"))
} else {
y <- 2 - 2 * pnorm((qnorm(1 - alpha / 2) -
qnorm(1 - gamma) * (1 - t)) / sqrt(t))
return(y)
}
}
# Error spending function for the combined subfamily of the first and the second subfamilies
## Input
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Vector of cumulative error spent
esf_combine_function <- function(alpha, t, gamma) {
if (gamma < 1 - pnorm(qnorm(1 - alpha / 2) / 2) | gamma >= 1) {
stop(paste0("gamma should be between (",
round(1 - pnorm(qnorm(1 - alpha / 2)/2), 3), ", 1)"))
} else {
if (gamma < 0.5) {
y <- 2 - 2 * pnorm((qnorm(1 - alpha / 2) -
qnorm(1 - gamma) * (1 - t)) / sqrt(t))
} else {
y <- 2 - 2 * pnorm((qnorm(1 - alpha / 2) -
qnorm(1 - gamma) * sqrt(1 - t)) / sqrt(t))
}
return(y)
}
}
# Error spending function for the third subfamily
## Input
### alpha: one-sided significance level
### t: information time
### gamma: parameter gamma
## Output
### Vector of cumulative error spent
esf_F3_function <- function(alpha, t, gamma) {
if (gamma <= alpha / 2 | gamma >= 1) {
stop(paste0("gamma should be between (", alpha / 2, ", 1)"))
} else {
y <- 2 - 2 * pnorm((qnorm(1 - alpha / 2) -
qnorm(1 - gamma) * (1 - sqrt(t))) / sqrt(t))
return(y)
}
}
# Error spending function for the Pocock Lan-DeMets design
## Input
### alpha: one-sided significance level
### t: information time
## Output
### Vector of cumulative error spent
esf_Pocock_function <- function(alpha, t) {
y <- alpha * log(1 + (exp(1) - 1) * t)
return(y)
}
# Error spending function for the power family
## Input
### alpha: one-sided significance level
### t: information time
### rho: parameter rho
## Output
### Vector of cumulative error spent
esf_power_function <- function(alpha, t, rho) {
y <- alpha * t^rho
return(y)
}
#########################################################################
# Example call for Table 1
alpha <- 0.025
t <- c(0.25, 0.5, 0.75, 1)
gamma <- 0.6
# Boundary approach
c_boundary <- uniroot(boundary_F1_function, interval = c(0.001, 10), alpha = alpha,
t = t, gamma = gamma)$root
a <- c_boundary / sqrt(t) - qnorm(1 - gamma) * sqrt(1 - t) / sqrt(t)
round(a, 3)
b <- CE_function(t, a)
round(b, 3)
# Error spending function approach
cumulative <- esf_F1_function(alpha, t, gamma)
a <- solver_boundary_esf_function(alpha, t, cumulative)
round(a, 3)
b <- CE_function(t, a)
round(b, 3)
#########################################################################
# Example call for Table 4
alpha <- 0.025
t <- c(0.2, 0.4, 0.6, 0.8, 1)
# For gamma >= 0.5
gamma <- 0.5
# Boundary approach
c_boundary <- uniroot(boundary_combine_function, interval = c(0.001, 10), alpha = alpha,
t = t, gamma = gamma)$root
a <- c_boundary / sqrt(t) - qnorm(1 - gamma) * sqrt(1 - t) / sqrt(t)
round(a, 3)
b <- CE_function(t, a)
round(b, 3)
# Error spending function approach
cumulative <- esf_combine_function(alpha, t, gamma)
a <- solver_boundary_esf_function(alpha, t, cumulative)
round(a, 3)
b <- CE_function(t, a)
round(b, 3)
# For gamma < 0.5
gamma <- 0.2
# Boundary approach
c_boundary <- uniroot(boundary_combine_function, interval = c(0.001, 10), alpha = alpha,
t = t, gamma = gamma)$root
a <- c_boundary / sqrt(t) - qnorm(1 - gamma) * (1 - t) / sqrt(t)
round(a, 3)
b <- CE_function(t, a)
round(b, 3)
# Error spending function approach
cumulative <- esf_combine_function(alpha, t, gamma)
a <- solver_boundary_esf_function(alpha, t, cumulative)
round(a, 3)
b <- CE_function(t, a)
round(b, 3)