Skip to content

Commit d56cd6d

Browse files
committed
Add more developer tests
1 parent 670401e commit d56cd6d

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

tests/testthat/test-developer-gs_design_ahr.R

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,99 @@ test_that("Pocock lower spending under H1 (NPH)", {
141141
expect_equal(x1$bound$z[x1$bound$bound == "lower"], x2$bounds$Z[x2$bounds$Bound == "Lower"])
142142
expect_equal(x1$bound$probability[x1$bound$bound == "lower"], x2$bounds$Probability[x2$bounds$Bound == "Lower"])
143143
})
144+
145+
test_that("Spending time when both efficacy and futility bound are fixed", {
146+
147+
x <- gs_design_ahr(alpha = 0.025,
148+
beta = 0.1,
149+
info_frac = 1:3/3, analysis_time = 36,
150+
upper = gs_b,
151+
upar = gsDesign::gsDesign(k = 3, test.type = 1, n.I = 1:3/3,
152+
sfu = gsDesign::sfLDOF, sfupar = NULL, alpha = 0.025)$upper$bound,
153+
lower = gs_b,
154+
lpar = rep(-Inf, 3))
155+
156+
expect_false("spending_time" %in% names(x$bound))
157+
})
158+
159+
test_that("Pre-specificed spending time", {
160+
161+
# one-sided design
162+
x <- gs_design_ahr(alpha = 0.025,
163+
beta = 0.1,
164+
info_frac = NULL, analysis_time = c(12, 24, 36),
165+
upper = gs_spending_bound,
166+
upar = list(sf = gsDesign::sfLDOF, timing = c(12, 24, 36) / 36, total_spend = 0.025),
167+
lower = gs_b,
168+
lpar = rep(-Inf, 3))
169+
170+
expect_equal(x$bound$spending_time, c(12, 24, 36) / 36)
171+
172+
# two-sided design
173+
x <- gs_design_ahr(alpha = 0.025,
174+
beta = 0.1,
175+
info_frac = NULL, analysis_time = c(12, 24, 36),
176+
upper = gs_spending_bound,
177+
upar = list(sf = gsDesign::sfLDOF, timing = c(12, 24, 36) / 36, total_spend = 0.025),
178+
lower = gs_spending_bound,
179+
lpar = list(sf = gsDesign::sfLDOF, timing = c(15, 24, 36) / 36, total_spend = 0.1))
180+
181+
expect_equal((x$bound |> filter(bound == "upper"))$spending_time, c(12, 24, 36) / 36)
182+
expect_equal((x$bound |> filter(bound == "lower"))$spending_time, c(15, 24, 36) / 36)
183+
})
184+
185+
test_that("Spending time when the analyses are driven by information fraction", {
186+
# one-sided design
187+
x <- gs_design_ahr(alpha = 0.025,
188+
beta = 0.1,
189+
info_frac = 1:3/3, analysis_time = 36,
190+
upper = gs_spending_bound,
191+
upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025),
192+
lower = gs_b,
193+
lpar = rep(-Inf, 3))
194+
195+
expect_equal(x$bound$spending_time, 1:3/3)
196+
197+
# two-sided design with futility bound spending under H1
198+
x <- gs_design_ahr(alpha = 0.025,
199+
beta = 0.1,
200+
info_frac = 1:3/3, analysis_time = 36,
201+
upper = gs_spending_bound,
202+
upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025),
203+
lower = gs_spending_bound,
204+
lpar = list(sf = gsDesign::sfHSD, total_spend = 0.1, param = 3),
205+
h1_spending = TRUE)
206+
207+
expect_equal((x$bound |> filter(bound == "upper"))$spending_time, 1:3/3)
208+
expect_equal((x$bound |> filter(bound == "lower"))$spending_time, x$analysis$info / max(x$analysis$info))
209+
210+
# two-sided design with futility bound spending under H0
211+
x <- gs_design_ahr(alpha = 0.025,
212+
beta = 0.1,
213+
info_frac = 1:3/3, analysis_time = 36,
214+
upper = gs_spending_bound,
215+
upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025),
216+
lower = gs_spending_bound,
217+
lpar = list(sf = gsDesign::sfHSD, total_spend = 0.1, param = 3),
218+
h1_spending = FALSE)
219+
220+
expect_equal((x$bound |> filter(bound == "upper"))$spending_time, 1:3/3)
221+
expect_equal((x$bound |> filter(bound == "lower"))$spending_time, x$analysis$info0 / max(x$analysis$info0))
222+
})
223+
224+
test_that("Spending time when some analyses are skipped", {
225+
226+
# two-sided design with futility bound spending under H1
227+
x <- gs_design_ahr(alpha = 0.025,
228+
beta = 0.1,
229+
info_frac = 1:3/3, analysis_time = 36,
230+
upper = gs_spending_bound,
231+
upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025),
232+
lower = gs_spending_bound,
233+
lpar = list(sf = gsDesign::sfHSD, total_spend = 0.1, param = 3),
234+
h1_spending = TRUE,
235+
test_lower = c(FALSE, TRUE, TRUE))
236+
237+
expect_equal((x$bound |> filter(bound == "upper"))$spending_time, 1:3/3)
238+
expect_equal((x$bound |> filter(bound == "lower"))$spending_time, x$analysis$info[2:3] / max(x$analysis$info))
239+
})

tests/testthat/test-developer-summary.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,12 @@ test_that("summary.gs_design() accepts a named vector for col_decimals", {
287287
"'col_decimals' must be a named vector if 'col_vars' is not provided"
288288
)
289289
})
290+
291+
# Output of spending time
292+
test_that("summary.gs_design() outputs spending time correctly", {
293+
x <- gs_design_ahr(info_frac = 1:3/3) |> summary(display_spending_time = TRUE)
294+
expect_true("Spending time" %in% names(x))
295+
296+
x <- gs_design_ahr(info_frac = 1:3/3) |> summary(display_spending_time = FALSE)
297+
expect_false("Spending time" %in% names(x))
298+
})

0 commit comments

Comments
 (0)