From d4f13d0052a8f8ce2bccd3a3398bff153f4d16fc Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 26 May 2024 19:50:36 +0200 Subject: [PATCH 01/53] examples and test --- R/boundsPredprob.R | 73 +++++++++------- examples/boundsPredprob.R | 16 ++-- man/boundsPredprob.Rd | 67 ++++++++------- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPredprob.R | 33 ++++++++ 5 files changed, 240 insertions(+), 70 deletions(-) create mode 100644 tests/testthat/test-boundsPredprob.R diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 66a0de3c..54c64d97 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -1,38 +1,36 @@ -#' Decision cutpoints for boundary (based on predictive probability) +#' Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule. #' #' This function is used to identify the efficacy boundary and futility -#' boundary based on predictive probabilities, i.e.: +#' boundary based on the following rules: #' Efficacy boundary: find minimum x (xU) where -#' Pr(Pr(P > p | x, Y) >= tT | x) > phiU, +#' Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, #' Futility boundary: find maximum x (xL) where -#' Pr(Pr(P > p | x, Y) >= tT | x) < phiL +#' Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL #' -#' @param nvec a vector of number of patients -#' @param Nmax maximum number of patients at the end of the trial -#' (default: maximum of \code{nvec}) -#' @param p threshold on the response rate -#' @param tT threshold on the posterior probability to be above p -#' @param phiL futility boundary predictive probability threshold -#' @param phiU efficacy boundary predictive probability threshold -#' @param a the alpha parameter of a beta prior of treatment group -#' @param b the beta parameter of a beta prior of treatment group -#' @return A matrix where for each sample size in \code{nvec}, this function -#' returns the maximum number of responses that meet the futility -#' threshold (xL), its corresponding response rate (pL), predictive probability -#' (ppL) and posterior probability (postL), the upper bound of one -#' sided 95% CI for the response rate based on an -#' exact binomial test (UciL), and the same boundary parameters for efficacy: -#' the minimal number of responses that meet the efficacy threshold (xU), -#' the corresponding response rate (pU), predictive probability -#' (ppL) and posterior probability (postU), the lower bound of one sided -#' 95% CI for the response rate based on exact binomial test (LciU). +#' @inheritParams predprob +#' @inheritParams ocPredprob +#' @inheritParams boundsPostprob +#' @return A matrix for each same size in `nvec`. For each sample size, the following is returned: +#' - `xL` : the maximum number of responses that meet the futility. +#' threshold +#' - `pL` : response rate corresponding to `xL`. +#' - `ppL` : predictive probability corresponding to `xL` +#' - `postL`: posterior probability corresponding to `xL`. +#' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an +#' exact binomial test. +#' - `xU` : the minimal number of responses that meet the efficacy threshold. +#' - `pU` : response rate corresponding to `xU`. +#' - `postL`: posterior probability corresponding to `xU`. +#' - `ppU` : predictive probability corresponding to `xU` +#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact +#' binomial test. #' #' @importFrom stats binom.test #' #' @example examples/boundsPredprob.R #' @export #' @keywords graphics -boundsPredprob <- function(nvec, Nmax = max(nvec), p, tT, phiL, phiU, a, b) { +boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { znames <- c( "xL", "pL", "ppL", "postL", "UciL", "xU", "pU", "ppU", "postU", "LciU" @@ -46,29 +44,42 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p, tT, phiL, phiU, a, b) { xL <- NA xU <- NA for (x in 0:n) { - pp <- predprob(x, n, Nmax, p, tT, parE = c(a, b))$result + pp <- predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result if (pp <= phiL) { xL <- x + ppL <- pp } if (pp >= phiU) { xU <- x + ppU <- ppL # done: leave innermost for loop break } } - # reset xU to NA if phiU=1 and n p | x, Y) >= tT | x) > phiU, +Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, Futility boundary: find maximum x (xL) where -Pr(Pr(P > p | x, Y) >= tT | x) < phiL +Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL } \examples{ -## 40 pts trial with interim looks after each 10 pts., -## final efficacy decision if more than 80\% probability to be above 20\% ORR, -## final futility decision otherwise. -## Interim efficacy decision if more than 90\% predictive probability reach this, -## interim futility decision if less than 10\% predictive probability. -## Uniform prior (i.e. beta(1, 1)) on the ORR: +# 40 pts trial with interim looks after each 10 pts., +# final efficacy decision if more than 80\% probability to be above 20\% ORR, +# final futility decision otherwise. +# Interim efficacy decision if more than 90\% predictive probability reach this, +# interim futility decision if less than 10\% predictive probability. +# Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, phiL = 0.10, phiU = 0.90, a = 1, b = 1 ) -## From this we see e.g. that at the first IA at 10 pts, we would stop for futility -## if no patient responded, and for efficacy if 4 or more pts responded. +# From this we see e.g. that at the first IA at 10 pts, we would stop for futility +# if no patient responded, and for efficacy if 4 or more pts responded. } \keyword{graphics} diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..fa79aa7c 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 100, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R new file mode 100644 index 00000000..5d43c25f --- /dev/null +++ b/tests/testthat/test-boundsPredprob.R @@ -0,0 +1,33 @@ +# boundsPostProb ---- +test_that("boundsPredprob gives correct result and list", { + result <- boundsPredprob( + nvec = c(10, 20, 30, 40), + p0 = 0.2, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + a = 1, + b = 1 + ) + expected <- data.frame( + list( + nvec = c(10, 20, 30, 40), + xL = c(0, 2, 5, 9), + pL = c(0, 0.1, 0.1667, 0.225), + postL = c(0.0859, 0.1787, 0.3931, 0.704), + UciL = c(0.2589, 0.2826, 0.319, 0.3598), + xU = c(4, 7, 9, 10), + pU = c(0.4, 0.35, 0.3, 0.25), + postU = c(0.9496, 0.9569, 0.9254, 0.8177), + LciU = c(0.15, 0.1773, 0.1663, 0.1424) + ) + ) + expect_equal(result$xL, c(0, 2, 5, 9)) + expect_equal(result$pL, c(0, 0.1, 0.1667, 0.225)) + expect_equal(result$postL, c(0.0859, 0.1787, 0.3931, 0.704)) + expect_equal(result$UciL, c(0.2589, 0.2826, 0.319, 0.3598)) + expect_equal(result$xU, c(4, 7, 9, 10)) + expect_equal(result$pU, c(0.4, 0.35, 0.3, 0.25)) + expect_equal(result$postU, c(0.9496, 0.9569, 0.9254, 0.8177)) + expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) +}) From 7e605bf8e54295e184d77bc75f0e436f514e8a1e Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sun, 26 May 2024 17:54:06 +0000 Subject: [PATCH 02/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index fa79aa7c..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 100, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From 3aa565b5a47b5d9822bc7d37ae947e8e92477e80 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 11 Jun 2024 16:05:29 +0200 Subject: [PATCH 03/53] clean --- R/boundsPredprob.R | 11 +++-- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 5 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 54c64d97..7b550341 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -45,13 +45,14 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { xU <- NA for (x in 0:n) { pp <- predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result - if (pp <= phiL) { - xL <- x - ppL <- pp - } - if (pp >= phiU) { + if (pp >= phiU) { # Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, xU <- x ppU <- ppL + } + predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result + if (pp <= phiL) { # Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL + xL <- x + ppL <- pp # done: leave innermost for loop break } diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From 7e50f1cff148860950d9bb62fe7de06ac0c04063 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:08:22 +0000 Subject: [PATCH 04/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From 75b676e430619303f3d944fd2a10e8cd41fc7372 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Wed, 26 Jun 2024 16:05:38 +0200 Subject: [PATCH 05/53] it works --- R/boundsPostprob.R | 21 ++++--- R/boundsPredprob.R | 14 ++--- examples/boundsPredprob.R | 25 +++++--- man/boundsPredprob.Rd | 25 +++++--- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 34 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 09822eda..ee7e37fc 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -29,15 +29,22 @@ #' @export #' @keywords graphics boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { - z <- matrix(NA, length(nvec), 6) - dimnames(z) <- list(nvec, c( - "xL", "pL", "postL", - "xU", "pU", "postU" - )) + z <- matrix(NA, length(nvec), ncol = 6) + # dimnames(z) <- list(nvec, c( + # "xL", "pL", "postL", + # "xU", "pU", "postU" + # )) + # znames <- c( + # "xL", "pL", "postL", "UciL", + # "xU", "pU", "postU", "LciU" + # ) + znames <- c( - "xL", "pL", "postL", "UciL", - "xU", "pU", "postU", "LciU" + "xL", "pL", "postL", "pL_upper_ci", + "xU", "pU", "postU", "pU_lower_ci" ) + dimnames(z) <- list(nvec, znames) + z <- matrix(NA, length(nvec), length(znames)) dimnames(z) <- list(nvec, znames) k <- 0 diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 7b550341..b926dfcc 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -45,15 +45,13 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { xU <- NA for (x in 0:n) { pp <- predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result - if (pp >= phiU) { # Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, - xU <- x - ppU <- ppL - } - predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result - if (pp <= phiL) { # Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL + if (pp <= phiL) { # Futility look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL xL <- x ppL <- pp - # done: leave innermost for loop + } + if (pp >= phiU) { # Efficacy look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, + xU <- x + ppU <- pp break } } @@ -62,8 +60,6 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { xU <- NA } # calculate predictive and posterior probabilities at boundaries - ppL <- predprob(xL, n, Nmax, p0, tT, parE = c(a, b))$result - ppU <- predprob(xU, n, Nmax, p0, tT, parE = c(a, b))$result postL <- postprob(xL, n, p0, parE = c(a, b)) postU <- postprob(xU, n, p0, parE = c(a, b)) # calculate lower CI at boundaries diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index 862d627c..5b56c681 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -1,12 +1,19 @@ -# 40 pts trial with interim looks after each 10 pts., -# final efficacy decision if more than 80% probability to be above 20% ORR, -# final futility decision otherwise. -# Interim efficacy decision if more than 90% predictive probability reach this, -# interim futility decision if less than 10% predictive probability. +# 40 pts trial with interim looks after each 10 patients. +# Final efficacy decision if more than 80% probability to be above 20% ORR, +# Final futility decision otherwise. +# Interim efficacy decision if more than 90% predictive probability reach this or +# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Interim futility decision if less than 10% predictive probability or +# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 + nvec = c(10, 20, 30, 40), + p = 0.20, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + a = 1, + b = 1 ) -# From this we see e.g. that at the first IA at 10 pts, we would stop for futility -# if no patient responded, and for efficacy if 4 or more pts responded. +# From this we see e.g. that at the first IA at 10 patients, we would stop for futility +# if no patient responded, and for efficacy if 4 or more patients responded. diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 9043ad3b..8c2fd728 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -50,17 +50,24 @@ Futility boundary: find maximum x (xL) where Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL } \examples{ -# 40 pts trial with interim looks after each 10 pts., -# final efficacy decision if more than 80\% probability to be above 20\% ORR, -# final futility decision otherwise. -# Interim efficacy decision if more than 90\% predictive probability reach this, -# interim futility decision if less than 10\% predictive probability. +# 40 pts trial with interim looks after each 10 patients. +# Final efficacy decision if more than 80\% probability to be above 20\% ORR, +# Final futility decision otherwise. +# Interim efficacy decision if more than 90\% predictive probability reach this or +# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Interim futility decision if less than 10\% predictive probability or +# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 + nvec = c(10, 20, 30, 40), + p = 0.20, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + a = 1, + b = 1 ) -# From this we see e.g. that at the first IA at 10 pts, we would stop for futility -# if no patient responded, and for efficacy if 4 or more pts responded. +# From this we see e.g. that at the first IA at 10 patients, we would stop for futility +# if no patient responded, and for efficacy if 4 or more patients responded. } \keyword{graphics} diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From a5134f048f15efc3c8561d2963a493c1657871f7 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:07:33 +0000 Subject: [PATCH 06/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From 1b7df2697ce351ea4ad26de0783ebb9bb0af9e96 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 26 Sep 2024 08:19:07 +0200 Subject: [PATCH 07/53] some syntax changes --- R/boundsPredprob.R | 16 +++--- man/boundsPredprob.Rd | 11 ++-- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 13 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index b926dfcc..1fd99ae4 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -10,7 +10,7 @@ #' @inheritParams predprob #' @inheritParams ocPredprob #' @inheritParams boundsPostprob -#' @return A matrix for each same size in `nvec`. For each sample size, the following is returned: +#' @return A matrix for each same size in `looks`. For each sample size, the following is returned: #' - `xL` : the maximum number of responses that meet the futility. #' threshold #' - `pL` : response rate corresponding to `xL`. @@ -30,15 +30,19 @@ #' @example examples/boundsPredprob.R #' @export #' @keywords graphics -boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { +boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE) { znames <- c( "xL", "pL", "ppL", "postL", "UciL", "xU", "pU", "ppU", "postU", "LciU" ) - z <- matrix(NA, length(nvec), length(znames)) - dimnames(z) <- list(nvec, znames) + z <- matrix(NA, length(looks), length(znames)) + dimnames(z) <- list(looks, znames) + parE <- t(parE) + if (missing(weights)) { + weights <- rep(1, nrow(parE)) + } k <- 0 - for (n in nvec) { + for (n in looks) { k <- k + 1 # initialize so will return NA if 0 or n in "continue" region xL <- NA @@ -78,5 +82,5 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { LciU ) } - return(round(data.frame(nvec, z), 4)) + return(round(data.frame(looks, z), 4)) } diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 8c2fd728..ecd65eb5 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -4,11 +4,9 @@ \alias{boundsPredprob} \title{Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule.} \usage{ -boundsPredprob(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) +boundsPredprob(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE) } \arguments{ -\item{nvec}{a vector of number of patients} - \item{Nmax}{(\code{number}):\cr maximum number of patients at the end of the trial in the \code{E} group.} \item{p0}{(\code{number}):\cr lower Futility threshold of response rate.} @@ -19,12 +17,11 @@ boundsPredprob(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) \item{phiU}{(\code{number}):\cr upper threshold on the predictive probability.} -\item{a}{the alpha parameter of the beta prior of treatment group} - -\item{b}{the beta parameter of the beta prior of treatment group} +\item{parE}{(\code{numeric}):\cr the beta parameters matrix, with K rows and 2 columns, +corresponding to the beta parameters of the K components.} } \value{ -A matrix for each same size in \code{nvec}. For each sample size, the following is returned: +A matrix for each same size in \code{looks}. For each sample size, the following is returned: \itemize{ \item \code{xL} : the maximum number of responses that meet the futility. threshold diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From bdcf2a393b6808b3be63862f7452b9c1d5fc74ed Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 06:22:27 +0000 Subject: [PATCH 08/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- DESCRIPTION | 2 +- man/ocPredprob.Rd | 121 ---------------------------------------------- 2 files changed, 1 insertion(+), 122 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b568d599..d7f95063 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,7 +44,7 @@ Language: en-US LazyData: true Roxygen: list(markdown = TRUE, packages = "roxytypes") -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Config/Needs/documentation: roxytypes Remotes: diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From e180429f76b5f19b5f26dbb2622a958740370af5 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 27 Sep 2024 10:58:14 +0200 Subject: [PATCH 09/53] clean --- R/boundsPredprob.R | 35 ++++---- examples/boundsPredprob.R | 8 +- man/boundsPredprob.Rd | 25 ++++-- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPredprob.R | 7 +- 5 files changed, 164 insertions(+), 32 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 1fd99ae4..27e916b9 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -14,14 +14,14 @@ #' - `xL` : the maximum number of responses that meet the futility. #' threshold #' - `pL` : response rate corresponding to `xL`. -#' - `ppL` : predictive probability corresponding to `xL` +#' - `predL` : predictive probability corresponding to `xL` #' - `postL`: posterior probability corresponding to `xL`. #' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an #' exact binomial test. #' - `xU` : the minimal number of responses that meet the efficacy threshold. #' - `pU` : response rate corresponding to `xU`. +#' - `predU` : predictive probability corresponding to `xU` #' - `postL`: posterior probability corresponding to `xU`. -#' - `ppU` : predictive probability corresponding to `xU` #' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact #' binomial test. #' @@ -30,32 +30,37 @@ #' @example examples/boundsPredprob.R #' @export #' @keywords graphics -boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE) { +boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = c(1, 1), weights) { + assert_numeric(looks) + assert_number(p0, lower = 0, upper = 1) + assert_number(tT, lower = 0, upper = 1) + assert_numeric(parE, min.len = 2, any.missing = FALSE) znames <- c( - "xL", "pL", "ppL", "postL", "UciL", - "xU", "pU", "ppU", "postU", "LciU" + "xL", "pL", "predL", "postL", "UciL", + "xU", "pU", "predU", "postU", "LciU" ) z <- matrix(NA, length(looks), length(znames)) dimnames(z) <- list(looks, znames) + k <- 0 parE <- t(parE) if (missing(weights)) { weights <- rep(1, nrow(parE)) } - k <- 0 + assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE) for (n in looks) { k <- k + 1 # initialize so will return NA if 0 or n in "continue" region xL <- NA xU <- NA for (x in 0:n) { - pp <- predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result - if (pp <= phiL) { # Futility look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL + predprob <- predprob(x, n, Nmax, p0, tT, parE = parE)$result + if (predprob <= phiL) { # Futility look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL xL <- x - ppL <- pp + predL <- predprob } - if (pp >= phiU) { # Efficacy look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, + if (predprob >= phiU) { # Efficacy look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, xU <- x - ppU <- pp + predU <- predprob break } } @@ -64,20 +69,20 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE) { xU <- NA } # calculate predictive and posterior probabilities at boundaries - postL <- postprob(xL, n, p0, parE = c(a, b)) - postU <- postprob(xU, n, p0, parE = c(a, b)) + postL <- postprob(xL, n, p0, parE = parE) + postU <- postprob(xU, n, p0, parE = parE) # calculate lower CI at boundaries UciL <- ifelse(!is.na(xL), stats::binom.test(xL, n, alt = "less")$conf.int[2], NA) LciU <- ifelse(!is.na(xU), stats::binom.test(xU, n, alt = "greater")$conf.int[1], NA) z[k, ] <- c( xL, xL / n, - ppL, + predL, postL, UciL, xU, xU / n, - ppU, + predU, postU, LciU ) diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index 5b56c681..25fcf729 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -7,13 +7,11 @@ # Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( - nvec = c(10, 20, 30, 40), - p = 0.20, + looks = c(10, 20, 30, 40), + p0 = 0.20, tT = 0.80, phiL = 0.10, - phiU = 0.90, - a = 1, - b = 1 + phiU = 0.90 ) # From this we see e.g. that at the first IA at 10 patients, we would stop for futility # if no patient responded, and for efficacy if 4 or more patients responded. diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index ecd65eb5..abd3a8ce 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -4,7 +4,16 @@ \alias{boundsPredprob} \title{Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule.} \usage{ -boundsPredprob(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE) +boundsPredprob( + looks, + Nmax = max(looks), + p0, + tT, + phiL, + phiU, + parE = c(1, 1), + weights +) } \arguments{ \item{Nmax}{(\code{number}):\cr maximum number of patients at the end of the trial in the \code{E} group.} @@ -19,6 +28,8 @@ boundsPredprob(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE) \item{parE}{(\code{numeric}):\cr the beta parameters matrix, with K rows and 2 columns, corresponding to the beta parameters of the K components.} + +\item{weights}{(\code{numeric}):\cr the mixture weights of the beta mixture prior.} } \value{ A matrix for each same size in \code{looks}. For each sample size, the following is returned: @@ -26,14 +37,14 @@ A matrix for each same size in \code{looks}. For each sample size, the following \item \code{xL} : the maximum number of responses that meet the futility. threshold \item \code{pL} : response rate corresponding to \code{xL}. -\item \code{ppL} : predictive probability corresponding to \code{xL} +\item \code{predL} : predictive probability corresponding to \code{xL} \item \code{postL}: posterior probability corresponding to \code{xL}. \item \code{Ucil} : upper bound of one sided 95\% CI for the response rate based on an exact binomial test. \item \code{xU} : the minimal number of responses that meet the efficacy threshold. \item \code{pU} : response rate corresponding to \code{xU}. +\item \code{predU} : predictive probability corresponding to \code{xU} \item \code{postL}: posterior probability corresponding to \code{xU}. -\item \code{ppU} : predictive probability corresponding to \code{xU} \item \code{LciU} : lower bound of one sided 95\% CI for the response rate based on exact binomial test. } @@ -56,13 +67,11 @@ Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL # Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( - nvec = c(10, 20, 30, 40), - p = 0.20, + looks = c(10, 20, 30, 40), + p0 = 0.20, tT = 0.80, phiL = 0.10, - phiU = 0.90, - a = 1, - b = 1 + phiU = 0.90 ) # From this we see e.g. that at the first IA at 10 patients, we would stop for futility # if no patient responded, and for efficacy if 4 or more patients responded. diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index 5d43c25f..4c8b17e0 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -1,13 +1,12 @@ # boundsPostProb ---- -test_that("boundsPredprob gives correct result and list", { +test_that("boundsPredprob gives correct result", { result <- boundsPredprob( - nvec = c(10, 20, 30, 40), + looks = c(10, 20, 30, 40), p0 = 0.2, tT = 0.80, phiL = 0.10, phiU = 0.90, - a = 1, - b = 1 + parE = c(1, 1) ) expected <- data.frame( list( From 942e0f7b2936b25ad0bdcb8eaf4306bf99585214 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 09:01:32 +0000 Subject: [PATCH 10/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From 23a06f30b1d4bf01fc48be982bc4c0fc4f6d5ba7 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sat, 28 Sep 2024 00:26:36 +0200 Subject: [PATCH 11/53] clean --- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPredprob.R | 33 ++++++++ 2 files changed, 154 insertions(+) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index 4c8b17e0..928b60e7 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -30,3 +30,36 @@ test_that("boundsPredprob gives correct result", { expect_equal(result$postU, c(0.9496, 0.9569, 0.9254, 0.8177)) expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) }) + +test_that("boundsPredprob of beta mixture gives correct result", { + result <- boundsPredprob( + looks = c(7, 15, 20), + p0 = 0.2, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + parE = rbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + ) + expected <- data.frame( + list( + nvec = c(10, 20, 30, 40), + xL = c(0, 2, 5, 9), + pL = c(0, 0.1, 0.1667, 0.225), + postL = c(0.0859, 0.1787, 0.3931, 0.704), + UciL = c(0.2589, 0.2826, 0.319, 0.3598), + xU = c(4, 7, 9, 10), + pU = c(0.4, 0.35, 0.3, 0.25), + postU = c(0.9496, 0.9569, 0.9254, 0.8177), + LciU = c(0.15, 0.1773, 0.1663, 0.1424) + ) + ) + expect_equal(result$xL, c(0, 2, 5, 9)) + expect_equal(result$pL, c(0, 0.1, 0.1667, 0.225)) + expect_equal(result$postL, c(0.0859, 0.1787, 0.3931, 0.704)) + expect_equal(result$UciL, c(0.2589, 0.2826, 0.319, 0.3598)) + expect_equal(result$xU, c(4, 7, 9, 10)) + expect_equal(result$pU, c(0.4, 0.35, 0.3, 0.25)) + expect_equal(result$postU, c(0.9496, 0.9569, 0.9254, 0.8177)) + expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) +}) From 9ffba4cd4430237a60d088ec9af11ca14202d2f2 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:29:24 +0000 Subject: [PATCH 12/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From f6faec2525fa0c5e0d337fe214debc5317236862 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 1 Oct 2024 11:24:05 +0200 Subject: [PATCH 13/53] clean --- R/predprob.R | 2 +- examples/boundsPredprob.R | 22 ++++++- man/boundsPredprob.Rd | 22 ++++++- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 7 deletions(-) diff --git a/R/predprob.R b/R/predprob.R index 93329528..f550e018 100644 --- a/R/predprob.R +++ b/R/predprob.R @@ -63,7 +63,7 @@ predprob <- function(x, n, Nmax, p, thetaT, parE = c(1, 1), betamixPost, dbetabinomMix(x = 0:m, m = m, par = par, weights = weights) ) - assert_numeric(density, lower = 0, upper = 1, finite = TRUE, any.missing = FALSE) + assert_numeric(density, lower = 0, upper = 1 + .Machine$double.eps, finite = TRUE, any.missing = FALSE) assert_number(thetaT, lower = 0, upper = 1, finite = TRUE) # posterior probabilities to be above threshold p posterior <- postprob(x = x + c(0:m), n = Nmax, p = p, parE = parE, weights = weights) diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index 25fcf729..1150fd9a 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -10,8 +10,24 @@ boundsPredprob( looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, - phiL = 0.10, + phiL = 0.60, phiU = 0.90 ) -# From this we see e.g. that at the first IA at 10 patients, we would stop for futility -# if no patient responded, and for efficacy if 4 or more patients responded. + +# 25 pts trial with interim looks at 7 and 15 pts. +# Efficacy decision if more than 80% probability to be above 20% ORR, +# Final futility decision otherwise. +# Interim efficacy decision if more than 90% predictive probability reach this or +# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Interim futility decision if less than 60% predictive probability or +# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi +# with mixed prior and weights: +boundsPredprob( + looks = c(7, 15, 25), + p0 = 0.20, + tT = 0.80, + phiL = 0.60, + phiU = 0.90, + parE = rbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) +) diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index abd3a8ce..0f082775 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -70,10 +70,26 @@ boundsPredprob( looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, - phiL = 0.10, + phiL = 0.60, phiU = 0.90 ) -# From this we see e.g. that at the first IA at 10 patients, we would stop for futility -# if no patient responded, and for efficacy if 4 or more patients responded. + +# 25 pts trial with interim looks at 7 and 15 pts. +# Efficacy decision if more than 80\% probability to be above 20\% ORR, +# Final futility decision otherwise. +# Interim efficacy decision if more than 90\% predictive probability reach this or +# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Interim futility decision if less than 60\% predictive probability or +# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi +# with mixed prior and weights: +boundsPredprob( + looks = c(7, 15, 25), + p0 = 0.20, + tT = 0.80, + phiL = 0.60, + phiU = 0.90, + parE = rbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) +) } \keyword{graphics} diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From cefe1a93092cf6a2ffc14b4ac448e33cb7714d88 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 1 Oct 2024 11:41:10 +0200 Subject: [PATCH 14/53] clean --- tests/testthat/test-boundsPredprob.R | 38 +++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index 928b60e7..ae62fee8 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -43,23 +43,27 @@ test_that("boundsPredprob of beta mixture gives correct result", { ) expected <- data.frame( list( - nvec = c(10, 20, 30, 40), - xL = c(0, 2, 5, 9), - pL = c(0, 0.1, 0.1667, 0.225), - postL = c(0.0859, 0.1787, 0.3931, 0.704), - UciL = c(0.2589, 0.2826, 0.319, 0.3598), - xU = c(4, 7, 9, 10), - pU = c(0.4, 0.35, 0.3, 0.25), - postU = c(0.9496, 0.9569, 0.9254, 0.8177), - LciU = c(0.15, 0.1773, 0.1663, 0.1424) + looks = c(7, 15, 20), + xL = c(1, 3, 6), + pL = c(0.1429, 0.2000, 0.3000), + predL = c(0.0446, 0.0121, 0.0000), + postL = c(0.2407, 0.3818, 0.7734), + UciL = c(0.5207, 0.4398, 0.5078), + xU = c(5, 7, 7), + pU = c(0.7143, 0.4667, 0.3500), + predU = c(0.9843, 1.0000, 1.0000), + postU = c(0.9883, 0.9727, 0.8919), + LciU = c(0.3413, 0.2437, 0.1773) ) ) - expect_equal(result$xL, c(0, 2, 5, 9)) - expect_equal(result$pL, c(0, 0.1, 0.1667, 0.225)) - expect_equal(result$postL, c(0.0859, 0.1787, 0.3931, 0.704)) - expect_equal(result$UciL, c(0.2589, 0.2826, 0.319, 0.3598)) - expect_equal(result$xU, c(4, 7, 9, 10)) - expect_equal(result$pU, c(0.4, 0.35, 0.3, 0.25)) - expect_equal(result$postU, c(0.9496, 0.9569, 0.9254, 0.8177)) - expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) + expect_equal(result$xL, c(1, 3, 6)) + expect_equal(result$pL, c(0.1429, 0.2000, 0.3000)) + expect_equal(result$predL, c(0.0446, 0.0121, 0.0000)) + expect_equal(result$postL, c(0.2407, 0.3818, 0.7734)) + expect_equal(result$UciL, c(0.5207, 0.4398, 0.5078)) + expect_equal(result$xU, c(5, 7, 7)) + expect_equal(result$pU, c(0.7143, 0.4667, 0.3500)) + expect_equal(result$predU, c(0.9843, 1.0000, 1.0000)) + expect_equal(result$postU, c(0.9883, 0.9727, 0.8919)) + expect_equal(result$LciU, c(0.3413, 0.2437, 0.1773)) }) From aee5fb6b6595f949c3b4b92054e7b7e97520487d Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Wed, 2 Oct 2024 18:17:34 +0200 Subject: [PATCH 15/53] clean --- examples/ocPredprobDist.R | 22 +++++++++++++--------- examples/plotBounds.R | 8 -------- man/ocPredprobDist.Rd | 26 +++++++++++++++++--------- man/plotBounds.Rd | 8 -------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/examples/ocPredprobDist.R b/examples/ocPredprobDist.R index 4bc2715e..19982cf1 100644 --- a/examples/ocPredprobDist.R +++ b/examples/ocPredprobDist.R @@ -10,7 +10,7 @@ # - Interim look for Efficacy: # Pr( success at final ) > 80% or P(success at final) > phiU # - Interim look for Futility: -# Pr( failure at final ) < 20% or P(success at final) < phiL +# Pr( success at final ) < 20% or P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) @@ -41,10 +41,14 @@ result$oc # Desired difference to Standard of Care for Efficacy and Futility is 10% and -10% respectively. # Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules. # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20% or P(success at final) < phiL +# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or +# P(response rate + deltaE > p0) > tT +# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or +# P(response rate + deltaF > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80% or +# P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20% or +# P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. # set.seed(20) @@ -111,10 +115,10 @@ result$oc # True response rate or truep of the treatment group = 40% # Desired difference to Standard of Care for Efficacy and Futility = 50% # Delta calculation is relative case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25% ) > 60% or P( P_S + (1-P_S)*deltaE > p0) > tT -# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25% ) < 60% or P( P_S + (1-P_S)*deltaF > p0) < tT -# - Interim look for Efficacy: P( success at final ) > 80% or P(success at final) > phiU -# - Interim look for Futility: P( failure at final ) < 20% or P(success at final) < phiL +# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25% ) > 60% +# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25% ) < 60% +# - Interim look for Efficacy: P( success at final ) > 80% +# - Interim look for Futility: P( failure at final ) < 20% # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) diff --git a/examples/plotBounds.R b/examples/plotBounds.R index c28479ea..42c34b05 100644 --- a/examples/plotBounds.R +++ b/examples/plotBounds.R @@ -1,9 +1 @@ # examples -plotBounds(boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 -), yt = "x") -plotBounds(boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 -), yt = "p") diff --git a/man/ocPredprobDist.Rd b/man/ocPredprobDist.Rd index 3a570cfa..eeb7de5f 100644 --- a/man/ocPredprobDist.Rd +++ b/man/ocPredprobDist.Rd @@ -144,7 +144,7 @@ seen in the evaluation for the final futility look in \code{\link[=ocPredprobDis # - Interim look for Efficacy: # Pr( success at final ) > 80\% or P(success at final) > phiU # - Interim look for Futility: -# Pr( failure at final ) < 20\% or P(success at final) < phiL +# Pr( success at final ) < 20\% or P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) @@ -175,10 +175,14 @@ result$oc # Desired difference to Standard of Care for Efficacy and Futility is 10\% and -10\% respectively. # Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules. # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or P(response rate + deltaF > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or +# P(response rate + deltaE > p0) > tT +# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or +# P(response rate + deltaF > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or +# P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or +# P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. # set.seed(20) @@ -245,10 +249,14 @@ result$oc # True response rate or truep of the treatment group = 40\% # Desired difference to Standard of Care for Efficacy and Futility = 50\% # Delta calculation is relative case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25\% ) > 60\% or P( P_S + (1-P_S)*deltaE > p0) > tT -# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25\% ) < 60\% or P( P_S + (1-P_S)*deltaF > p0) < tT -# - Interim look for Efficacy: P( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: P( failure at final ) < 20\% or P(success at final) < phiL +# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25\% ) > 60\% or +# P( P_S + (1-P_S)*deltaE > p0) > tT +# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25\% ) < 60\% or +# P( P_S + (1-P_S)*deltaF > p0) < tT +# - Interim look for Efficacy: P( success at final ) > 80\% or +# P(success at final) > phiU +# - Interim look for Futility: P( failure at final ) < 20\% or +# P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) diff --git a/man/plotBounds.Rd b/man/plotBounds.Rd index 0ee0034d..1cd568db 100644 --- a/man/plotBounds.Rd +++ b/man/plotBounds.Rd @@ -56,13 +56,5 @@ and \code{\link{boundsPostprob}} } \examples{ # examples -plotBounds(boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 -), yt = "x") -plotBounds(boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 -), yt = "p") } \keyword{graphics} From e5850930bcef05d0854c7ce51d03073f75a12343 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:19:53 +0000 Subject: [PATCH 16/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprobDist.Rd | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/man/ocPredprobDist.Rd b/man/ocPredprobDist.Rd index eeb7de5f..99accac9 100644 --- a/man/ocPredprobDist.Rd +++ b/man/ocPredprobDist.Rd @@ -249,14 +249,10 @@ result$oc # True response rate or truep of the treatment group = 40\% # Desired difference to Standard of Care for Efficacy and Futility = 50\% # Delta calculation is relative case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25\% ) > 60\% or -# P( P_S + (1-P_S)*deltaE > p0) > tT -# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25\% ) < 60\% or -# P( P_S + (1-P_S)*deltaF > p0) < tT -# - Interim look for Efficacy: P( success at final ) > 80\% or -# P(success at final) > phiU -# - Interim look for Futility: P( failure at final ) < 20\% or -# P(success at final) < phiL +# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25\% ) > 60\% +# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25\% ) < 60\% +# - Interim look for Efficacy: P( success at final ) > 80\% +# - Interim look for Futility: P( failure at final ) < 20\% # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) From eba4d49d78b0ab8d9e766c8a0a00c1a442c74097 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Wed, 2 Oct 2024 18:38:39 +0200 Subject: [PATCH 17/53] clean From e4864b52e363991d9cbf3b3ac9e92be4fc40c1ec Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 04:08:48 +0200 Subject: [PATCH 18/53] test case with pred prob passes with missing weights argument --- R/boundsPredprob.R | 3 +-- tests/testthat/test-boundsPredprob.R | 37 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 27e916b9..a92e6726 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -42,7 +42,6 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = z <- matrix(NA, length(looks), length(znames)) dimnames(z) <- list(looks, znames) k <- 0 - parE <- t(parE) if (missing(weights)) { weights <- rep(1, nrow(parE)) } @@ -53,7 +52,7 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = xL <- NA xU <- NA for (x in 0:n) { - predprob <- predprob(x, n, Nmax, p0, tT, parE = parE)$result + predprob <- predprob(x = x, n = n, Nmax = max(looks), p = p0, thetaT = tT, parE = parE, weights = weights)$result if (predprob <= phiL) { # Futility look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL xL <- x predL <- predprob diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index ae62fee8..e6a9601f 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -67,3 +67,40 @@ test_that("boundsPredprob of beta mixture gives correct result", { expect_equal(result$postU, c(0.9883, 0.9727, 0.8919)) expect_equal(result$LciU, c(0.3413, 0.2437, 0.1773)) }) + +test_that("boundsPredprob of beta mixture gives correct result", { + result <- boundsPredprob( + looks = c(7, 15, 20), + p0 = 0.2, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + parE = rbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + ) + expected <- data.frame( + list( + looks = c(7, 15, 20), + xL = c(1, 3, 6), + pL = c(0.1429, 0.2000, 0.3000), + predL = c(0.0446, 0.0121, 0.0000), + postL = c(0.2407, 0.3818, 0.7734), + UciL = c(0.5207, 0.4398, 0.5078), + xU = c(5, 7, 7), + pU = c(0.7143, 0.4667, 0.3500), + predU = c(0.9843, 1.0000, 1.0000), + postU = c(0.9883, 0.9727, 0.8919), + LciU = c(0.3413, 0.2437, 0.1773) + ) + ) + expect_equal(result$xL, c(1, 3, 6)) + expect_equal(result$pL, c(0.1429, 0.2000, 0.3000)) + expect_equal(result$predL, c(0.0446, 0.0121, 0.0000)) + expect_equal(result$postL, c(0.2407, 0.3818, 0.7734)) + expect_equal(result$UciL, c(0.5207, 0.4398, 0.5078)) + expect_equal(result$xU, c(5, 7, 7)) + expect_equal(result$pU, c(0.7143, 0.4667, 0.3500)) + expect_equal(result$predU, c(0.9843, 1.0000, 1.0000)) + expect_equal(result$postU, c(0.9883, 0.9727, 0.8919)) + expect_equal(result$LciU, c(0.3413, 0.2437, 0.1773)) +}) From 945a2b974d94600b18cfbd29699a68724b2ea3ff Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 13:10:09 +0200 Subject: [PATCH 19/53] clean --- R/boundsPredprob.R | 4 - examples/boundsPredprob.R | 2 +- man/boundsPredprob.Rd | 2 +- tests/testthat/test-boundsPredprob.R | 117 +++++++++++++-------------- 4 files changed, 58 insertions(+), 67 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index a92e6726..71f02452 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -42,10 +42,6 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = z <- matrix(NA, length(looks), length(znames)) dimnames(z) <- list(looks, znames) k <- 0 - if (missing(weights)) { - weights <- rep(1, nrow(parE)) - } - assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE) for (n in looks) { k <- k + 1 # initialize so will return NA if 0 or n in "continue" region diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index 1150fd9a..934c0064 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -28,6 +28,6 @@ boundsPredprob( tT = 0.80, phiL = 0.60, phiU = 0.90, - parE = rbind(c(1, 1), c(3, 10)), + parE = cbind(c(1, 1), c(3, 10)), weights = c(0.2, 0.8) ) diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 7c43eca2..aba286bc 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -90,7 +90,7 @@ boundsPredprob( tT = 0.80, phiL = 0.60, phiU = 0.90, - parE = rbind(c(1, 1), c(3, 10)), + parE = cbind(c(1, 1), c(3, 10)), weights = c(0.2, 0.8) ) } diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index e6a9601f..7144dc2c 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -1,5 +1,14 @@ -# boundsPostProb ---- -test_that("boundsPredprob gives correct result", { +# boundsPredProb ---- +test_that("boundsPredprob gives correct result and when default weight is not assigned", { + result_weights <- boundsPredprob( + looks = c(10, 20, 30, 40), + p0 = 0.2, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + parE = c(1, 1), + weights = 1 + ) result <- boundsPredprob( looks = c(10, 20, 30, 40), p0 = 0.2, @@ -21,6 +30,7 @@ test_that("boundsPredprob gives correct result", { LciU = c(0.15, 0.1773, 0.1663, 0.1424) ) ) + expect_equal(result_weights, result) expect_equal(result$xL, c(0, 2, 5, 9)) expect_equal(result$pL, c(0, 0.1, 0.1667, 0.225)) expect_equal(result$postL, c(0.0859, 0.1787, 0.3931, 0.704)) @@ -31,76 +41,61 @@ test_that("boundsPredprob gives correct result", { expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) }) -test_that("boundsPredprob of beta mixture gives correct result", { +test_that("boundsPredprob with Beta Mixture Priors give correct results with predprob", { result <- boundsPredprob( - looks = c(7, 15, 20), - p0 = 0.2, + looks = c(10, 20), + p0 = 0.20, tT = 0.80, phiL = 0.10, phiU = 0.90, - parE = rbind(c(1, 1), c(3, 10)), + parE = cbind(c(1, 1), c(3, 10)), weights = c(0.2, 0.8) ) - expected <- data.frame( - list( - looks = c(7, 15, 20), - xL = c(1, 3, 6), - pL = c(0.1429, 0.2000, 0.3000), - predL = c(0.0446, 0.0121, 0.0000), - postL = c(0.2407, 0.3818, 0.7734), - UciL = c(0.5207, 0.4398, 0.5078), - xU = c(5, 7, 7), - pU = c(0.7143, 0.4667, 0.3500), - predU = c(0.9843, 1.0000, 1.0000), - postU = c(0.9883, 0.9727, 0.8919), - LciU = c(0.3413, 0.2437, 0.1773) - ) + result_predprob_lower <- predprob( + x = 2, + n = 10, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) ) - expect_equal(result$xL, c(1, 3, 6)) - expect_equal(result$pL, c(0.1429, 0.2000, 0.3000)) - expect_equal(result$predL, c(0.0446, 0.0121, 0.0000)) - expect_equal(result$postL, c(0.2407, 0.3818, 0.7734)) - expect_equal(result$UciL, c(0.5207, 0.4398, 0.5078)) - expect_equal(result$xU, c(5, 7, 7)) - expect_equal(result$pU, c(0.7143, 0.4667, 0.3500)) - expect_equal(result$predU, c(0.9843, 1.0000, 1.0000)) - expect_equal(result$postU, c(0.9883, 0.9727, 0.8919)) - expect_equal(result$LciU, c(0.3413, 0.2437, 0.1773)) -}) - -test_that("boundsPredprob of beta mixture gives correct result", { - result <- boundsPredprob( - looks = c(7, 15, 20), - p0 = 0.2, - tT = 0.80, - phiL = 0.10, - phiU = 0.90, - parE = rbind(c(1, 1), c(3, 10)), + result_predprob_upper <- predprob( + x = 6, + n = 10, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), weights = c(0.2, 0.8) ) expected <- data.frame( list( - looks = c(7, 15, 20), - xL = c(1, 3, 6), - pL = c(0.1429, 0.2000, 0.3000), - predL = c(0.0446, 0.0121, 0.0000), - postL = c(0.2407, 0.3818, 0.7734), - UciL = c(0.5207, 0.4398, 0.5078), - xU = c(5, 7, 7), - pU = c(0.7143, 0.4667, 0.3500), - predU = c(0.9843, 1.0000, 1.0000), - postU = c(0.9883, 0.9727, 0.8919), - LciU = c(0.3413, 0.2437, 0.1773) + looks = c(10, 20), + xL = c(2, 6), + pL = c(0.2, 0.3), + predL = c(0.0409, 0), + postL = c(0.367, 0.7734), + UciL = c(0.5069, 0.5078), + xU = c(6, 7), + pU = c(0.6, 0.35), + predU = c(0.9859, 1), + postU = c(0.9875, 0.8919), + LciU = c(0.3035, 0.1773) ) ) - expect_equal(result$xL, c(1, 3, 6)) - expect_equal(result$pL, c(0.1429, 0.2000, 0.3000)) - expect_equal(result$predL, c(0.0446, 0.0121, 0.0000)) - expect_equal(result$postL, c(0.2407, 0.3818, 0.7734)) - expect_equal(result$UciL, c(0.5207, 0.4398, 0.5078)) - expect_equal(result$xU, c(5, 7, 7)) - expect_equal(result$pU, c(0.7143, 0.4667, 0.3500)) - expect_equal(result$predU, c(0.9843, 1.0000, 1.0000)) - expect_equal(result$postU, c(0.9883, 0.9727, 0.8919)) - expect_equal(result$LciU, c(0.3413, 0.2437, 0.1773)) + expect_equal(result$xL[1], 2) + expect_equal(result$predL[1], result_predprob_lower$result, tolerance = 1e-3) + expect_equal(result$xL[2], 6) + expect_equal(result$predU[1], result_predprob_upper$result, tolerance = 1e-4) + expect_equal(result$xL, c(2, 6)) + expect_equal(result$pL, c(0.2, 0.3)) + expect_equal(result$predL, c(0.0409, 0)) + expect_equal(result$postL, c(0.367, 0.7734)) + expect_equal(result$UciL, c(0.5069, 0.5078)) + expect_equal(result$xU, c(6, 7)) + expect_equal(result$pU, c(0.6, 0.35)) + expect_equal(result$predU, c(0.9859, 1)) + expect_equal(result$postU, c(0.9875, 0.8919)) + expect_equal(result$LciU, c(0.3035, 0.1773)) }) From d9cc2e381daf07b081954b3f748bae1f7e534842 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 20:13:35 +0200 Subject: [PATCH 20/53] resolve conflict when rebasing feature off main --- R/boundsPredprob.R | 73 ++++++++++++++++------------ examples/boundsPredprob.R | 16 +++--- man/boundsPredprob.Rd | 69 +++++++++++++------------- tests/testthat/test-boundsPredprob.R | 33 +++++++++++++ 4 files changed, 117 insertions(+), 74 deletions(-) create mode 100644 tests/testthat/test-boundsPredprob.R diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 66a0de3c..54c64d97 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -1,38 +1,36 @@ -#' Decision cutpoints for boundary (based on predictive probability) +#' Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule. #' #' This function is used to identify the efficacy boundary and futility -#' boundary based on predictive probabilities, i.e.: +#' boundary based on the following rules: #' Efficacy boundary: find minimum x (xU) where -#' Pr(Pr(P > p | x, Y) >= tT | x) > phiU, +#' Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, #' Futility boundary: find maximum x (xL) where -#' Pr(Pr(P > p | x, Y) >= tT | x) < phiL +#' Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL #' -#' @param nvec a vector of number of patients -#' @param Nmax maximum number of patients at the end of the trial -#' (default: maximum of \code{nvec}) -#' @param p threshold on the response rate -#' @param tT threshold on the posterior probability to be above p -#' @param phiL futility boundary predictive probability threshold -#' @param phiU efficacy boundary predictive probability threshold -#' @param a the alpha parameter of a beta prior of treatment group -#' @param b the beta parameter of a beta prior of treatment group -#' @return A matrix where for each sample size in \code{nvec}, this function -#' returns the maximum number of responses that meet the futility -#' threshold (xL), its corresponding response rate (pL), predictive probability -#' (ppL) and posterior probability (postL), the upper bound of one -#' sided 95% CI for the response rate based on an -#' exact binomial test (UciL), and the same boundary parameters for efficacy: -#' the minimal number of responses that meet the efficacy threshold (xU), -#' the corresponding response rate (pU), predictive probability -#' (ppL) and posterior probability (postU), the lower bound of one sided -#' 95% CI for the response rate based on exact binomial test (LciU). +#' @inheritParams predprob +#' @inheritParams ocPredprob +#' @inheritParams boundsPostprob +#' @return A matrix for each same size in `nvec`. For each sample size, the following is returned: +#' - `xL` : the maximum number of responses that meet the futility. +#' threshold +#' - `pL` : response rate corresponding to `xL`. +#' - `ppL` : predictive probability corresponding to `xL` +#' - `postL`: posterior probability corresponding to `xL`. +#' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an +#' exact binomial test. +#' - `xU` : the minimal number of responses that meet the efficacy threshold. +#' - `pU` : response rate corresponding to `xU`. +#' - `postL`: posterior probability corresponding to `xU`. +#' - `ppU` : predictive probability corresponding to `xU` +#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact +#' binomial test. #' #' @importFrom stats binom.test #' #' @example examples/boundsPredprob.R #' @export #' @keywords graphics -boundsPredprob <- function(nvec, Nmax = max(nvec), p, tT, phiL, phiU, a, b) { +boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) { znames <- c( "xL", "pL", "ppL", "postL", "UciL", "xU", "pU", "ppU", "postU", "LciU" @@ -46,29 +44,42 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p, tT, phiL, phiU, a, b) { xL <- NA xU <- NA for (x in 0:n) { - pp <- predprob(x, n, Nmax, p, tT, parE = c(a, b))$result + pp <- predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result if (pp <= phiL) { xL <- x + ppL <- pp } if (pp >= phiU) { xU <- x + ppU <- ppL # done: leave innermost for loop break } } - # reset xU to NA if phiU=1 and n p | x, Y) >= tT | x) > phiU, +Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, Futility boundary: find maximum x (xL) where -Pr(Pr(P > p | x, Y) >= tT | x) < phiL +Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL } \examples{ -## 40 pts trial with interim looks after each 10 pts., -## final efficacy decision if more than 80\% probability to be above 20\% ORR, -## final futility decision otherwise. -## Interim efficacy decision if more than 90\% predictive probability reach this, -## interim futility decision if less than 10\% predictive probability. -## Uniform prior (i.e. beta(1, 1)) on the ORR: +# 40 pts trial with interim looks after each 10 pts., +# final efficacy decision if more than 80\% probability to be above 20\% ORR, +# final futility decision otherwise. +# Interim efficacy decision if more than 90\% predictive probability reach this, +# interim futility decision if less than 10\% predictive probability. +# Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, phiL = 0.10, phiU = 0.90, a = 1, b = 1 ) -## From this we see e.g. that at the first IA at 10 pts, we would stop for futility -## if no patient responded, and for efficacy if 4 or more pts responded. +# From this we see e.g. that at the first IA at 10 pts, we would stop for futility +# if no patient responded, and for efficacy if 4 or more pts responded. } \keyword{graphics} diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R new file mode 100644 index 00000000..5d43c25f --- /dev/null +++ b/tests/testthat/test-boundsPredprob.R @@ -0,0 +1,33 @@ +# boundsPostProb ---- +test_that("boundsPredprob gives correct result and list", { + result <- boundsPredprob( + nvec = c(10, 20, 30, 40), + p0 = 0.2, + tT = 0.80, + phiL = 0.10, + phiU = 0.90, + a = 1, + b = 1 + ) + expected <- data.frame( + list( + nvec = c(10, 20, 30, 40), + xL = c(0, 2, 5, 9), + pL = c(0, 0.1, 0.1667, 0.225), + postL = c(0.0859, 0.1787, 0.3931, 0.704), + UciL = c(0.2589, 0.2826, 0.319, 0.3598), + xU = c(4, 7, 9, 10), + pU = c(0.4, 0.35, 0.3, 0.25), + postU = c(0.9496, 0.9569, 0.9254, 0.8177), + LciU = c(0.15, 0.1773, 0.1663, 0.1424) + ) + ) + expect_equal(result$xL, c(0, 2, 5, 9)) + expect_equal(result$pL, c(0, 0.1, 0.1667, 0.225)) + expect_equal(result$postL, c(0.0859, 0.1787, 0.3931, 0.704)) + expect_equal(result$UciL, c(0.2589, 0.2826, 0.319, 0.3598)) + expect_equal(result$xU, c(4, 7, 9, 10)) + expect_equal(result$pU, c(0.4, 0.35, 0.3, 0.25)) + expect_equal(result$postU, c(0.9496, 0.9569, 0.9254, 0.8177)) + expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) +}) From a2194d7f7a32e1cc2ed229d3f06653201ec7e78d Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:08:22 +0000 Subject: [PATCH 21/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From e42ce48d6ec5719be1a95e3511f942459a413b50 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 21:23:33 +0200 Subject: [PATCH 22/53] clean --- R/boundsPostprob.R | 16 +++--- man/boundsPostprob.Rd | 10 ++-- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 16 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index a35fef8d..7e555993 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -23,19 +23,17 @@ #' #' @example examples/boundsPostprob.R #' @export -boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) { - assert_numeric(looks) - assert_number(p0, lower = 0, upper = 1) - assert_number(p1, lower = 0, upper = 1) - assert_number(tL, lower = 0, upper = 1) - assert_number(tU, lower = 0, upper = 1) - assert_numeric(parE, min.len = 2, any.missing = FALSE) - z <- matrix(NA, nrow = length(looks), ncol = 8) +#' @keywords graphics +boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { + z <- matrix(NA, length(nvec), ncol = 6) znames <- c( "xL", "pL", "postL", "pL_upper_ci", "xU", "pU", "postU", "pU_lower_ci" ) - dimnames(z) <- list(looks, znames) + dimnames(z) <- list(nvec, znames) + + z <- matrix(NA, length(nvec), length(znames)) + dimnames(z) <- list(nvec, znames) k <- 0 parE <- t(parE) if (missing(weights)) { diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index b21240cd..5d99cf35 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -4,11 +4,9 @@ \alias{boundsPostprob} \title{Decision cutpoints for boundary (based on posterior probability)} \usage{ -boundsPostprob(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) +boundsPostprob(nvec, p0, p1 = p0, tL, tU, a, b) } \arguments{ -\item{looks}{(\code{numeric}):\cr A vector of number of patients in each look.} - \item{p0}{(\code{number}):\cr lower Futility threshold of response rate.} \item{p1}{(\code{number}):\cr upper Efficacy threshold of response rate.} @@ -17,10 +15,7 @@ boundsPostprob(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} -\item{parE}{(\code{matrix}):\cr the beta parameters matrix, with \code{K} rows and 2 columns, -corresponding to the beta parameters of the \code{K} components.} - -\item{weights}{(\code{vector}):\cr The mixture weights of the beta mixture prior.} +\item{looks}{(\code{numeric}):\cr A vector of number of patients in each look.} } \value{ A matrix for each same size in \code{looks}. For each sample size, the following is returned: @@ -71,3 +66,4 @@ boundsPostprob( weights = c(0.2, 0.8) ) } +\keyword{graphics} diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From f544973c3c71d4f122aca75857b115692df0992e Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:07:33 +0000 Subject: [PATCH 23/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From db70515144306b7e3bc80b1bf6d9c688c4b19958 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 21:25:17 +0200 Subject: [PATCH 24/53] clean --- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From ea185a8ffa5fe0b7be0b7d260577145ef5d5aabe Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 21:30:07 +0200 Subject: [PATCH 25/53] clean --- R/boundsPostprob.R | 16 +++++++++------- man/boundsPostprob.Rd | 10 +++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 7e555993..a35fef8d 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -23,17 +23,19 @@ #' #' @example examples/boundsPostprob.R #' @export -#' @keywords graphics -boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { - z <- matrix(NA, length(nvec), ncol = 6) +boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) { + assert_numeric(looks) + assert_number(p0, lower = 0, upper = 1) + assert_number(p1, lower = 0, upper = 1) + assert_number(tL, lower = 0, upper = 1) + assert_number(tU, lower = 0, upper = 1) + assert_numeric(parE, min.len = 2, any.missing = FALSE) + z <- matrix(NA, nrow = length(looks), ncol = 8) znames <- c( "xL", "pL", "postL", "pL_upper_ci", "xU", "pU", "postU", "pU_lower_ci" ) - dimnames(z) <- list(nvec, znames) - - z <- matrix(NA, length(nvec), length(znames)) - dimnames(z) <- list(nvec, znames) + dimnames(z) <- list(looks, znames) k <- 0 parE <- t(parE) if (missing(weights)) { diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 5d99cf35..b21240cd 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -4,9 +4,11 @@ \alias{boundsPostprob} \title{Decision cutpoints for boundary (based on posterior probability)} \usage{ -boundsPostprob(nvec, p0, p1 = p0, tL, tU, a, b) +boundsPostprob(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) } \arguments{ +\item{looks}{(\code{numeric}):\cr A vector of number of patients in each look.} + \item{p0}{(\code{number}):\cr lower Futility threshold of response rate.} \item{p1}{(\code{number}):\cr upper Efficacy threshold of response rate.} @@ -15,7 +17,10 @@ boundsPostprob(nvec, p0, p1 = p0, tL, tU, a, b) \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} -\item{looks}{(\code{numeric}):\cr A vector of number of patients in each look.} +\item{parE}{(\code{matrix}):\cr the beta parameters matrix, with \code{K} rows and 2 columns, +corresponding to the beta parameters of the \code{K} components.} + +\item{weights}{(\code{vector}):\cr The mixture weights of the beta mixture prior.} } \value{ A matrix for each same size in \code{looks}. For each sample size, the following is returned: @@ -66,4 +71,3 @@ boundsPostprob( weights = c(0.2, 0.8) ) } -\keyword{graphics} From 9e42113d5f9f59f7690a7a705fbfecf29a84bbb5 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 06:22:27 +0000 Subject: [PATCH 26/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From 0e945351b54681bd1ac484e86309340ce07660a7 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:29:24 +0000 Subject: [PATCH 27/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/ocPredprob.Rd | 121 ---------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..25c8d9e2 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,124 +117,3 @@ The criteria for Decision 2 for Futility looks are : } } } -\examples{ -# Here we illustrate an example for Decision 1 with the following assumptions : -# True response rate or truep of the treatment group = 40\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 1 with no wiggle. -set.seed(20) -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - decision1 = TRUE -) -result$oc - -# Decision 1 with wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.4, - p0 = 0.25, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.4, - p0 = 0.25, - p1 = 0.2, - tT = 0.6, - phiL = 0.2, - phiU = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = TRUE, - nnF = c(10, 15, 20), - decision1 = TRUE -) -result$oc - -# Here we illustrate an example for Decision 2 with the following assumptions : -# True response rate or truep of the treatment group = 60\% -# The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF -# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu -# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. - -# Decision 2 without wiggle. -result <- ocPredprob( - nnE = c(10, 20), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiU = 0.8, - phiFu = 0.8, - parE = c(1, 1), - sim = 50, - wiggle = FALSE, - nnF = c(10, 20), - decision1 = FALSE -) -result$oc - -# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. -result <- ocPredprob( - nnE = c(10, 25, 30), - truep = 0.6, - p0 = 0.25, - p1 = 0.25, - tT = 0.6, - tF = 0.6, - phiL = 0.8, - phiU = 0.8, - parE = c(11, 19), - sim = 50, - wiggle = TRUE, - nnF = 30, - decision1 = FALSE -) -result$oc -} From c9907745be934e5b8ff8a7646d4622e901ee19fc Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 10 Oct 2024 21:39:59 +0200 Subject: [PATCH 28/53] clean --- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} From bb749b91dedab121f04d1d2d0f142d1afa55e831 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 11 Oct 2024 13:49:23 +0200 Subject: [PATCH 29/53] clean --- examples/plotBounds.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/plotBounds.R b/examples/plotBounds.R index 42c34b05..c28479ea 100644 --- a/examples/plotBounds.R +++ b/examples/plotBounds.R @@ -1 +1,9 @@ # examples +plotBounds(boundsPredprob( + nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, a = 1, b = 1 +), yt = "x") +plotBounds(boundsPredprob( + nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, a = 1, b = 1 +), yt = "p") From fc3bd8e5972bf73dc986a080f13ff149f3166d48 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 11 Oct 2024 13:51:21 +0200 Subject: [PATCH 30/53] clean --- examples/plotBounds.R | 8 -- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPredprob.R | 4 +- 3 files changed, 123 insertions(+), 10 deletions(-) diff --git a/examples/plotBounds.R b/examples/plotBounds.R index c28479ea..42c34b05 100644 --- a/examples/plotBounds.R +++ b/examples/plotBounds.R @@ -1,9 +1 @@ # examples -plotBounds(boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 -), yt = "x") -plotBounds(boundsPredprob( - nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, - phiL = 0.10, phiU = 0.90, a = 1, b = 1 -), yt = "p") diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 25c8d9e2..63e17a09 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,3 +117,124 @@ The criteria for Decision 2 for Futility looks are : } } } +\examples{ +# Here we illustrate an example for Decision 1 with the following assumptions : +# True response rate or truep of the treatment group = 40\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 1 with no wiggle. +set.seed(20) +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + decision1 = TRUE +) +result$oc + +# Decision 1 with wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.4, + p0 = 0.25, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final without wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Decision 1 with separate Futility and Efficacy looks at interim and final with wiggle. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.4, + p0 = 0.25, + p1 = 0.2, + tT = 0.6, + phiL = 0.2, + phiU = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = TRUE, + nnF = c(10, 15, 20), + decision1 = TRUE +) +result$oc + +# Here we illustrate an example for Decision 2 with the following assumptions : +# True response rate or truep of the treatment group = 60\% +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT +# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU +# - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu +# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. + +# Decision 2 without wiggle. +result <- ocPredprob( + nnE = c(10, 20), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiU = 0.8, + phiFu = 0.8, + parE = c(1, 1), + sim = 50, + wiggle = FALSE, + nnF = c(10, 20), + decision1 = FALSE +) +result$oc + +# Decision 2 with wiggle and with Futility only at final with non-uniform beta prior parE. +result <- ocPredprob( + nnE = c(10, 25, 30), + truep = 0.6, + p0 = 0.25, + p1 = 0.25, + tT = 0.6, + tF = 0.6, + phiL = 0.8, + phiU = 0.8, + parE = c(11, 19), + sim = 50, + wiggle = TRUE, + nnF = 30, + decision1 = FALSE +) +result$oc +} diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index 9ff4d20d..cc51ea33 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -1,4 +1,4 @@ -# boundsPredProb ---- +# boundsPredprob ---- test_that("boundsPredprob gives correct result and when default weight is not assigned", { result_weights <- boundsPredprob( looks = c(10, 20, 30, 40), @@ -40,7 +40,7 @@ test_that("boundsPredprob gives correct result and when default weight is not as expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) }) -test_that("boundsPredprob with Beta Mixture Priors give correct results with predprob", { +test_that("boundsPredprob with Beta Mixture Priors give correct results", { result <- boundsPredprob( looks = c(10, 20), p0 = 0.20, From 7ab498b1ba886d04647d1973dd861e249a852ca1 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 11 Oct 2024 20:41:10 +0200 Subject: [PATCH 31/53] clean --- R/boundsPredprob.R | 13 ++++++++----- man/boundsPredprob.Rd | 10 +++++++--- tests/testthat/test-boundsPredprob.R | 4 +++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 302cfe3d..23d34966 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -1,11 +1,7 @@ #' Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule. #' #' This function is used to identify the efficacy boundary and futility -#' boundary based on the following rules: -#' Efficacy boundary: find minimum x (xU) where -#' Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, -#' Futility boundary: find maximum x (xL) where -#' Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL +#' boundary based on rules in @details. #' #' @inheritParams predprob #' @inheritParams ocPredprob @@ -27,6 +23,13 @@ #' #' @importFrom stats binom.test #' +#' @details see also `predprob()` +#' The following rules are Decision 1 rules: +#' Efficacy boundary: find minimum x (xU) where +#' Pr(Pr(response rate > p0 | data) >= tT | x) >= phiU, +#' Futility boundary: find maximum x (xL) where +#' Pr(Pr(response rate > p0 | data) >= tT | x) =< phiL +#' #' @example examples/boundsPredprob.R #' @export #' @keywords graphics diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index aba286bc..6fa7c081 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -53,11 +53,15 @@ binomial test. } \description{ This function is used to identify the efficacy boundary and futility -boundary based on the following rules: +boundary based on rules in @details. +} +\details{ +see also \code{predprob()} +The following rules are Decision 1 rules: Efficacy boundary: find minimum x (xU) where -Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +Pr(Pr(response rate > p0 | data) >= tT | x) >= phiU, Futility boundary: find maximum x (xL) where -Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL +Pr(Pr(response rate > p0 | data) >= tT | x) =< phiL } \examples{ # 40 pts trial with interim looks after each 10 patients. diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index cc51ea33..8de932ad 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -19,13 +19,15 @@ test_that("boundsPredprob gives correct result and when default weight is not as ) expected <- data.frame( list( - nvec = c(10, 20, 30, 40), + looks = c(10, 20, 30, 40), xL = c(0, 2, 5, 9), pL = c(0, 0.1, 0.1667, 0.225), + predL = c(0.0268, 0.0269, 0.0446, 0.0000), postL = c(0.0859, 0.1787, 0.3931, 0.704), UciL = c(0.2589, 0.2826, 0.319, 0.3598), xU = c(4, 7, 9, 10), pU = c(0.4, 0.35, 0.3, 0.25), + predU = c(0.9287, 0.9600, 0.9604, 1.0000), postU = c(0.9496, 0.9569, 0.9254, 0.8177), LciU = c(0.15, 0.1773, 0.1663, 0.1424) ) From 053547d41e233470554c162baae648fd076e2c79 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 11 Oct 2024 20:42:33 +0200 Subject: [PATCH 32/53] clean --- R/boundsPredprob.R | 2 +- man/boundsPredprob.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 23d34966..4ff0529e 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -17,7 +17,7 @@ #' - `xU` : the minimal number of responses that meet the efficacy threshold. #' - `pU` : response rate corresponding to `xU`. #' - `predU` : predictive probability corresponding to `xU` -#' - `postL`: posterior probability corresponding to `xU`. +#' - `postU`: posterior probability corresponding to `xU`. #' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact #' binomial test. #' diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 6fa7c081..bf9b1597 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -46,7 +46,7 @@ exact binomial test. \item \code{xU} : the minimal number of responses that meet the efficacy threshold. \item \code{pU} : response rate corresponding to \code{xU}. \item \code{predU} : predictive probability corresponding to \code{xU} -\item \code{postL}: posterior probability corresponding to \code{xU}. +\item \code{postU}: posterior probability corresponding to \code{xU}. \item \code{LciU} : lower bound of one sided 95\% CI for the response rate based on exact binomial test. } From f41678829d6bad332a5562a7627560642ddbe658 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 15 Oct 2024 11:01:38 +0200 Subject: [PATCH 33/53] empty From abe8a2cf917af3b7383fe9bdbb69d2d3cd97dd76 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 15 Oct 2024 20:55:25 +0200 Subject: [PATCH 34/53] empty From 855dc8ec2957a5c7b5e76f8c4b8d90adde8a2513 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Wed, 16 Oct 2024 14:35:00 +0200 Subject: [PATCH 35/53] added plotBounds(boundsPredprob()) examples --- R/plotBounds.R | 20 ++++++++++---------- examples/plotBounds.R | 8 ++++++++ man/plotBounds.Rd | 8 ++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/R/plotBounds.R b/R/plotBounds.R index b396549a..4e956771 100644 --- a/R/plotBounds.R +++ b/R/plotBounds.R @@ -31,8 +31,8 @@ plotBounds <- function(z, area = TRUE, grid = TRUE, yt = "x", add = FALSE, cols = c("green", "red", "darkgreen", "orange"), lwds = c(3, 3), ltype = "l", lpch = 16, lcex = 1, gy = 20) { n <- nrow(z) - nmin <- min(z$nvec) - nmax <- max(z$nvec) + nmin <- min(z$looks) + nmax <- max(z$looks) if (yt == "x") { z1 <- z$xL z2 <- z$xU @@ -51,38 +51,38 @@ plotBounds <- function(z, area = TRUE, grid = TRUE, yt = "x", add = FALSE, stop("yt can only be x or p") } if (add) { - graphics::lines(z$nvec, z2, + graphics::lines(z$looks, z2, lwd = lwds[1], col = cols[3], type = ltype, pch = lpch, cex = lcex ) - graphics::lines(z$nvec, z1, + graphics::lines(z$looks, z1, lwd = lwds[2], col = cols[4], type = ltype, pch = lpch, cex = lcex ) return(invisible()) } - graphics::plot(z$nvec, rep(0, n), - xlim = c(0, max(z$nvec)), ylim = c(0, yU), type = "n", + graphics::plot(z$looks, rep(0, n), + xlim = c(0, max(z$looks)), ylim = c(0, yU), type = "n", xlab = "n", ylab = ylabel ) if (grid) { graphics::abline(h = gridy, col = "gray") } if (area) { - graphics::polygon(c(z$nvec, nmax, nmin), c(z2, yU, yU2), + graphics::polygon(c(z$looks, nmax, nmin), c(z2, yU, yU2), lwd = lwds[1], col = cols[1], border = cols[1] ) - graphics::polygon(c(z$nvec, nmax, nmin), c(z1, 0, 0), + graphics::polygon(c(z$looks, nmax, nmin), c(z1, 0, 0), lwd = lwds[2], col = cols[2], border = cols[2] ) } else { - graphics::lines(z$nvec, z2, + graphics::lines(z$looks, z2, lwd = lwds[1], col = cols[1], type = ltype, pch = lpch, cex = lcex ) - graphics::lines(z$nvec, z1, + graphics::lines(z$looks, z1, lwd = lwds[2], col = cols[2], type = ltype, pch = lpch, cex = lcex ) diff --git a/examples/plotBounds.R b/examples/plotBounds.R index 42c34b05..3c32d666 100644 --- a/examples/plotBounds.R +++ b/examples/plotBounds.R @@ -1 +1,9 @@ # examples +plotBounds(boundsPredprob( + looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, +), yt = "x") +plotBounds(boundsPredprob( + looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, +), yt = "p") diff --git a/man/plotBounds.Rd b/man/plotBounds.Rd index 1cd568db..df1bb128 100644 --- a/man/plotBounds.Rd +++ b/man/plotBounds.Rd @@ -56,5 +56,13 @@ and \code{\link{boundsPostprob}} } \examples{ # examples +plotBounds(boundsPredprob( + looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, +), yt = "x") +plotBounds(boundsPredprob( + looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, +), yt = "p") } \keyword{graphics} From a133d9225f3698fc9df2a92a22f6f731daa8e630 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Wed, 16 Oct 2024 14:38:05 +0200 Subject: [PATCH 36/53] added plotBounds(boundsPredprob()) examples and plotBounds( --- examples/plotBounds.R | 7 +++++++ man/plotBounds.Rd | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/examples/plotBounds.R b/examples/plotBounds.R index 3c32d666..c39fc05b 100644 --- a/examples/plotBounds.R +++ b/examples/plotBounds.R @@ -1,4 +1,11 @@ # examples +plotBounds( + boundsPostprob( + looks = c(10, 20, 30, 40), p0 = 0.20, + tL = 0.10, tU = 0.90, parE = c(1, 1) + ), + yt = "p", add = TRUE +) plotBounds(boundsPredprob( looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, phiL = 0.10, phiU = 0.90, diff --git a/man/plotBounds.Rd b/man/plotBounds.Rd index df1bb128..0caf508c 100644 --- a/man/plotBounds.Rd +++ b/man/plotBounds.Rd @@ -56,6 +56,13 @@ and \code{\link{boundsPostprob}} } \examples{ # examples +plotBounds( + boundsPostprob( + looks = c(10, 20, 30, 40), p0 = 0.20, + tL = 0.10, tU = 0.90, parE = c(1, 1) + ), + yt = "p", add = TRUE +) plotBounds(boundsPredprob( looks = c(10, 20, 30, 40), p0 = 0.20, tT = 0.80, phiL = 0.10, phiU = 0.90, From ed3aea6e77eb129929127e78449bee0962ef68a2 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sat, 19 Oct 2024 11:03:14 +0200 Subject: [PATCH 37/53] Update R/boundsPredprob.R Co-authored-by: Daniel Sabanes Bove --- R/boundsPredprob.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 4ff0529e..b453e9b0 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -7,7 +7,7 @@ #' @inheritParams ocPredprob #' @inheritParams boundsPostprob #' @return A matrix for each same size in `looks`. For each sample size, the following is returned: -#' - `xL` : the maximum number of responses that meet the futility. +#' - `xL` : the maximum number of responses that meet the futility #' threshold #' - `pL` : response rate corresponding to `xL`. #' - `predL` : predictive probability corresponding to `xL` From 17fbce44ef77e3ce60c896428c749c7f4d03f651 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 09:05:21 +0000 Subject: [PATCH 38/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/boundsPredprob.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index bf9b1597..6b3f4396 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -36,7 +36,7 @@ corresponding to the beta parameters of the K components.} \value{ A matrix for each same size in \code{looks}. For each sample size, the following is returned: \itemize{ -\item \code{xL} : the maximum number of responses that meet the futility. +\item \code{xL} : the maximum number of responses that meet the futility threshold \item \code{pL} : response rate corresponding to \code{xL}. \item \code{predL} : predictive probability corresponding to \code{xL} From 2d1ed9445119dd6df8a0102c034a33d123d7bfc0 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sat, 19 Oct 2024 15:02:31 +0200 Subject: [PATCH 39/53] clean --- R/boundsPredprob.R | 10 ++++++---- man/boundsPredprob.Rd | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index b453e9b0..82b6faf9 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -12,13 +12,13 @@ #' - `pL` : response rate corresponding to `xL`. #' - `predL` : predictive probability corresponding to `xL` #' - `postL`: posterior probability corresponding to `xL`. -#' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an +#' - `pL_upper_ci` : upper bound of one sided 95% CI for the response rate based on an #' exact binomial test. #' - `xU` : the minimal number of responses that meet the efficacy threshold. #' - `pU` : response rate corresponding to `xU`. #' - `predU` : predictive probability corresponding to `xU` #' - `postU`: posterior probability corresponding to `xU`. -#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact +#' - `pU_lower_ci` : lower bound of one sided 95% CI for the response rate based on exact #' binomial test. #' #' @importFrom stats binom.test @@ -37,6 +37,8 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = assert_numeric(looks) assert_number(p0, lower = 0, upper = 1) assert_number(tT, lower = 0, upper = 1) + assert_number(phiU, lower = 0, upper = 1) + assert_number(phiL, lower = 0, upper = 1) assert_numeric(parE, min.len = 2, any.missing = FALSE) znames <- c( "xL", "pL", "predL", "postL", "UciL", @@ -52,11 +54,11 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = xU <- NA for (x in 0:n) { predprob <- predprob(x = x, n = n, Nmax = max(looks), p = p0, thetaT = tT, parE = parE, weights = weights)$result - if (predprob <= phiL) { # Futility look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL + if (predprob <= phiL) { # Futility look, Rule Pr(Pr( RR > p0 | x, Y) >= tT | x) =< phiL xL <- x predL <- predprob } - if (predprob >= phiU) { # Efficacy look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, + if (predprob >= phiU) { # Efficacy look, Rule Pr(Pr( RR > p0 | x, Y) >= tT | x) >= phiU, xU <- x predU <- predprob break diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 6b3f4396..96ec30b3 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -41,13 +41,13 @@ threshold \item \code{pL} : response rate corresponding to \code{xL}. \item \code{predL} : predictive probability corresponding to \code{xL} \item \code{postL}: posterior probability corresponding to \code{xL}. -\item \code{Ucil} : upper bound of one sided 95\% CI for the response rate based on an +\item \code{pL_upper_ci} : upper bound of one sided 95\% CI for the response rate based on an exact binomial test. \item \code{xU} : the minimal number of responses that meet the efficacy threshold. \item \code{pU} : response rate corresponding to \code{xU}. \item \code{predU} : predictive probability corresponding to \code{xU} \item \code{postU}: posterior probability corresponding to \code{xU}. -\item \code{LciU} : lower bound of one sided 95\% CI for the response rate based on exact +\item \code{pU_lower_ci} : lower bound of one sided 95\% CI for the response rate based on exact binomial test. } } From 09a374405a634adac22c70ad289e8413cc4365d0 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sat, 19 Oct 2024 15:07:32 +0200 Subject: [PATCH 40/53] make sure helper functions are written with all input arguments --- R/boundsPostprob.R | 4 ++-- R/boundsPredprob.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index a35fef8d..da0db1e8 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -48,12 +48,12 @@ boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) xL <- NA xU <- NA for (x in 0:n) { - postp_fut <- 1 - postprob(x, n, p0, parE, weights) # futility look + postp_fut <- 1 - postprob(x = x, n = x, p = p0, parE = parE, weights = weights) # futility look if (postp_fut >= tL) { # Rule is P(RR < p0) > tL postL <- postp_fut xL <- x } - postp_eff <- postprob(x, n, p1, parE, weights) # efficacy look + postp_eff <- postprob(x = x, n = n, p1 = p1, parE = parE, weights = weights) # efficacy look if (postp_eff >= tU) { # Rule is P(RR > p1) > tU postU <- postp_eff xU <- x diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 82b6faf9..fcb99a30 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -69,8 +69,8 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = xU <- NA } # calculate predictive and posterior probabilities at boundaries - postL <- postprob(xL, n, p0, parE = parE) - postU <- postprob(xU, n, p0, parE = parE) + postL <- postprob(x = xL, n = n, p = p0, parE = parE, weights = weights, log.p = FALSE) + postU <- postprob(x = xU, n = n, p = p0, parE = parE, weights = weights, log.p = FALSE) # calculate lower CI at boundaries pL_upper_ci <- ifelse(!is.na(xL), stats::binom.test(xL, n, alt = "less")$conf.int[2], NA) pU_lower_ci <- ifelse(!is.na(xU), stats::binom.test(xU, n, alt = "greater")$conf.int[1], NA) From 5dce59ecb92209818e3c898132e8984d7130675a Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sat, 19 Oct 2024 15:10:05 +0200 Subject: [PATCH 41/53] clean --- examples/boundsPredprob.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index 934c0064..61f0c0e8 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -2,9 +2,9 @@ # Final efficacy decision if more than 80% probability to be above 20% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(P > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 10% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL +# Futility look Pr(Pr(P > p0 | x, Y) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( looks = c(10, 20, 30, 40), @@ -18,9 +18,9 @@ boundsPredprob( # Efficacy decision if more than 80% probability to be above 20% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(P > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 60% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi +# Futility look Pr(Pr(P > p0 | x, Y) >= tT | x) =< phi # with mixed prior and weights: boundsPredprob( looks = c(7, 15, 25), From 07359b7e2bb9792aaf1cf0c361959d5912a06f65 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:12:21 +0000 Subject: [PATCH 42/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/boundsPredprob.Rd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 96ec30b3..815ea002 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -68,9 +68,9 @@ Pr(Pr(response rate > p0 | data) >= tT | x) =< phiL # Final efficacy decision if more than 80\% probability to be above 20\% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90\% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(P > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 10\% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL +# Futility look Pr(Pr(P > p0 | x, Y) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( looks = c(10, 20, 30, 40), @@ -84,9 +84,9 @@ boundsPredprob( # Efficacy decision if more than 80\% probability to be above 20\% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90\% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(P > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 60\% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi +# Futility look Pr(Pr(P > p0 | x, Y) >= tT | x) =< phi # with mixed prior and weights: boundsPredprob( looks = c(7, 15, 25), From 9db05d74d2e8bbe062bc3bf39beb9732ec489dfd Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 21 Nov 2024 21:28:33 +0100 Subject: [PATCH 43/53] clean --- R/boundsPostprob.R | 4 ++-- R/boundsPredprob.R | 14 +++++++++++--- examples/boundsPredprob.R | 8 ++++---- examples/ocPredprobDist.R | 15 +++++---------- man/boundsPostprob.Rd | 2 +- man/boundsPredprob.Rd | 12 ++++++------ man/ocPredprobDist.Rd | 15 +++++---------- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index da0db1e8..0fcedb17 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -2,7 +2,7 @@ #' #' This function is used to identify the efficacy and futility #' boundaries based on the following rules: -#' Efficacy boundary: find minimum x (xU) where Pr(RR > p1 |x, n, a, b) >= tU and +#' Efficacy boundary: find minimum x (xU) where Pr(RR > p1 | x, n, a, b) >= tU and #' Futility boundary: find maximum x (xL) where Pr(RR < p0 | x, n, a, b) >= tL #' #' @inheritParams postprob @@ -53,7 +53,7 @@ boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) postL <- postp_fut xL <- x } - postp_eff <- postprob(x = x, n = n, p1 = p1, parE = parE, weights = weights) # efficacy look + postp_eff <- postprob(x = x, n = n, p = p1, parE = parE, weights = weights) # efficacy look if (postp_eff >= tU) { # Rule is P(RR > p1) > tU postU <- postp_eff xU <- x diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index fcb99a30..4a9fdee9 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -26,9 +26,9 @@ #' @details see also `predprob()` #' The following rules are Decision 1 rules: #' Efficacy boundary: find minimum x (xU) where -#' Pr(Pr(response rate > p0 | data) >= tT | x) >= phiU, +#' Pr(Pr(RR > p0 | data) >= tT | x) >= phiU, #' Futility boundary: find maximum x (xL) where -#' Pr(Pr(response rate > p0 | data) >= tT | x) =< phiL +#' Pr(Pr(RR > p0 | data) >= tT | x) =< phiL #' #' @example examples/boundsPredprob.R #' @export @@ -53,7 +53,15 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = xL <- NA xU <- NA for (x in 0:n) { - predprob <- predprob(x = x, n = n, Nmax = max(looks), p = p0, thetaT = tT, parE = parE, weights = weights)$result + predprob <- predprob( + x = x, + n = n, + Nmax = max(looks), + p = p0, + thetaT = tT, + parE = parE, + weights = weights + )$result if (predprob <= phiL) { # Futility look, Rule Pr(Pr( RR > p0 | x, Y) >= tT | x) =< phiL xL <- x predL <- predprob diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index 61f0c0e8..ce66c059 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -2,9 +2,9 @@ # Final efficacy decision if more than 80% probability to be above 20% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 10% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y) >= tT | x) =< phiL +# Futility look Pr(Pr(RR) > p0 | x, Y) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( looks = c(10, 20, 30, 40), @@ -18,9 +18,9 @@ boundsPredprob( # Efficacy decision if more than 80% probability to be above 20% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 60% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y) >= tT | x) =< phi +# Futility look Pr(Pr(RR > p0 | x, Y) >= tT | x) =< phi # with mixed prior and weights: boundsPredprob( looks = c(7, 15, 25), diff --git a/examples/ocPredprobDist.R b/examples/ocPredprobDist.R index 19982cf1..a09387e4 100644 --- a/examples/ocPredprobDist.R +++ b/examples/ocPredprobDist.R @@ -41,10 +41,8 @@ result$oc # Desired difference to Standard of Care for Efficacy and Futility is 10% and -10% respectively. # Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules. # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or -# P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or -# P(response rate + deltaF > p0) < tT +# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P( response rate + deltaE > p0) > tT +# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P( response rate + deltaF > p0) < tT # - Interim look for Efficacy: Pr( success at final ) > 80% or # P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20% or @@ -78,12 +76,9 @@ result$oc # True response rate or truep of the treatment group = 40% # Desired difference to Standard of Care for Efficacy and Futility = 50% # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or -# P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or -# P(response rate + deltaF > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80% or -# P(success at final) > phiU +# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT +# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20% or # P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index b21240cd..1fa8bde4 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -40,7 +40,7 @@ binomial test. \description{ This function is used to identify the efficacy and futility boundaries based on the following rules: -Efficacy boundary: find minimum x (xU) where Pr(RR > p1 |x, n, a, b) >= tU and +Efficacy boundary: find minimum x (xU) where Pr(RR > p1 | x, n, a, b) >= tU and Futility boundary: find maximum x (xL) where Pr(RR < p0 | x, n, a, b) >= tL } \examples{ diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 96ec30b3..d3db96d7 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -59,18 +59,18 @@ boundary based on rules in @details. see also \code{predprob()} The following rules are Decision 1 rules: Efficacy boundary: find minimum x (xU) where -Pr(Pr(response rate > p0 | data) >= tT | x) >= phiU, +Pr(Pr(RR > p0 | data) >= tT | x) >= phiU, Futility boundary: find maximum x (xL) where -Pr(Pr(response rate > p0 | data) >= tT | x) =< phiL +Pr(Pr(RR > p0 | data) >= tT | x) =< phiL } \examples{ # 40 pts trial with interim looks after each 10 patients. # Final efficacy decision if more than 80\% probability to be above 20\% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90\% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 10\% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL +# Futility look Pr(Pr(RR) > p0 | x, Y) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( looks = c(10, 20, 30, 40), @@ -84,9 +84,9 @@ boundsPredprob( # Efficacy decision if more than 80\% probability to be above 20\% ORR, # Final futility decision otherwise. # Interim efficacy decision if more than 90\% predictive probability reach this or -# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU, +# Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 60\% predictive probability or -# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi +# Futility look Pr(Pr(RR > p0 | x, Y) >= tT | x) =< phi # with mixed prior and weights: boundsPredprob( looks = c(7, 15, 25), diff --git a/man/ocPredprobDist.Rd b/man/ocPredprobDist.Rd index 99accac9..c13b3efd 100644 --- a/man/ocPredprobDist.Rd +++ b/man/ocPredprobDist.Rd @@ -175,10 +175,8 @@ result$oc # Desired difference to Standard of Care for Efficacy and Futility is 10\% and -10\% respectively. # Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules. # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or -# P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or -# P(response rate + deltaF > p0) < tT +# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or P( response rate + deltaE > p0) > tT +# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or P( response rate + deltaF > p0) < tT # - Interim look for Efficacy: Pr( success at final ) > 80\% or # P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20\% or @@ -212,12 +210,9 @@ result$oc # True response rate or truep of the treatment group = 40\% # Desired difference to Standard of Care for Efficacy and Futility = 50\% # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or -# P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or -# P(response rate + deltaF > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or -# P(success at final) > phiU +# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or P(response rate + deltaE > p0) > tT +# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or P(response rate + deltaF > p0) < tT +# - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20\% or # P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. From 47d51558044b189d3077f244c0d7192c82e71d50 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 30 Dec 2024 18:57:47 +0100 Subject: [PATCH 44/53] clean --- R/ocPostprobDist.R | 4 ++-- examples/ocPostprobDist.R | 2 -- examples/ocPredprob.R | 8 ++++---- examples/ocPredprobDist.R | 28 +++++++++++----------------- man/ocPostprobDist.Rd | 6 ++---- man/ocPredprob.Rd | 8 ++++---- man/ocPredprobDist.Rd | 28 +++++++++++----------------- 7 files changed, 34 insertions(+), 50 deletions(-) diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index d82424d7..f2559d92 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -103,11 +103,11 @@ h_get_decisionDist <- function(nnr, #' #' Stop criteria for Efficacy : #' -#' `Pr(truep > P_S + deltaE) > tU` +#' `Pr(RR > P_S + deltaE) > tU` #' #' Stop criteria for Futility : #' -#' `Pr(truep < P_S + deltaF) > tL` +#' `Pr(RR < P_S + deltaF) > tL` #' #' Where `truep` is the assumed true rate of response and `p1` and `p0` respectively are #' the thresholds for Efficacy and Futility respectively. diff --git a/examples/ocPostprobDist.R b/examples/ocPostprobDist.R index 42355591..3161f6f5 100644 --- a/examples/ocPostprobDist.R +++ b/examples/ocPostprobDist.R @@ -3,8 +3,6 @@ # True response rate or truep of the treatment group = 40% # The following are the Go and Stop rules respectively : # Prior of treatment arm parE= Beta(1,1). -# stop for efficacy (deltaE): Pr(truep > P_S + deltaE) > tU -# stop for futility (deltaF): Pr(truep < P_S + deltaF) > tL # Without random distance allowed for Futility and Efficacy Looks. res1 <- ocPostprobDist( nnE = c(10, 20, 30), diff --git a/examples/ocPredprob.R b/examples/ocPredprob.R index bed3d299..72741aea 100644 --- a/examples/ocPredprob.R +++ b/examples/ocPredprob.R @@ -1,8 +1,8 @@ # Here we illustrate an example for Decision 1 with the following assumptions : # True response rate or truep of the treatment group = 40% # The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25% ) > 60% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25% ) < 60% or P(response rate > p0) < tT +# - Final look for Efficacy: Pr( RR > 25% ) > 60% or P( RR > p0) > tT +# - Final look for Futility: Pr( RR < 25% ) < 60% or P(RR > p0) < tT # - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20% or P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. @@ -76,8 +76,8 @@ result$oc # Here we illustrate an example for Decision 2 with the following assumptions : # True response rate or truep of the treatment group = 60% # The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25% ) > 60% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25% ) < 60% or P(response rate < p1) > tF +# - Final look for Efficacy: Pr( RR > 25% ) > 60% or P(RR > p0) > tT +# - Final look for Futility: Pr( RR < 25% ) < 60% or P(RR < p1) > tF # - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) > 80% or P(failure at final) > phiFu # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. diff --git a/examples/ocPredprobDist.R b/examples/ocPredprobDist.R index a09387e4..7ebee7e1 100644 --- a/examples/ocPredprobDist.R +++ b/examples/ocPredprobDist.R @@ -2,15 +2,11 @@ # Efficacy Looks and Futility looks are identical at sample size of 10, 20 and 30. # True response rate or truep of the treatment group = 40% # Desired difference to Standard of Care for Efficacy and Futility = 10% -# Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: -# Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT -# - Final look for Futility: -# Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT -# - Interim look for Efficacy: -# Pr( success at final ) > 80% or P(success at final) > phiU -# - Interim look for Futility: -# Pr( success at final ) < 20% or P(success at final) < phiL +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( RR + deltaE > 25% ) > 60% +# - Final look for Futility: Pr( RR + deltaF < 25% ) < 60% +# - Interim look for Efficacy: Pr( success at final ) > 80% +# - Interim look for Futility: Pr( failure at final ) < 20% # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) @@ -41,12 +37,10 @@ result$oc # Desired difference to Standard of Care for Efficacy and Futility is 10% and -10% respectively. # Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules. # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P( response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P( response rate + deltaF > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80% or -# P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20% or -# P(success at final) < phiL +# - Final look for Efficacy: Pr( RR + deltaE > 25% ) > 60% +# - Final look for Futility: Pr( RR + deltaF < 25% ) < 60% +# - Interim look for Efficacy: Pr( success at final ) > 80% +# - Interim look for Futility: Pr( failure at final ) < 20% # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. # set.seed(20) @@ -76,8 +70,8 @@ result$oc # True response rate or truep of the treatment group = 40% # Desired difference to Standard of Care for Efficacy and Futility = 50% # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT +# - Final look for Efficacy: Pr( RR + deltaE > 25% ) > 60% or P(RR + deltaE > p0) > tT +# - Final look for Futility: Pr( RR + deltaF < 25% ) < 60% or P(RR + deltaF > p0) < tT # - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20% or # P(success at final) < phiL diff --git a/man/ocPostprobDist.Rd b/man/ocPostprobDist.Rd index d047ebc1..7f54795e 100644 --- a/man/ocPostprobDist.Rd +++ b/man/ocPostprobDist.Rd @@ -76,11 +76,11 @@ respectively. Stop criteria for Efficacy : -\code{Pr(truep > P_S + deltaE) > tU} +\code{Pr(RR > P_S + deltaE) > tU} Stop criteria for Futility : -\code{Pr(truep < P_S + deltaF) > tL} +\code{Pr(RR < P_S + deltaF) > tL} Where \code{truep} is the assumed true rate of response and \code{p1} and \code{p0} respectively are the thresholds for Efficacy and Futility respectively. @@ -121,8 +121,6 @@ or \code{Pr(truep > P_S + (1 - P_S) * deltaF | data)} for Futility looks. # True response rate or truep of the treatment group = 40\% # The following are the Go and Stop rules respectively : # Prior of treatment arm parE= Beta(1,1). -# stop for efficacy (deltaE): Pr(truep > P_S + deltaE) > tU -# stop for futility (deltaF): Pr(truep < P_S + deltaF) > tL # Without random distance allowed for Futility and Efficacy Looks. res1 <- ocPostprobDist( nnE = c(10, 20, 30), diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..e46db038 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -121,8 +121,8 @@ The criteria for Decision 2 for Futility looks are : # Here we illustrate an example for Decision 1 with the following assumptions : # True response rate or truep of the treatment group = 40\% # The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate > p0) < tT +# - Final look for Efficacy: Pr( RR > 25\% ) > 60\% or P( RR > p0) > tT +# - Final look for Futility: Pr( RR < 25\% ) < 60\% or P(RR > p0) < tT # - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20\% or P(success at final) < phiL # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. @@ -196,8 +196,8 @@ result$oc # Here we illustrate an example for Decision 2 with the following assumptions : # True response rate or truep of the treatment group = 60\% # The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate > 25\% ) > 60\% or P(response rate > p0) > tT -# - Final look for Futility: Pr( response rate < 25\% ) < 60\% or P(response rate < p1) > tF +# - Final look for Efficacy: Pr( RR > 25\% ) > 60\% or P(RR > p0) > tT +# - Final look for Futility: Pr( RR < 25\% ) < 60\% or P(RR < p1) > tF # - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) > 80\% or P(failure at final) > phiFu # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. diff --git a/man/ocPredprobDist.Rd b/man/ocPredprobDist.Rd index c13b3efd..85eef12a 100644 --- a/man/ocPredprobDist.Rd +++ b/man/ocPredprobDist.Rd @@ -136,15 +136,11 @@ seen in the evaluation for the final futility look in \code{\link[=ocPredprobDis # Efficacy Looks and Futility looks are identical at sample size of 10, 20 and 30. # True response rate or truep of the treatment group = 40\% # Desired difference to Standard of Care for Efficacy and Futility = 10\% -# Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: -# Pr( response rate + deltaE > 25\% ) > 60\% or P(response rate + deltaE > p0) > tT -# - Final look for Futility: -# Pr( response rate + deltaF < 25\% ) < 60\% or P(response rate + deltaF > p0) < tT -# - Interim look for Efficacy: -# Pr( success at final ) > 80\% or P(success at final) > phiU -# - Interim look for Futility: -# Pr( success at final ) < 20\% or P(success at final) < phiL +# The following are the Final Stop rules respectively : +# - Final look for Efficacy: Pr( RR + deltaE > 25\% ) > 60\% +# - Final look for Futility: Pr( RR + deltaF < 25\% ) < 60\% +# - Interim look for Efficacy: Pr( success at final ) > 80\% +# - Interim look for Futility: Pr( failure at final ) < 20\% # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. set.seed(20) @@ -175,12 +171,10 @@ result$oc # Desired difference to Standard of Care for Efficacy and Futility is 10\% and -10\% respectively. # Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules. # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or P( response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or P( response rate + deltaF > p0) < tT -# - Interim look for Efficacy: Pr( success at final ) > 80\% or -# P(success at final) > phiU -# - Interim look for Futility: Pr( failure at final ) < 20\% or -# P(success at final) < phiL +# - Final look for Efficacy: Pr( RR + deltaE > 25\% ) > 60\% +# - Final look for Futility: Pr( RR + deltaF < 25\% ) < 60\% +# - Interim look for Efficacy: Pr( success at final ) > 80\% +# - Interim look for Futility: Pr( failure at final ) < 20\% # We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated. # set.seed(20) @@ -210,8 +204,8 @@ result$oc # True response rate or truep of the treatment group = 40\% # Desired difference to Standard of Care for Efficacy and Futility = 50\% # Delta calculation is absolute case. The following are the Final Stop rules respectively : -# - Final look for Efficacy: Pr( response rate + deltaE > 25\% ) > 60\% or P(response rate + deltaE > p0) > tT -# - Final look for Futility: Pr( response rate + deltaF < 25\% ) < 60\% or P(response rate + deltaF > p0) < tT +# - Final look for Efficacy: Pr( RR + deltaE > 25\% ) > 60\% or P(RR + deltaE > p0) > tT +# - Final look for Futility: Pr( RR + deltaF < 25\% ) < 60\% or P(RR + deltaF > p0) < tT # - Interim look for Efficacy: Pr( success at final ) > 80\% or P(success at final) > phiU # - Interim look for Futility: Pr( failure at final ) < 20\% or # P(success at final) < phiL From 41108936897b06557643d7dce939ab6439e5f784 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 30 Dec 2024 19:06:03 +0100 Subject: [PATCH 45/53] RR documentation --- R/ocPredprob.R | 8 ++++---- examples/ocPostprob.R | 4 ++-- man/ocPostprob.Rd | 4 ++-- man/ocPredprob.Rd | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/ocPredprob.R b/R/ocPredprob.R index c0f4bd65..f97976c1 100644 --- a/R/ocPredprob.R +++ b/R/ocPredprob.R @@ -211,8 +211,8 @@ h_get_decision_two_predprob <- function(nnr, truep, p0, p1, parE = c(1, 1), nnE, #' - interim STOP = P(successful trial at final) < phiL #' #' The criteria for Decision 1 for Final looks are: -#' - Final GO = P( response rate > p0 | data) > tT -#' - Final STOP = P( response rate > p0 | data ) < tT +#' - Final GO = P( RR > p0 | data) > tT +#' - Final STOP = P( RR > p0 | data ) < tT #' #' ## Decision 2: #' The criteria for Decision 2 for Interim looks are : @@ -220,8 +220,8 @@ h_get_decision_two_predprob <- function(nnr, truep, p0, p1, parE = c(1, 1), nnE, #' - Interim STOP : P (failure at final ) > phiFu #' #' The criteria for Decision 2 for Futility looks are : -#' - Final GO = P( response rate > p0) > tT -#' - Final STOP = P( response rate < p1) > tF +#' - Final GO = P( RR > p0) > tT +#' - Final STOP = P( RR < p1) > tF #' #' @inheritParams h_get_decision_one_predprob #' @inheritParams h_get_decision_two_predprob diff --git a/examples/ocPostprob.R b/examples/ocPostprob.R index b7aded5d..05062f78 100644 --- a/examples/ocPostprob.R +++ b/examples/ocPostprob.R @@ -1,8 +1,8 @@ # For three looks of 10, 20 and 30 we have the following assumptions : # True response rate or truep of the treatment group = 40% # The following are the Stop rules respectively : -# Look for Efficacy: Pr(truep > 30% )> 80% -# Look for Futility: Pr(truep < 20% )> 60% +# Look for Efficacy: Pr(RR > 30% )> 80% +# Look for Futility: Pr(RR < 20% )> 60% # Prior of treatment arm parE= Beta(1,1). res <- ocPostprob( nnE = c(10, 20, 30), truep = 0.40, p0 = 0.20, p1 = 0.30, tL = 0.60, tU = 0.80, parE = c(1, 1), diff --git a/man/ocPostprob.Rd b/man/ocPostprob.Rd index 950cde0a..9f7802ef 100644 --- a/man/ocPostprob.Rd +++ b/man/ocPostprob.Rd @@ -85,8 +85,8 @@ maximum sample size) # For three looks of 10, 20 and 30 we have the following assumptions : # True response rate or truep of the treatment group = 40\% # The following are the Stop rules respectively : -# Look for Efficacy: Pr(truep > 30\% )> 80\% -# Look for Futility: Pr(truep < 20\% )> 60\% +# Look for Efficacy: Pr(RR > 30\% )> 80\% +# Look for Futility: Pr(RR < 20\% )> 60\% # Prior of treatment arm parE= Beta(1,1). res <- ocPostprob( nnE = c(10, 20, 30), truep = 0.40, p0 = 0.20, p1 = 0.30, tL = 0.60, tU = 0.80, parE = c(1, 1), diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index e46db038..05595ace 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -97,8 +97,8 @@ The criteria for Decision 1 for Interim looks are : The criteria for Decision 1 for Final looks are: \itemize{ -\item Final GO = P( response rate > p0 | data) > tT -\item Final STOP = P( response rate > p0 | data ) < tT +\item Final GO = P( RR > p0 | data) > tT +\item Final STOP = P( RR > p0 | data ) < tT } } @@ -112,8 +112,8 @@ The criteria for Decision 2 for Interim looks are : The criteria for Decision 2 for Futility looks are : \itemize{ -\item Final GO = P( response rate > p0) > tT -\item Final STOP = P( response rate < p1) > tF +\item Final GO = P( RR > p0) > tT +\item Final STOP = P( RR < p1) > tF } } } From cdcc320cead4d2a42b0cdea6c67024dfaca304aa Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 31 Dec 2024 19:33:59 +0100 Subject: [PATCH 46/53] clean --- R/boundsPostprob.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 0fcedb17..9cf86fe5 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -48,7 +48,7 @@ boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) xL <- NA xU <- NA for (x in 0:n) { - postp_fut <- 1 - postprob(x = x, n = x, p = p0, parE = parE, weights = weights) # futility look + postp_fut <- 1 - postprob(x = x, n = n, p = p0, parE = parE, weights = weights) # futility look if (postp_fut >= tL) { # Rule is P(RR < p0) > tL postL <- postp_fut xL <- x From c661bdfdaf24bf240707712b06bca1b7e212ac95 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 31 Dec 2024 20:20:08 +0100 Subject: [PATCH 47/53] clean --- tests/testthat/test-boundsPredprob.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index 8de932ad..5d02f362 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -92,11 +92,11 @@ test_that("boundsPredprob with Beta Mixture Priors give correct results", { expect_equal(result$xL, c(2, 6)) expect_equal(result$pL, c(0.2, 0.3)) expect_equal(result$predL, c(0.0409, 0)) - expect_equal(result$postL, c(0.367, 0.7734)) + expect_equal(result$postL, c(0.27410, 0.69650)) expect_equal(result$UciL, c(0.5069, 0.5078)) expect_equal(result$xU, c(6, 7)) expect_equal(result$pU, c(0.6, 0.35)) expect_equal(result$predU, c(0.9859, 1)) - expect_equal(result$postU, c(0.9875, 0.8919)) + expect_equal(result$postU, c(0.97480, 0.840)) expect_equal(result$LciU, c(0.3035, 0.1773)) }) From 50830886ab072f804fe5e0a035c77c2687907bdb Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 31 Dec 2024 20:59:15 +0100 Subject: [PATCH 48/53] clean --- R/boundsPostprob.R | 4 +++- R/boundsPredprob.R | 11 +++++++---- man/boundsPostprob.Rd | 2 ++ man/boundsPredprob.Rd | 6 ++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 9cf86fe5..ed258ff9 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -1,5 +1,7 @@ #' Decision cutpoints for boundary (based on posterior probability) #' +#' @description `r lifecycle::badge("experimental")` +#' #' This function is used to identify the efficacy and futility #' boundaries based on the following rules: #' Efficacy boundary: find minimum x (xU) where Pr(RR > p1 | x, n, a, b) >= tU and @@ -24,7 +26,7 @@ #' @example examples/boundsPostprob.R #' @export boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) { - assert_numeric(looks) + assert_numeric(looks, any.missing = FALSE) assert_number(p0, lower = 0, upper = 1) assert_number(p1, lower = 0, upper = 1) assert_number(tL, lower = 0, upper = 1) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 4a9fdee9..536b8228 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -1,5 +1,7 @@ #' Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule. #' +#' @description `r lifecycle::badge("experimental")` +#' #' This function is used to identify the efficacy boundary and futility #' boundary based on rules in @details. #' @@ -8,7 +10,7 @@ #' @inheritParams boundsPostprob #' @return A matrix for each same size in `looks`. For each sample size, the following is returned: #' - `xL` : the maximum number of responses that meet the futility -#' threshold +#' threshold. #' - `pL` : response rate corresponding to `xL`. #' - `predL` : predictive probability corresponding to `xL` #' - `postL`: posterior probability corresponding to `xL`. @@ -16,7 +18,7 @@ #' exact binomial test. #' - `xU` : the minimal number of responses that meet the efficacy threshold. #' - `pU` : response rate corresponding to `xU`. -#' - `predU` : predictive probability corresponding to `xU` +#' - `predU` : predictive probability corresponding to `xU`. #' - `postU`: posterior probability corresponding to `xU`. #' - `pU_lower_ci` : lower bound of one sided 95% CI for the response rate based on exact #' binomial test. @@ -34,11 +36,11 @@ #' @export #' @keywords graphics boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = c(1, 1), weights) { - assert_numeric(looks) + assert_numeric(looks, any.missing = FALSE) assert_number(p0, lower = 0, upper = 1) assert_number(tT, lower = 0, upper = 1) - assert_number(phiU, lower = 0, upper = 1) assert_number(phiL, lower = 0, upper = 1) + assert_number(phiU, lower = 0, upper = 1) assert_numeric(parE, min.len = 2, any.missing = FALSE) znames <- c( "xL", "pL", "predL", "postL", "UciL", @@ -47,6 +49,7 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = z <- matrix(NA, length(looks), length(znames)) dimnames(z) <- list(looks, znames) k <- 0 + assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE) for (n in looks) { k <- k + 1 # initialize so will return NA if 0 or n in "continue" region diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 1fa8bde4..e97bf85e 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -38,6 +38,8 @@ binomial test. } } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} + This function is used to identify the efficacy and futility boundaries based on the following rules: Efficacy boundary: find minimum x (xU) where Pr(RR > p1 | x, n, a, b) >= tU and diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index d3db96d7..007fcea4 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -37,7 +37,7 @@ corresponding to the beta parameters of the K components.} A matrix for each same size in \code{looks}. For each sample size, the following is returned: \itemize{ \item \code{xL} : the maximum number of responses that meet the futility -threshold +threshold. \item \code{pL} : response rate corresponding to \code{xL}. \item \code{predL} : predictive probability corresponding to \code{xL} \item \code{postL}: posterior probability corresponding to \code{xL}. @@ -45,13 +45,15 @@ threshold exact binomial test. \item \code{xU} : the minimal number of responses that meet the efficacy threshold. \item \code{pU} : response rate corresponding to \code{xU}. -\item \code{predU} : predictive probability corresponding to \code{xU} +\item \code{predU} : predictive probability corresponding to \code{xU}. \item \code{postU}: posterior probability corresponding to \code{xU}. \item \code{pU_lower_ci} : lower bound of one sided 95\% CI for the response rate based on exact binomial test. } } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} + This function is used to identify the efficacy boundary and futility boundary based on rules in @details. } From 69f7ae95a0157b218043ae49d17e5053d054d493 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 9 Jan 2025 10:49:07 +0100 Subject: [PATCH 49/53] Update examples/boundsPredprob.R Co-authored-by: Daniel Sabanes Bove --- examples/boundsPredprob.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/boundsPredprob.R b/examples/boundsPredprob.R index ce66c059..0ec7021b 100644 --- a/examples/boundsPredprob.R +++ b/examples/boundsPredprob.R @@ -4,7 +4,7 @@ # Interim efficacy decision if more than 90% predictive probability reach this or # Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 10% predictive probability or -# Futility look Pr(Pr(RR) > p0 | x, Y) >= tT | x) =< phiL +# Futility look Pr(Pr(RR > p0 | x, Y) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( looks = c(10, 20, 30, 40), From d7d04ef22410082f3d0a9a0d1c3545da591a0945 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:51:13 +0000 Subject: [PATCH 50/53] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/boundsPredprob.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 007fcea4..04d6756b 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -72,7 +72,7 @@ Pr(Pr(RR > p0 | data) >= tT | x) =< phiL # Interim efficacy decision if more than 90\% predictive probability reach this or # Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU, # Interim futility decision if less than 10\% predictive probability or -# Futility look Pr(Pr(RR) > p0 | x, Y) >= tT | x) =< phiL +# Futility look Pr(Pr(RR > p0 | x, Y) >= tT | x) =< phiL # Uniform prior (i.e. beta(1, 1)) on the ORR: boundsPredprob( looks = c(10, 20, 30, 40), From 87760357d62d454a61cd904eeb9c4d174303f83e Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 13 Jan 2025 15:13:58 +0100 Subject: [PATCH 51/53] debugging on parE issue with giving correct results and other documentation consistencies --- R/boundsPostprob.R | 2 +- R/boundsPredprob.R | 7 +- R/postprob.R | 2 +- R/predprob.R | 2 +- man/boundsPostprob.Rd | 2 +- man/boundsPredprob.Rd | 2 +- man/postprob.Rd | 2 +- man/predprob.Rd | 2 +- tests/testthat/test-boundsPredprob.R | 133 ++++++++++++++++++--------- 9 files changed, 100 insertions(+), 54 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index ed258ff9..874a8c99 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -32,11 +32,11 @@ boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) assert_number(tL, lower = 0, upper = 1) assert_number(tU, lower = 0, upper = 1) assert_numeric(parE, min.len = 2, any.missing = FALSE) - z <- matrix(NA, nrow = length(looks), ncol = 8) znames <- c( "xL", "pL", "postL", "pL_upper_ci", "xU", "pU", "postU", "pU_lower_ci" ) + z <- matrix(NA, nrow = length(looks), ncol = length(znames)) dimnames(z) <- list(looks, znames) k <- 0 parE <- t(parE) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 536b8228..38728a5f 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -43,12 +43,15 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = assert_number(phiU, lower = 0, upper = 1) assert_numeric(parE, min.len = 2, any.missing = FALSE) znames <- c( - "xL", "pL", "predL", "postL", "UciL", - "xU", "pU", "predU", "postU", "LciU" + "xL", "pL", "predL", "postL", "pL_upper_ci", + "xU", "pU", "predU", "postU", "pU_lower_ci" ) z <- matrix(NA, length(looks), length(znames)) dimnames(z) <- list(looks, znames) k <- 0 + if (missing(weights)) { + weights <- rep(1, nrow(t(parE))) + } assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE) for (n in looks) { k <- k + 1 diff --git a/R/postprob.R b/R/postprob.R index 383bf790..87fde190 100644 --- a/R/postprob.R +++ b/R/postprob.R @@ -55,7 +55,7 @@ postprobBeta <- function(x, n, p, a = 1, b = 1) { #' threshold that `P_E` is measured. #' @typed parE : matrix #' the beta parameters matrix, with `K` rows and 2 columns, -#' corresponding to the beta parameters of the `K` components. +#' corresponding to the beta parameters of the `K` priors. #' @typed weights : vector #' The mixture weights of the beta mixture prior. #' @typed betamixPost : matrix diff --git a/R/predprob.R b/R/predprob.R index f550e018..749288ba 100644 --- a/R/predprob.R +++ b/R/predprob.R @@ -31,7 +31,7 @@ #' threshold on the probability to be above p. #' @typed parE : numeric #' the beta parameters matrix, with K rows and 2 columns, -#' corresponding to the beta parameters of the K components. +#' corresponding to the beta parameters of the K priors. #' @typed weights : numeric #' the mixture weights of the beta mixture prior. #' @return A `list` is returned with names `result` for predictive probability and diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index e97bf85e..d0122c82 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -18,7 +18,7 @@ boundsPostprob(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} \item{parE}{(\code{matrix}):\cr the beta parameters matrix, with \code{K} rows and 2 columns, -corresponding to the beta parameters of the \code{K} components.} +corresponding to the beta parameters of the \code{K} priors.} \item{weights}{(\code{vector}):\cr The mixture weights of the beta mixture prior.} } diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 04d6756b..6b93cb04 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -29,7 +29,7 @@ boundsPredprob( \item{phiU}{(\code{number}):\cr upper threshold on the predictive probability.} \item{parE}{(\code{numeric}):\cr the beta parameters matrix, with K rows and 2 columns, -corresponding to the beta parameters of the K components.} +corresponding to the beta parameters of the K priors.} \item{weights}{(\code{numeric}):\cr the mixture weights of the beta mixture prior.} } diff --git a/man/postprob.Rd b/man/postprob.Rd index cf78cc9b..10edc426 100644 --- a/man/postprob.Rd +++ b/man/postprob.Rd @@ -14,7 +14,7 @@ postprob(x, n, p, parE = c(1, 1), weights, betamixPost, log.p = FALSE) \item{p}{(\code{number}):\cr threshold that \code{P_E} is measured.} \item{parE}{(\code{matrix}):\cr the beta parameters matrix, with \code{K} rows and 2 columns, -corresponding to the beta parameters of the \code{K} components.} +corresponding to the beta parameters of the \code{K} priors.} \item{weights}{(\code{vector}):\cr The mixture weights of the beta mixture prior.} diff --git a/man/predprob.Rd b/man/predprob.Rd index 27440d07..b9cd44eb 100644 --- a/man/predprob.Rd +++ b/man/predprob.Rd @@ -18,7 +18,7 @@ predprob(x, n, Nmax, p, thetaT, parE = c(1, 1), weights) \item{thetaT}{(\code{number}):\cr threshold on the probability to be above p.} \item{parE}{(\code{numeric}):\cr the beta parameters matrix, with K rows and 2 columns, -corresponding to the beta parameters of the K components.} +corresponding to the beta parameters of the K priors.} \item{weights}{(\code{numeric}):\cr the mixture weights of the beta mixture prior.} } diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index 5d02f362..b4395acb 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -35,11 +35,11 @@ test_that("boundsPredprob gives correct result and when default weight is not as expect_equal(result$xL, c(0, 2, 5, 9)) expect_equal(result$pL, c(0, 0.1, 0.1667, 0.225)) expect_equal(result$postL, c(0.0859, 0.1787, 0.3931, 0.704)) - expect_equal(result$UciL, c(0.2589, 0.2826, 0.319, 0.3598)) + expect_equal(result$pL_upper_ci, c(0.2589, 0.2826, 0.319, 0.3598)) expect_equal(result$xU, c(4, 7, 9, 10)) expect_equal(result$pU, c(0.4, 0.35, 0.3, 0.25)) expect_equal(result$postU, c(0.9496, 0.9569, 0.9254, 0.8177)) - expect_equal(result$LciU, c(0.15, 0.1773, 0.1663, 0.1424)) + expect_equal(result$pU_lower_ci, c(0.15, 0.1773, 0.1663, 0.1424)) }) test_that("boundsPredprob with Beta Mixture Priors give correct results", { @@ -52,51 +52,94 @@ test_that("boundsPredprob with Beta Mixture Priors give correct results", { parE = cbind(c(1, 1), c(3, 10)), weights = c(0.2, 0.8) ) - result_predprob_lower <- predprob( - x = 2, - n = 10, - p = 0.20, - Nmax = 20, - thetaT = 0.80, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8) - ) - result_predprob_upper <- predprob( - x = 6, - n = 10, - p = 0.20, - Nmax = 20, - thetaT = 0.80, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8) + expected_lower_bound_results <- data.frame( + list(interim_predL = # predL of interim data + predprob( + x = result$xL[1], + n = 10, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + interim_post = # postL of interim data + postprob( + x = 2, + n = 10, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE), + final_predL = # predU of interim data + predprob( + x = result$xL[2], + n = 20, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + final_post = # postU of final data + postprob( + x = 6, + n = 20, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE) + ) ) - expected <- data.frame( - list( - looks = c(10, 20), - xL = c(2, 6), - pL = c(0.2, 0.3), - predL = c(0.0409, 0), - postL = c(0.367, 0.7734), - UciL = c(0.5069, 0.5078), - xU = c(6, 7), - pU = c(0.6, 0.35), - predU = c(0.9859, 1), - postU = c(0.9875, 0.8919), - LciU = c(0.3035, 0.1773) + expected_upper_bound_results <- data.frame( + list(interim_predU = # predL of interim data + predprob( + x = result$xU[1], + n = 10, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + interim_post = # postL of interim data + postprob( + x = result$xU[1], + n = 10, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE), + final_predU = # predU of interim data + predprob( + x = result$xU[2], + n = 20, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + final_post = # postU of final data + postprob( + x = result$xU[2], + n = 20, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE) ) ) + # lower bound predictive and posterior probabilities expect_equal(result$xL[1], 2) - expect_equal(result$predL[1], result_predprob_lower$result, tolerance = 1e-3) - expect_equal(result$xL[2], 6) - expect_equal(result$predU[1], result_predprob_upper$result, tolerance = 1e-4) - expect_equal(result$xL, c(2, 6)) - expect_equal(result$pL, c(0.2, 0.3)) - expect_equal(result$predL, c(0.0409, 0)) - expect_equal(result$postL, c(0.27410, 0.69650)) - expect_equal(result$UciL, c(0.5069, 0.5078)) - expect_equal(result$xU, c(6, 7)) - expect_equal(result$pU, c(0.6, 0.35)) - expect_equal(result$predU, c(0.9859, 1)) - expect_equal(result$postU, c(0.97480, 0.840)) - expect_equal(result$LciU, c(0.3035, 0.1773)) + expect_equal(result$predL[1], expected_lower_bound_results$interim_predL, tolerance = 1e-3) + expect_equal(result$postL[1], expected_lower_bound_results$interim_post, tolerance = 1e-4) + expect_equal(result$predL[2], expected_lower_bound_results$final_predL, tolerance = 1e-3) + expect_equal(result$postL[2], expected_lower_bound_results$final_post, tolerance = 1e-4) + # lower bound predictive and posterior probabilities + expect_equal(result$xU[1], 6) + expect_equal(result$predU[1], expected_upper_bound_results$interim_predU, tolerance = 1e-3) + expect_equal(result$postU[1], expected_upper_bound_results$interim_post, tolerance = 1e-4) + expect_equal(result$predU[2], expected_upper_bound_results$final_predU, tolerance = 1e-3) + expect_equal(result$postU[2], expected_upper_bound_results$final_post, tolerance = 1e-4) }) From 9b912bd174dd4cd5397f507dec70cc2eca6ffbd6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:15:58 +0000 Subject: [PATCH 52/53] [skip style] [skip vbump] Restyle files --- tests/testthat/test-boundsPredprob.R | 150 ++++++++++++++------------- 1 file changed, 78 insertions(+), 72 deletions(-) diff --git a/tests/testthat/test-boundsPredprob.R b/tests/testthat/test-boundsPredprob.R index b4395acb..af3c9f90 100644 --- a/tests/testthat/test-boundsPredprob.R +++ b/tests/testthat/test-boundsPredprob.R @@ -53,81 +53,87 @@ test_that("boundsPredprob with Beta Mixture Priors give correct results", { weights = c(0.2, 0.8) ) expected_lower_bound_results <- data.frame( - list(interim_predL = # predL of interim data - predprob( - x = result$xL[1], - n = 10, - p = 0.20, - Nmax = 20, - thetaT = 0.80, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8) - )$result, - interim_post = # postL of interim data - postprob( - x = 2, - n = 10, - p = 0.2, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8), - log.p = FALSE), - final_predL = # predU of interim data - predprob( - x = result$xL[2], - n = 20, - p = 0.20, - Nmax = 20, - thetaT = 0.80, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8) - )$result, - final_post = # postU of final data - postprob( - x = 6, - n = 20, - p = 0.2, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8), - log.p = FALSE) + list( + interim_predL = # predL of interim data + predprob( + x = result$xL[1], + n = 10, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + interim_post = # postL of interim data + postprob( + x = 2, + n = 10, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE + ), + final_predL = # predU of interim data + predprob( + x = result$xL[2], + n = 20, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + final_post = # postU of final data + postprob( + x = 6, + n = 20, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE + ) ) ) expected_upper_bound_results <- data.frame( - list(interim_predU = # predL of interim data - predprob( - x = result$xU[1], - n = 10, - p = 0.20, - Nmax = 20, - thetaT = 0.80, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8) - )$result, - interim_post = # postL of interim data - postprob( - x = result$xU[1], - n = 10, - p = 0.2, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8), - log.p = FALSE), - final_predU = # predU of interim data - predprob( - x = result$xU[2], - n = 20, - p = 0.20, - Nmax = 20, - thetaT = 0.80, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8) - )$result, - final_post = # postU of final data - postprob( - x = result$xU[2], - n = 20, - p = 0.2, - parE = cbind(c(1, 1), c(3, 10)), - weights = c(0.2, 0.8), - log.p = FALSE) + list( + interim_predU = # predL of interim data + predprob( + x = result$xU[1], + n = 10, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + interim_post = # postL of interim data + postprob( + x = result$xU[1], + n = 10, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE + ), + final_predU = # predU of interim data + predprob( + x = result$xU[2], + n = 20, + p = 0.20, + Nmax = 20, + thetaT = 0.80, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8) + )$result, + final_post = # postU of final data + postprob( + x = result$xU[2], + n = 20, + p = 0.2, + parE = cbind(c(1, 1), c(3, 10)), + weights = c(0.2, 0.8), + log.p = FALSE + ) ) ) # lower bound predictive and posterior probabilities From 258ae08043cd7684e6d97bb5c5d02cd024aa9820 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 14 Jan 2025 10:25:13 +0100 Subject: [PATCH 53/53] clean --- R/boundsPredprob.R | 2 +- R/postprob.R | 2 +- R/predprob.R | 2 +- man/boundsPostprob.Rd | 2 +- man/boundsPredprob.Rd | 2 +- man/postprob.Rd | 2 +- man/predprob.Rd | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/boundsPredprob.R b/R/boundsPredprob.R index 38728a5f..c118671b 100644 --- a/R/boundsPredprob.R +++ b/R/boundsPredprob.R @@ -52,7 +52,7 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = if (missing(weights)) { weights <- rep(1, nrow(t(parE))) } - assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE) + assert_numeric(weights, min.len = 0, len = nrow(parE), finite = TRUE) for (n in looks) { k <- k + 1 # initialize so will return NA if 0 or n in "continue" region diff --git a/R/postprob.R b/R/postprob.R index 87fde190..383bf790 100644 --- a/R/postprob.R +++ b/R/postprob.R @@ -55,7 +55,7 @@ postprobBeta <- function(x, n, p, a = 1, b = 1) { #' threshold that `P_E` is measured. #' @typed parE : matrix #' the beta parameters matrix, with `K` rows and 2 columns, -#' corresponding to the beta parameters of the `K` priors. +#' corresponding to the beta parameters of the `K` components. #' @typed weights : vector #' The mixture weights of the beta mixture prior. #' @typed betamixPost : matrix diff --git a/R/predprob.R b/R/predprob.R index 749288ba..f550e018 100644 --- a/R/predprob.R +++ b/R/predprob.R @@ -31,7 +31,7 @@ #' threshold on the probability to be above p. #' @typed parE : numeric #' the beta parameters matrix, with K rows and 2 columns, -#' corresponding to the beta parameters of the K priors. +#' corresponding to the beta parameters of the K components. #' @typed weights : numeric #' the mixture weights of the beta mixture prior. #' @return A `list` is returned with names `result` for predictive probability and diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index d0122c82..e97bf85e 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -18,7 +18,7 @@ boundsPostprob(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} \item{parE}{(\code{matrix}):\cr the beta parameters matrix, with \code{K} rows and 2 columns, -corresponding to the beta parameters of the \code{K} priors.} +corresponding to the beta parameters of the \code{K} components.} \item{weights}{(\code{vector}):\cr The mixture weights of the beta mixture prior.} } diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 6b93cb04..04d6756b 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -29,7 +29,7 @@ boundsPredprob( \item{phiU}{(\code{number}):\cr upper threshold on the predictive probability.} \item{parE}{(\code{numeric}):\cr the beta parameters matrix, with K rows and 2 columns, -corresponding to the beta parameters of the K priors.} +corresponding to the beta parameters of the K components.} \item{weights}{(\code{numeric}):\cr the mixture weights of the beta mixture prior.} } diff --git a/man/postprob.Rd b/man/postprob.Rd index 10edc426..cf78cc9b 100644 --- a/man/postprob.Rd +++ b/man/postprob.Rd @@ -14,7 +14,7 @@ postprob(x, n, p, parE = c(1, 1), weights, betamixPost, log.p = FALSE) \item{p}{(\code{number}):\cr threshold that \code{P_E} is measured.} \item{parE}{(\code{matrix}):\cr the beta parameters matrix, with \code{K} rows and 2 columns, -corresponding to the beta parameters of the \code{K} priors.} +corresponding to the beta parameters of the \code{K} components.} \item{weights}{(\code{vector}):\cr The mixture weights of the beta mixture prior.} diff --git a/man/predprob.Rd b/man/predprob.Rd index b9cd44eb..27440d07 100644 --- a/man/predprob.Rd +++ b/man/predprob.Rd @@ -18,7 +18,7 @@ predprob(x, n, Nmax, p, thetaT, parE = c(1, 1), weights) \item{thetaT}{(\code{number}):\cr threshold on the probability to be above p.} \item{parE}{(\code{numeric}):\cr the beta parameters matrix, with K rows and 2 columns, -corresponding to the beta parameters of the K priors.} +corresponding to the beta parameters of the K components.} \item{weights}{(\code{numeric}):\cr the mixture weights of the beta mixture prior.} }