Skip to content

Commit 8f1a3a3

Browse files
authored
Merge pull request #143 from keaven/136-independent-testing-of-gsbinomialexact
Expand tests for `gsBinomialExact()`
2 parents 5ec0400 + 6fb335d commit 8f1a3a3

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

tests/testthat/test-independent-test-gsBinomialExact.R

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,50 @@ testthat::test_that("Test gsBinomialExact for n.I and vector-b for increasing or
209209
})
210210

211211

212+
### Test gsBinomialExact for properly increasing n.I
213+
testthat::test_that("Test gsBinomialExact for properly increasing n.I", code = {
214+
testthat::expect_error(gsBinomialExact(
215+
k = 2, theta = c(.1, .2), n.I = c(50, 50),
216+
a = c(3, 7), b = c(20, 30)
217+
),
218+
info = "Checking properly increasing n.I"
219+
)
220+
})
221+
222+
### Test gsBinomialExact for b greater than a
223+
testthat::test_that("Test gsBinomialExact for b greater than a", code = {
224+
testthat::expect_error(gsBinomialExact(
225+
k = 2, theta = c(.1, .2), n.I = c(50, 100),
226+
a = c(25, 50), b = c(15, 40)
227+
),
228+
info = "Checking for b greater than a"
229+
)
230+
})
231+
232+
### Test gsBinomialExact for a being a non-decreasing sequence of non-negative integers
233+
testthat::test_that("Test gsBinomialExact for a being a non-decreasing sequence of non-negative integers", code = {
234+
testthat::expect_error(gsBinomialExact(
235+
k = 2, theta = c(.1, .2), n.I = c(50, 100),
236+
a = c(25, 20), b = c(30, 40)
237+
),
238+
info = "Checking a for being a non-decreasing sequence of non-negative integers"
239+
)
240+
})
241+
242+
### Test gsBinomialExact for n.I - b being a non-decreasing sequence
243+
testthat::test_that("Test gsBinomialExact for n.I - b being a non-decreasing sequence", code = {
244+
testthat::expect_error(gsBinomialExact(
245+
k = 2, theta = c(.1, .2), n.I = c(50, 100),
246+
a = c(3, 7), b = c(25, 100)
247+
),
248+
info = "Checking for n.I - b being a non-decreasing sequence"
249+
)
250+
})
251+
212252

213253
# Test gsBinomial Exact for upper efficacy boundary crossing probabilities: Benchmark values have been obtained from East 6.5
214254
testthat::test_that(
215-
desc = "Test gsBinomial Exact for upper efficacy bounday crossing probabilities :
255+
desc = "Test gsBinomial Exact for upper efficacy boundary crossing probabilities :
216256
Benchmark values have been obtained from East 6.5 : BinomialExact-01.html",
217257
code = {
218258
x <- gsBinomialExact(
@@ -252,9 +292,9 @@ testthat::test_that(
252292
)
253293

254294

255-
# Test gsBinomial Exact for lower futility bounday crossing probabilities : Benchmark values have been obtained from East 6.5
295+
# Test gsBinomial Exact for lower futility boundary crossing probabilities : Benchmark values have been obtained from East 6.5
256296
testthat::test_that(
257-
desc = "Test gsBinomial Exact for lower futility bounday crossing probabilities :
297+
desc = "Test gsBinomial Exact for lower futility boundary crossing probabilities :
258298
Benchmark values have been obtained from East 6.5 : BinomialExact-02.html",
259299
code = {
260300
x <- gsBinomialExact(
@@ -294,10 +334,10 @@ testthat::test_that(
294334
)
295335

296336

297-
# Test gsBinomial Exact for lower futility & upper efficacy bounday crossing
337+
# Test gsBinomial Exact for lower futility & upper efficacy boundary crossing
298338
# probabilities : Benchmark values have been obtained from East 6.5
299339
testthat::test_that(
300-
desc = "Test gsBinomial Exact for lower futility & upper efficacy bounday crossing
340+
desc = "Test gsBinomial Exact for lower futility & upper efficacy boundary crossing
301341
probabilities : Benchmark values have been obtained from East 6.5 :BinomialExact-03.html",
302342
code = {
303343
x <- gsBinomialExact(
@@ -378,3 +418,31 @@ testthat::test_that(
378418
}
379419
)
380420

421+
### Test binomialPP by comparing with gsBinomialExact
422+
testthat::test_that("Testing binomialPP by comparing with gsBinomialExact", {
423+
a <- 0.2
424+
b <- 0.8
425+
theta <- c(0.2, 0.4)
426+
p1 <- 0.4
427+
PP <- c(0.025, 0.95)
428+
nIA <- c(50, 100)
429+
upper <- nIA + 1
430+
lower <- rep(-1, length(nIA))
431+
j <- 1
432+
for (i in nIA) {
433+
q <- 0:i
434+
post <- stats::pbeta(p1, a + q, b + i - q, lower.tail = F)
435+
upper[j] <- sum(post < PP[2])
436+
lower[j] <- sum(post <= PP[1])
437+
j <- j + 1
438+
}
439+
440+
ns <- binomialPP(a = a, b = b, theta = theta, p1 = p1, PP = PP, nIA = nIA)
441+
442+
nz <- gsBinomialExact(k = 2, theta = theta, a = lower, b = upper, n.I = nIA)
443+
444+
testthat::expect_equal(ns$lower$bound, nz$lower$bound, info = "Checking lower bound")
445+
testthat::expect_equal(ns$lower$prob, nz$lower$prob, info = "Checking lower probability")
446+
testthat::expect_equal(ns$upper$bound, nz$upper$bound, info = "Checking upper bound")
447+
testthat::expect_equal(ns$upper$prob, nz$upper$prob, info = "Checking upper probability")
448+
})

0 commit comments

Comments
 (0)