diff --git a/R/ocPredprob.R b/R/ocPredprob.R index a436ac59..1ceb08c3 100644 --- a/R/ocPredprob.R +++ b/R/ocPredprob.R @@ -58,7 +58,7 @@ h_get_decision_one_predprob <- function(nnr, truep, p0, parE = c(1, 1), nnE, nnF thetaT = tT, parE = parE )$result - decision <- ifelse(interim_qU > phiU, FALSE, decision) + decision <- ifelse(interim_qU > phiU, TRUE, decision) all_looks <- orig_nnr[index_look] } if (size_look %in% nnF) { diff --git a/tests/testthat/test-ocPredprob.R b/tests/testthat/test-ocPredprob.R index 159a429d..1dd271a2 100644 --- a/tests/testthat/test-ocPredprob.R +++ b/tests/testthat/test-ocPredprob.R @@ -21,6 +21,34 @@ test_that("h_get_decision_one_predprob gives correct result and list", { expect_list(result) }) +test_that("Go decision for all interims when criteria met for decision 1", { + set.seed(40) + expect_warning( + res <- ocPredprob( + decision1 = TRUE, + nnE = c(20, 30, 40), + nnF = c(20, 30, 40), + truep = 0.90, + phiU = 0.75, + phiL = 0.20, + tT = 0.70, + p0 = 0.20, + parE = c(0.2, 0.8), + sim = 100 + ), + "Advise to use sim >= 50000 to achieve convergence" + ) + random_number <- sample(x = length(res$Decision), size = 1) + expect_true(all(res$Decision) == TRUE) + expect_true(all(res$SampleSize == 20)) + expect_true(res$params$decision1 == TRUE) + expect_equal(res$oc$ExpectedN, res$SampleSize[random_number]) + expect_identical(res$oc$PrEfficacy, 1) + expect_identical(res$oc$PrEarlyEff, 1) + expect_identical(res$oc$PrEarlyFut, 0) + expect_identical(res$oc$PrFutility, 0) +}) + # h_get_decision_two_predprob ---- test_that("h_get_decision_two_predprob gives correct result and list", { set.seed(1989) diff --git a/tests/testthat/test-predprobDist.R b/tests/testthat/test-predprobDist.R index 8bcbcf76..6269e50e 100644 --- a/tests/testthat/test-predprobDist.R +++ b/tests/testthat/test-predprobDist.R @@ -15,7 +15,7 @@ test_that("h_predprobdist_single_arm gives correct results", { ) expect_equal(result$result, 0.7081907, tolerance = 1e-4) expect_equal(sum(result$table$density), 1, tolerance = 1e-4) - expect_true(all(result$posterior) <= 1) + expect_true(all(result$table$posterior <= 1)) }) test_that("h_predprobdist_single_arm gives higher predictive probability when thetaT is lower", { @@ -99,7 +99,7 @@ test_that("h_predprobdist_single_arm gives correct list", { # h_predprobdist ---- test_that("h_predprobdist gives correct list", { - result <- h_predprobdist( + warnings <- capture_warnings(result <- h_predprobdist( NmaxControl = 20, Nmax = 40, n = 23, @@ -113,7 +113,11 @@ test_that("h_predprobdist gives correct list", { delta = 0.1, relativeDelta = FALSE, thetaT = 0.5 - ) + )) + number_of_arms <- 2 + number_of_warnings <- sum(length(result$posterior) * number_of_arms, number_of_arms) + expect_true(all(grepl("Weights have been corrected", warnings))) + expect_length(warnings, number_of_warnings) expect_equal(result$result, 0.9322923, tolerance = 1e-4) expect_identical(result$table, data.frame(counts = 0:17, cumul_counts = as.numeric(16:33))) @@ -228,34 +232,47 @@ test_that("predprobDist gives the correct results in a two-arm study", { }) test_that("predprobDist gives higher predictive probability when thetaT is lower in a single-arm trial", { - is_lower <- predprobDist( - x = 16, - n = 23, - xS = 5, - nS = 10, - Nmax = 40, - NmaxControl = 20, - delta = 0.1, - thetaT = 0.9, - parE = rbind(c(1, 1), c(50, 10)), - weights = c(2, 1), - parS = rbind(c(1, 1), c(20, 40)), - weightsS = c(2, 1) + expect_warnings( + is_lower <- predprobDist( + x = 16, + n = 23, + xS = 5, + nS = 10, + Nmax = 40, + NmaxControl = 20, + delta = 0.1, + thetaT = 0.9, + parE = rbind(c(1, 1), c(50, 10)), + weights = c(2, 1), + parS = rbind(c(1, 1), c(20, 40)), + weightsS = c(2, 1) + ), + "Weights have been corrected" ) - is_higher <- predprobDist( - x = 16, - n = 23, - xS = 5, - nS = 10, - Nmax = 40, - NmaxControl = 20, - delta = 0.1, - thetaT = 0.5, - parE = rbind(c(1, 1), c(50, 10)), - weights = c(2, 1), - parS = rbind(c(1, 1), c(20, 40)), - weightsS = c(2, 1) + + expect_warning( + is_higher <- predprobDist( + x = 16, + n = 23, + xS = 5, + nS = 10, + Nmax = 40, + NmaxControl = 20, + delta = 0.1, + thetaT = 0.5, + parE = rbind(c(1, 1), c(50, 10)), + weights = c(2, 1), + parS = rbind(c(1, 1), c(20, 40)), + weightsS = c(2, 1) + ), + "Weights have been corrected" + ) + expect_equal( + length(warnings_list), + 50, + label = "Check total number of warnings" ) + expect_true(is_higher$result > is_lower$result) })