Skip to content

Commit

Permalink
add test for to_integer.fixed_design
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleBeannie committed Nov 13, 2024
1 parent 58c950e commit c6d26ec
Showing 1 changed file with 126 additions and 14 deletions.
140 changes: 126 additions & 14 deletions tests/testthat/test-developer-to_integer.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,92 @@ test_that("The statistcial information under null equals to event/4 udner equal
expect_true(all(x$analysis$info0 - x$analysis$event / 4 == 0))
})

test_that("Validate the sample size rounding under equal randomization for TTE endpoint.", {
test_that("Validate the sample size rounding under equal randomization (1:1) for TTE endpoint. -- GSD", {

x <- gs_design_ahr(analysis_time = c(24, 36))

# ----------------------- #
# round_up_final = TRUE #
# ----------------------- #
y1 <- x |> to_integer(round_up_final = TRUE)
y2 <- x |> to_integer(round_up_final = FALSE)

# test the sample size at FA is rounded up and multiple of 2
expect_equal(ceiling(x$analysis$n[2] / 2) * 2, y1$analysis$n[2])
# test the event at FA is rounded up
expect_equal(ceiling(x$analysis$event[2]), y1$analysis$event[2])
# test the event at IA is rounded
expect_equal(round(x$analysis$event[1], 0), y1$analysis$event[1])


# ----------------------- #
# round_up_final = FALSE #
# ----------------------- #
y2 <- x |> to_integer(round_up_final = FALSE)
# test the sample size at FA is rounded up and multiple of 2
expect_equal(round(x$analysis$n[2] / 2, 0) * 2, y2$analysis$n[2])
# test the event at FA is rounded
expect_equal(round(x$analysis$event[2], 0), y2$analysis$event[2])
# test the event at IA is rounded
expect_equal(round(x$analysis$event[1], 0), y2$analysis$event[1])

expect_error(x |> to_integer(ratio = -2))
})

test_that("Validate the sample size rounding under unequal randomization (3:2) for TTE endpoint.", {
test_that("Validate the sample size rounding under unequal randomization (3:2) for TTE endpoint. -- GSD", {

x <- gs_design_ahr(analysis_time = c(24, 36), ratio = 1.5,
alpha = 0.025,
upper = gs_spending_bound,
upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025))

# ceiling the sample size at FA, but may not be a multiplier of 5
# ---------------------------------------------- #
# round_up_final = TRUE & ratio is NOT integer #
# ---------------------------------------------- #
y1 <- x |> to_integer(round_up_final = TRUE)
# test the FA sample size is rounded up, but may not be a multiplier of 5
expect_equal(ceiling(x$analysis$n[2]), y1$analysis$n[2])

# ceiling the sample size at FA, and is a multiplier of 5
# test the FA events is rounded up
expect_equal(ceiling(x$analysis$event[2]), y1$analysis$event[2])
# test the IA events is rounded
expect_equal(round(x$analysis$event[1], 0), y1$analysis$event[1])

# ---------------------------------------------- #
# round_up_final = TRUE & ratio is integer #
# ---------------------------------------------- #
y2 <- x |> to_integer(round_up_final = TRUE, ratio = 4)
# test the FA sample size is round up, and is a multiplier of 5
expect_equal(ceiling(x$analysis$n[2] / 5) * 5, y2$analysis$n[2])

# round the sample size at FA, but may not a multiplier of 5
# test the FA events is rounded up
expect_equal(ceiling(x$analysis$event[2]), y2$analysis$event[2])
# test the IA events is rounded
expect_equal(round(x$analysis$event[1], 0), y2$analysis$event[1])

# ---------------------------------------------- #
# round_up_final = FALSE & ratio is NOT integer #
# ---------------------------------------------- #
y3 <- x |> to_integer(round_up_final = FALSE)
# test the sample size at FA is rounded, but may not a multiplier of 5
expect_equal(round(x$analysis$n[2]), y3$analysis$n[2])

# round the sample size at FA, and is a multiplier of 5
# test the FA events is rounded
expect_equal(round(x$analysis$event[2], 0), y2$analysis$event[2])
# test the IA events is rounded
expect_equal(round(x$analysis$event[1], 0), y2$analysis$event[1])

# ---------------------------------------------- #
# round_up_final = FALSE & ratio is integer #
# ---------------------------------------------- #
y4 <- x |> to_integer(round_up_final = FALSE, ratio = 4)
# test the FA sample size is rounded, but may not is a multiplier of 5
expect_equal(round(x$analysis$n[2] / 5, 0) * 5, y4$analysis$n[2])
# test the FA events is rounded
expect_equal(round(x$analysis$event[2], 0), y2$analysis$event[2])
# test the IA events is rounded
expect_equal(round(x$analysis$event[1], 0), y2$analysis$event[1])

# error when ratio is negative
expect_error(x |> to_integer(ratio = -2))
})


test_that("Validate the sample size rounding for binary endpoint under equal randomization.", {
test_that("Validate the sample size rounding under equal randomization (1:1) for binary endpoint. -- GSD", {

x <- gs_design_rd(ratio = 1,
alpha = 0.025,
Expand All @@ -109,7 +154,7 @@ test_that("Validate the sample size rounding for binary endpoint under equal ran
expect_error(x |> to_integer(ratio = -2))
})

test_that("Validate the sample size rounding for binary endpoint under unequal randomization (3:2).", {
test_that("Validate the sample size rounding under unequal randomization (3:2) for binary endpoint. -- GSD", {

x <- gs_design_rd(ratio = 1.5,
alpha = 0.025,
Expand All @@ -136,3 +181,70 @@ test_that("Validate the sample size rounding for binary endpoint under unequal r
# error when ratio is negative
expect_error(x |> to_integer(ratio = -2))
})

test_that("Validate the sample size rounding under equal randomization (1:1) for TTE endpoint -- fixed design.", {

x <- fixed_design_ahr(alpha = .025, power = .9, ratio = 1,
enroll_rate = define_enroll_rate(duration = 18, rate = 1),
fail_rate = define_fail_rate(duration = c(4, 100),
fail_rate = log(2) / 10, hr = c(1, .6),
dropout_rate = .001),
study_duration = 36)

y1 <- x |> to_integer(round_up_final = TRUE)
y2 <- x |> to_integer(round_up_final = FALSE)

expect_equal(ceiling(x$analysis$n / 2) * 2, y1$analysis$n)
expect_equal(round(x$analysis$n / 2, 0) * 2, y2$analysis$n)

expect_error(x |> to_integer(ratio = -2))
})

test_that("Validate the sample size rounding under unequal randomization (3:2) for TTE endpoint.", {

x <- fixed_design_ahr(alpha = .025, power = .9, ratio = 1.5,
enroll_rate = define_enroll_rate(duration = 18, rate = 1),
fail_rate = define_fail_rate(duration = c(4, 100),
fail_rate = log(2) / 10, hr = c(1, .6),
dropout_rate = .001),
study_duration = 36)

# ---------------------------------------------- #
# round_up_final = TRUE & ratio is NOT integer #
# ---------------------------------------------- #
y1 <- x |> to_integer(round_up_final = TRUE)
# test the sample size is rounded up, but may not be a multiplier of 5
expect_equal(ceiling(x$analysis$n), y1$analysis$n)
# test the event is rounded up
expect_equal(ceiling(x$analysis$event), y1$analysis$event)

# ---------------------------------------------- #
# round_up_final = TRUE & ratio is integer #
# ---------------------------------------------- #
y2 <- x |> to_integer(round_up_final = TRUE, ratio = 4)
# test the sample size is rounded up, and is a multiplier of 5
expect_equal(ceiling(x$analysis$n / 5) * 5, y2$analysis$n)
# test the event is rounded up
expect_equal(ceiling(x$analysis$event), y2$analysis$event)

# ---------------------------------------------- #
# round_up_final = FALSE & ratio is NOT integer #
# ---------------------------------------------- #
y3 <- x |> to_integer(round_up_final = FALSE)
# test the sample size is rounded, but may not a multiplier of 5
expect_equal(round(x$analysis$n), y3$analysis$n)
# test the event is rounded
expect_equal(round(x$analysis$event, 0), y3$analysis$event)

# ---------------------------------------------- #
# round_up_final = FALSE & ratio is integer #
# ---------------------------------------------- #
y4 <- x |> to_integer(round_up_final = FALSE, ratio = 4)
# test the sample size is rounded, and is a multiplier of 5
expect_equal(round(x$analysis$n / 5, 0) * 5, y4$analysis$n)
# test the event is rounded
expect_equal(ceiling(x$analysis$event), y4$analysis$event)

# error when ratio is negative
expect_error(x |> to_integer(ratio = -2))
})

0 comments on commit c6d26ec

Please sign in to comment.