From a649dc7bdba867f339fcd68c4fa2239b837f2734 Mon Sep 17 00:00:00 2001 From: wanjau_merck Date: Tue, 9 Jul 2024 11:49:39 -0400 Subject: [PATCH 1/9] test fo ahr_blinded.R --- tests/testthat/test-independent-ahr_blinded.R | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/testthat/test-independent-ahr_blinded.R diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R new file mode 100644 index 00000000..762ecc1a --- /dev/null +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -0,0 +1,30 @@ + +test_that("hr vector must be a vector of positive numbers", { + expect_error(ahr_blinded(hr = c(1, -2, 3)), "ahr_blinded: hr must be a vector of positive numbers.") + expect_error(ahr_blinded(hr = "abc"), "ahr_blinded: hr must be a vector of positive numbers.") +}) + +test_that("Piecewise model hr and intervals must be aligned", { + expect_error(ahr_blinded(hr = c(1, 2, 4), intervals = 3), "ahr_blinded: the piecewise model specified hr and intervals are not aligned.") + expect_error(ahr_blinded(hr = c(1, 3), intervals = c(3, 4)), "ahr_blinded: the piecewise model specified hr and intervals are not aligned.") +}) + +test_that("Correct computation of blinded AHR and information adjustment", { + surv <- survival::Surv(simtrial::ex2_delayed_effect$month, event = simtrial::ex2_delayed_effect$evntd) + intervals <- c(3, Inf) + hr <- c(1, 0.6) + ratio <- 1 + event<- simtrial::fit_pwexp(surv, intervals)[, 3] + + expected_event <- sum(surv[, "status"]) + expected_theta <- -sum(log(hr[1:length(event)]) * event) / sum(event) + expected_ahr <- exp(-(-sum(log(hr[1:length(event)]) * event) / sum(event))) + expected_info0 <- sum(surv[, "status"]) * (1 - ratio / (1 + ratio)) * (ratio / (1 + ratio)) + + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) + + expect_equal(result$event, expected_event) + expect_equal(result$ahr, expected_ahr, tolerance = 0.001) + expect_equal(result$theta, expected_theta, tolerance = 0.001) + expect_equal(result$info0, expected_info0) +}) From 29a43d9c4d11f9c8a51ea7de36a41785f4da2042 Mon Sep 17 00:00:00 2001 From: wanjau_merck Date: Tue, 9 Jul 2024 11:57:59 -0400 Subject: [PATCH 2/9] test fo ahr_blinded.R --- tests/testthat/test-independent-ahr_blinded.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index 762ecc1a..d3c7d843 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -1,4 +1,3 @@ - test_that("hr vector must be a vector of positive numbers", { expect_error(ahr_blinded(hr = c(1, -2, 3)), "ahr_blinded: hr must be a vector of positive numbers.") expect_error(ahr_blinded(hr = "abc"), "ahr_blinded: hr must be a vector of positive numbers.") From bb9a8a738ce0e04654c390de62bfd231207b0505 Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Fri, 2 Aug 2024 14:00:44 -0400 Subject: [PATCH 3/9] Style `ahr_blinded()` tests with styler --- tests/testthat/test-independent-ahr_blinded.R | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index d3c7d843..a5401e35 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -1,29 +1,44 @@ test_that("hr vector must be a vector of positive numbers", { - expect_error(ahr_blinded(hr = c(1, -2, 3)), "ahr_blinded: hr must be a vector of positive numbers.") - expect_error(ahr_blinded(hr = "abc"), "ahr_blinded: hr must be a vector of positive numbers.") + expect_error( + ahr_blinded(hr = c(1, -2, 3)), + "ahr_blinded: hr must be a vector of positive numbers." + ) + expect_error( + ahr_blinded(hr = "abc"), + "ahr_blinded: hr must be a vector of positive numbers." + ) }) test_that("Piecewise model hr and intervals must be aligned", { - expect_error(ahr_blinded(hr = c(1, 2, 4), intervals = 3), "ahr_blinded: the piecewise model specified hr and intervals are not aligned.") - expect_error(ahr_blinded(hr = c(1, 3), intervals = c(3, 4)), "ahr_blinded: the piecewise model specified hr and intervals are not aligned.") + expect_error( + ahr_blinded(hr = c(1, 2, 4), intervals = 3), + "ahr_blinded: the piecewise model specified hr and intervals are not aligned." + ) + expect_error( + ahr_blinded(hr = c(1, 3), intervals = c(3, 4)), + "ahr_blinded: the piecewise model specified hr and intervals are not aligned." + ) }) test_that("Correct computation of blinded AHR and information adjustment", { - surv <- survival::Surv(simtrial::ex2_delayed_effect$month, event = simtrial::ex2_delayed_effect$evntd) - intervals <- c(3, Inf) - hr <- c(1, 0.6) - ratio <- 1 - event<- simtrial::fit_pwexp(surv, intervals)[, 3] + surv <- survival::Surv( + simtrial::ex2_delayed_effect$month, + event = simtrial::ex2_delayed_effect$evntd + ) + intervals <- c(3, Inf) + hr <- c(1, 0.6) + ratio <- 1 + event <- simtrial::fit_pwexp(surv, intervals)[, 3] - expected_event <- sum(surv[, "status"]) - expected_theta <- -sum(log(hr[1:length(event)]) * event) / sum(event) - expected_ahr <- exp(-(-sum(log(hr[1:length(event)]) * event) / sum(event))) - expected_info0 <- sum(surv[, "status"]) * (1 - ratio / (1 + ratio)) * (ratio / (1 + ratio)) + expected_event <- sum(surv[, "status"]) + expected_theta <- -sum(log(hr[1:length(event)]) * event) / sum(event) + expected_ahr <- exp(-(-sum(log(hr[1:length(event)]) * event) / sum(event))) + expected_info0 <- sum(surv[, "status"]) * (1 - ratio / (1 + ratio)) * (ratio / (1 + ratio)) - result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) - expect_equal(result$event, expected_event) - expect_equal(result$ahr, expected_ahr, tolerance = 0.001) - expect_equal(result$theta, expected_theta, tolerance = 0.001) - expect_equal(result$info0, expected_info0) + expect_equal(result$event, expected_event) + expect_equal(result$ahr, expected_ahr, tolerance = 0.001) + expect_equal(result$theta, expected_theta, tolerance = 0.001) + expect_equal(result$info0, expected_info0) }) From c4ef49a6b81899f977a910584939e7a2fab187e6 Mon Sep 17 00:00:00 2001 From: wanjau_merck Date: Mon, 19 Aug 2024 14:29:01 -0400 Subject: [PATCH 4/9] Fix test for ahr_blinded.R --- tests/testthat/test-independent-ahr_blinded.R | 67 ++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index a5401e35..e9942e9b 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -1,4 +1,4 @@ -test_that("hr vector must be a vector of positive numbers", { +test_that("ahr_blinded throws an error for non-numeric or negative hr", { expect_error( ahr_blinded(hr = c(1, -2, 3)), "ahr_blinded: hr must be a vector of positive numbers." @@ -9,26 +9,56 @@ test_that("hr vector must be a vector of positive numbers", { ) }) -test_that("Piecewise model hr and intervals must be aligned", { - expect_error( - ahr_blinded(hr = c(1, 2, 4), intervals = 3), - "ahr_blinded: the piecewise model specified hr and intervals are not aligned." - ) - expect_error( - ahr_blinded(hr = c(1, 3), intervals = c(3, 4)), - "ahr_blinded: the piecewise model specified hr and intervals are not aligned." - ) +test_that("ahr_blinded throws an error when intervals and hr are not aligned", { + expect_error(ahr_blinded(intervals = c(3, 6), hr = c(1)), + "ahr_blinded: the piecewise model specified hr and intervals are not aligned.") +}) + +test_that("ahr_blinded handles piecewise exponential model fitting and calculations correctly", { + surv <- Surv(time = simtrial::ex1_delayed_effect$month, + event = simtrial::ex1_delayed_effect$evntd) + intervals <- c(3, 6, Inf) + hr <- c(1, 0.7, 0.5) + ratio <- 2 + + # Run the function + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) + + # Test 1: Correct fitting of survival data into piecewise exponential model + event <- simtrial::fit_pwexp(surv, intervals)[, 3] + expect_length(event, length(intervals)) + expect_true(all(event >= 0)) + + # Test 2: Hazard ratio vector is correctly extended + nhr <- length(hr) + nx <- length(event) + if (length(hr) < length(event)) { + hr <- c(hr, rep(hr[nhr], nx - nhr)) + } + expect_equal(length(hr), length(event)) + expect_equal(hr, c(1, 0.7, 0.5)) # Expected extended hr vector + + # Test 3: Blinded AHR (theta) is computed correctly + theta <- -sum(log(hr[1:nx]) * event) / sum(event) + expect_true(!is.na(theta)) + + # Test 4: Information adjustment (q_e) is computed correctly + q_e <- ratio / (1 + ratio) + expect_equal(q_e, 2 / 3) + + # Check the overall result + expect_true(inherits(result, "tbl_df")) + expect_equal(result$event, sum(event)) + expect_equal(result$theta, theta) + expect_equal(result$ahr, exp(-theta)) }) test_that("Correct computation of blinded AHR and information adjustment", { - surv <- survival::Surv( - simtrial::ex2_delayed_effect$month, - event = simtrial::ex2_delayed_effect$evntd - ) + surv <- survival::Surv(simtrial::ex2_delayed_effect$month, event = simtrial::ex2_delayed_effect$evntd) intervals <- c(3, Inf) hr <- c(1, 0.6) ratio <- 1 - event <- simtrial::fit_pwexp(surv, intervals)[, 3] + event<- simtrial::fit_pwexp(surv, intervals)[, 3] expected_event <- sum(surv[, "status"]) expected_theta <- -sum(log(hr[1:length(event)]) * event) / sum(event) @@ -42,3 +72,10 @@ test_that("Correct computation of blinded AHR and information adjustment", { expect_equal(result$theta, expected_theta, tolerance = 0.001) expect_equal(result$info0, expected_info0) }) + +test_that("ahr_blinded returns a tibble with correct structure", { + result <- ahr_blinded() + expect_true(tibble::is_tibble(result)) + expect_named(result, c("event", "ahr", "theta", "info0")) + expect_true(nrow(result) == 1) +}) \ No newline at end of file From 3c430d0e9d8ea809d1944a0f9bc571ad428b598c Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Tue, 20 Aug 2024 11:39:04 -0400 Subject: [PATCH 5/9] Run styler --- tests/testthat/test-independent-ahr_blinded.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index e9942e9b..e49ce232 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -10,13 +10,17 @@ test_that("ahr_blinded throws an error for non-numeric or negative hr", { }) test_that("ahr_blinded throws an error when intervals and hr are not aligned", { - expect_error(ahr_blinded(intervals = c(3, 6), hr = c(1)), - "ahr_blinded: the piecewise model specified hr and intervals are not aligned.") + expect_error( + ahr_blinded(intervals = c(3, 6), hr = c(1)), + "ahr_blinded: the piecewise model specified hr and intervals are not aligned." + ) }) test_that("ahr_blinded handles piecewise exponential model fitting and calculations correctly", { - surv <- Surv(time = simtrial::ex1_delayed_effect$month, - event = simtrial::ex1_delayed_effect$evntd) + surv <- Surv( + time = simtrial::ex1_delayed_effect$month, + event = simtrial::ex1_delayed_effect$evntd + ) intervals <- c(3, 6, Inf) hr <- c(1, 0.7, 0.5) ratio <- 2 @@ -36,7 +40,7 @@ test_that("ahr_blinded handles piecewise exponential model fitting and calculati hr <- c(hr, rep(hr[nhr], nx - nhr)) } expect_equal(length(hr), length(event)) - expect_equal(hr, c(1, 0.7, 0.5)) # Expected extended hr vector + expect_equal(hr, c(1, 0.7, 0.5)) # Expected extended hr vector # Test 3: Blinded AHR (theta) is computed correctly theta <- -sum(log(hr[1:nx]) * event) / sum(event) @@ -58,7 +62,7 @@ test_that("Correct computation of blinded AHR and information adjustment", { intervals <- c(3, Inf) hr <- c(1, 0.6) ratio <- 1 - event<- simtrial::fit_pwexp(surv, intervals)[, 3] + event <- simtrial::fit_pwexp(surv, intervals)[, 3] expected_event <- sum(surv[, "status"]) expected_theta <- -sum(log(hr[1:length(event)]) * event) / sum(event) @@ -78,4 +82,4 @@ test_that("ahr_blinded returns a tibble with correct structure", { expect_true(tibble::is_tibble(result)) expect_named(result, c("event", "ahr", "theta", "info0")) expect_true(nrow(result) == 1) -}) \ No newline at end of file +}) From b228b36655ecd4f2f04f15a84e78b03459cd864a Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Tue, 20 Aug 2024 11:43:26 -0400 Subject: [PATCH 6/9] Use sentence case for error message --- R/ahr_blinded.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ahr_blinded.R b/R/ahr_blinded.R index 691afe59..8dbb66dc 100644 --- a/R/ahr_blinded.R +++ b/R/ahr_blinded.R @@ -91,7 +91,7 @@ ahr_blinded <- function( stop("'intervals' must be a vector of positive numbers.") } if (length(intervals) != length(hr)) { - stop("the piecewise model specified 'hr' and 'intervals' differ in length.") + stop("The piecewise model specified 'hr' and 'intervals' differ in length.") } # Set final element of "intervals" to Inf From 8d893f6203538d4c81745701e7aa8fd514e286d5 Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Tue, 20 Aug 2024 11:43:47 -0400 Subject: [PATCH 7/9] Align error messages with latest actual --- tests/testthat/test-independent-ahr_blinded.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index e49ce232..af9cb4ca 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -1,18 +1,18 @@ test_that("ahr_blinded throws an error for non-numeric or negative hr", { expect_error( ahr_blinded(hr = c(1, -2, 3)), - "ahr_blinded: hr must be a vector of positive numbers." + "'hr' must be a vector of positive numbers." ) expect_error( ahr_blinded(hr = "abc"), - "ahr_blinded: hr must be a vector of positive numbers." + "'hr' must be a vector of positive numbers." ) }) test_that("ahr_blinded throws an error when intervals and hr are not aligned", { expect_error( ahr_blinded(intervals = c(3, 6), hr = c(1)), - "ahr_blinded: the piecewise model specified hr and intervals are not aligned." + "The piecewise model specified 'hr' and 'intervals' differ in length." ) }) From f171a69848f1c78416863d063900de49d9bf3433 Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Tue, 20 Aug 2024 12:28:08 -0400 Subject: [PATCH 8/9] Add more `ahr_blinded()` tests for specific edge cases and reasonable values --- tests/testthat/test-independent-ahr_blinded.R | 82 ++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index af9cb4ca..6783d38b 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -17,7 +17,7 @@ test_that("ahr_blinded throws an error when intervals and hr are not aligned", { }) test_that("ahr_blinded handles piecewise exponential model fitting and calculations correctly", { - surv <- Surv( + surv <- survival::Surv( time = simtrial::ex1_delayed_effect$month, event = simtrial::ex1_delayed_effect$evntd ) @@ -77,9 +77,85 @@ test_that("Correct computation of blinded AHR and information adjustment", { expect_equal(result$info0, expected_info0) }) -test_that("ahr_blinded returns a tibble with correct structure", { +test_that("ahr_blinded computes theta with constant hazard ratios correctly", { + surv <- survival::Surv( + simtrial::ex1_delayed_effect$month, + simtrial::ex1_delayed_effect$evntd + ) + intervals <- c(3, 6, Inf) + hr <- c(1, 1, 1) + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr) + + # When all hr = 1, theta should be 0 + expect_equal(result$theta, 0) +}) + +test_that("ahr_blinded handles zero events", { + surv <- survival::Surv(time = c(1, 2, 3, 4, 5), event = c(0, 0, 0, 0, 0)) # No events + intervals <- c(2, 3, Inf) + hr <- c(0.8, 0.9, 1) + + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr) + + expect_equal(result$event, 0) + expect_true(is.nan(result$ahr)) + expect_true(is.nan(result$theta)) + expect_equal(result$info0, 0) +}) + +test_that("ahr_blinded handles all events in the first interval", { + surv <- survival::Surv(time = c(1, 2, 2.5, 3, 3.5), event = c(1, 1, 1, 1, 1)) + # Only the first interval contains events + intervals <- c(4, Inf) + hr <- c(0.5, 0.7) + + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr) + + # All events are in the first interval, so result should reflect hr[1] + expected_theta <- -sum(log(hr[1]) * sum(surv[, "status"])) / sum(surv[, "status"]) + expect_equal(result$theta, expected_theta) + expect_equal(result$event, sum(surv[, "status"])) +}) + +test_that("ahr_blinded handles very small or very large hazard ratios", { + surv <- survival::Surv(time = c(1, 2, 3, 4, 5), event = c(1, 1, 1, 1, 1)) + intervals <- c(2, 3, Inf) + hr_small <- c(0.1, 0.2, 0.3) + hr_large <- c(10, 20, 30) + + res_hr_small <- ahr_blinded(surv = surv, intervals = intervals, hr = hr_small) + res_hr_large <- ahr_blinded(surv = surv, intervals = intervals, hr = hr_large) + + expect_true(res_hr_small$theta > 0) + expect_true(res_hr_small$ahr < 1) + + expect_true(res_hr_large$theta < 0) + expect_true(res_hr_large$ahr > 1) +}) + +test_that("ahr_blinded handles very high randomization ratio", { + surv <- survival::Surv(time = c(1, 2, 3, 4, 5), event = c(1, 1, 1, 1, 1)) + intervals <- c(2, 3, Inf) + hr <- c(0.8, 0.9, 0.95) + ratio <- 100 + + result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) + + q_e <- ratio / (1 + ratio) + # q_e should be close to 1 + expect_equal(q_e, 1, tolerance = 0.01) + # info0 should be near 0 + expect_equal(result$info0, 0, tolerance = 0.05) +}) + +test_that("ahr_blinded returns a tibble with correct structure and types", { result <- ahr_blinded() + expect_true(tibble::is_tibble(result)) expect_named(result, c("event", "ahr", "theta", "info0")) - expect_true(nrow(result) == 1) + expect_true(nrow(result) == 1L) + expect_type(result$event, "double") + expect_type(result$ahr, "double") + expect_type(result$theta, "double") + expect_type(result$info0, "double") }) From 1380950bacf3b41d5b61b83bf31f8af32ad5b089 Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Sun, 25 Aug 2024 17:47:34 -0400 Subject: [PATCH 9/9] Remove non-informative and unrealistic test cases --- tests/testthat/test-independent-ahr_blinded.R | 59 ++----------------- 1 file changed, 5 insertions(+), 54 deletions(-) diff --git a/tests/testthat/test-independent-ahr_blinded.R b/tests/testthat/test-independent-ahr_blinded.R index 6783d38b..6d52bb24 100644 --- a/tests/testthat/test-independent-ahr_blinded.R +++ b/tests/testthat/test-independent-ahr_blinded.R @@ -16,47 +16,6 @@ test_that("ahr_blinded throws an error when intervals and hr are not aligned", { ) }) -test_that("ahr_blinded handles piecewise exponential model fitting and calculations correctly", { - surv <- survival::Surv( - time = simtrial::ex1_delayed_effect$month, - event = simtrial::ex1_delayed_effect$evntd - ) - intervals <- c(3, 6, Inf) - hr <- c(1, 0.7, 0.5) - ratio <- 2 - - # Run the function - result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) - - # Test 1: Correct fitting of survival data into piecewise exponential model - event <- simtrial::fit_pwexp(surv, intervals)[, 3] - expect_length(event, length(intervals)) - expect_true(all(event >= 0)) - - # Test 2: Hazard ratio vector is correctly extended - nhr <- length(hr) - nx <- length(event) - if (length(hr) < length(event)) { - hr <- c(hr, rep(hr[nhr], nx - nhr)) - } - expect_equal(length(hr), length(event)) - expect_equal(hr, c(1, 0.7, 0.5)) # Expected extended hr vector - - # Test 3: Blinded AHR (theta) is computed correctly - theta <- -sum(log(hr[1:nx]) * event) / sum(event) - expect_true(!is.na(theta)) - - # Test 4: Information adjustment (q_e) is computed correctly - q_e <- ratio / (1 + ratio) - expect_equal(q_e, 2 / 3) - - # Check the overall result - expect_true(inherits(result, "tbl_df")) - expect_equal(result$event, sum(event)) - expect_equal(result$theta, theta) - expect_equal(result$ahr, exp(-theta)) -}) - test_that("Correct computation of blinded AHR and information adjustment", { surv <- survival::Surv(simtrial::ex2_delayed_effect$month, event = simtrial::ex2_delayed_effect$evntd) intervals <- c(3, Inf) @@ -117,20 +76,15 @@ test_that("ahr_blinded handles all events in the first interval", { expect_equal(result$event, sum(surv[, "status"])) }) -test_that("ahr_blinded handles very small or very large hazard ratios", { +test_that("ahr_blinded handles very small hazard ratios", { surv <- survival::Surv(time = c(1, 2, 3, 4, 5), event = c(1, 1, 1, 1, 1)) intervals <- c(2, 3, Inf) - hr_small <- c(0.1, 0.2, 0.3) - hr_large <- c(10, 20, 30) - - res_hr_small <- ahr_blinded(surv = surv, intervals = intervals, hr = hr_small) - res_hr_large <- ahr_blinded(surv = surv, intervals = intervals, hr = hr_large) + hr <- c(0.1, 0.2, 0.3) - expect_true(res_hr_small$theta > 0) - expect_true(res_hr_small$ahr < 1) + res <- ahr_blinded(surv = surv, intervals = intervals, hr = hr) - expect_true(res_hr_large$theta < 0) - expect_true(res_hr_large$ahr > 1) + expect_true(res$theta > 0) + expect_true(res$ahr < 1) }) test_that("ahr_blinded handles very high randomization ratio", { @@ -141,9 +95,6 @@ test_that("ahr_blinded handles very high randomization ratio", { result <- ahr_blinded(surv = surv, intervals = intervals, hr = hr, ratio = ratio) - q_e <- ratio / (1 + ratio) - # q_e should be close to 1 - expect_equal(q_e, 1, tolerance = 0.01) # info0 should be near 0 expect_equal(result$info0, 0, tolerance = 0.05) })