From dff2ff6ce97831a3ce4873239a70cae17037a4dd Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 21 May 2024 17:38:31 +0200 Subject: [PATCH 01/35] delete helpers --- R/helpers.R | 77 ----------------------------------- tests/testthat/test-helpers.R | 13 ------ 2 files changed, 90 deletions(-) delete mode 100644 R/helpers.R delete mode 100644 tests/testthat/test-helpers.R diff --git a/R/helpers.R b/R/helpers.R deleted file mode 100644 index 5b7b9c41..00000000 --- a/R/helpers.R +++ /dev/null @@ -1,77 +0,0 @@ -#' -#' Checking for scalar -#' -#' @param x the input -#' @return Returns \code{TRUE} if \code{x} is a length one vector -#' (i.e., a scalar) -#' -#' @keywords internal -is.scalar <- function(x) { - return(identical(length(x), 1L)) -} - - -#' Predicate checking for a boolean option -#' -#' @param x the object being checked -#' @return Returns \code{TRUE} if \code{x} is a length one logical vector (i.e., a -#' scalar) -#' -#' @keywords internal -is.bool <- function(x) { - return(is.scalar(x) && is.logical(x)) -} - -#' Predicate checking for a probability -#' -#' @param x the object being checked -#' @param bounds whether to include the bounds 0 and 1 (default) -#' @return Returns \code{TRUE} if \code{x} is a probability -#' -#' @keywords internal -is.probability <- function(x, - bounds = TRUE) { - return(is.scalar(x) && - if (bounds) { - 0 <= x && 1 >= x - } else { - 0 < x && 1 > x - }) -} - -#' Predicate checking for a probability range -#' -#' @param x the object being checked -#' @param bounds whether to include the bounds 0 and 1 (default) -#' @return Returns \code{TRUE} if \code{x} is a probability range -#' -#' @keywords internal -is.probRange <- function(x, - bounds = TRUE) { - return(identical(length(x), 2L) && - x[1] < x[2] && - if (bounds) { - 0 <= x[1] && 1 >= x[2] - } else { - 0 < x[1] && 1 > x[2] - }) -} - - -#' The Logit Function -#' -#' @description `r lifecycle::badge("experimental")` -#' -#' This just calculates the logit. -#' -#' @typed x: numeric -#' probabilities to transform. -#' @return The logit of `x`. -#' -#' @example examples/logit.R -#' @export -logit <- function(x) { - assert_numeric(x, lower = 0, upper = 1, finite = TRUE) - - stats::qlogis(x) -} diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R deleted file mode 100644 index 332acd98..00000000 --- a/tests/testthat/test-helpers.R +++ /dev/null @@ -1,13 +0,0 @@ -test_that("logit works as expected", { - probs <- seq(0, 1, length = 100) - result <- logit(probs) - expect_numeric(result, len = length(probs), sorted = TRUE, unique = TRUE) - expect_identical(result[1], -Inf) - expect_identical(result[100], Inf) -}) - -test_that("logit gives expected value for example value 0.2", { - result <- logit(0.2) - expected <- -1.386294 - expect_equal(result, expected, tolerance = 1e-4) -}) From 37561fcab0a269e17ae1253a1b676bc086e871cb 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, 21 May 2024 15:53:55 +0000 Subject: [PATCH 02/35] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- DESCRIPTION | 1 - man/is.bool.Rd | 19 ------------------- man/is.probRange.Rd | 20 -------------------- man/is.probability.Rd | 20 -------------------- man/is.scalar.Rd | 19 ------------------- man/logit.Rd | 23 ----------------------- 6 files changed, 102 deletions(-) delete mode 100644 man/is.bool.Rd delete mode 100644 man/is.probRange.Rd delete mode 100644 man/is.probability.Rd delete mode 100644 man/is.scalar.Rd delete mode 100644 man/logit.Rd diff --git a/DESCRIPTION b/DESCRIPTION index a7e3765b..bfdb50be 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -52,7 +52,6 @@ Collate: 'boundsPredprob.R' 'data.R' 'dbetabinom.R' - 'helpers.R' 'oc2.R' 'oc3.R' 'ocPostprob.R' diff --git a/man/is.bool.Rd b/man/is.bool.Rd deleted file mode 100644 index 23ff5261..00000000 --- a/man/is.bool.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.bool} -\alias{is.bool} -\title{Predicate checking for a boolean option} -\usage{ -is.bool(x) -} -\arguments{ -\item{x}{the object being checked} -} -\value{ -Returns \code{TRUE} if \code{x} is a length one logical vector (i.e., a -scalar) -} -\description{ -Predicate checking for a boolean option -} -\keyword{internal} diff --git a/man/is.probRange.Rd b/man/is.probRange.Rd deleted file mode 100644 index e27fd5f6..00000000 --- a/man/is.probRange.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.probRange} -\alias{is.probRange} -\title{Predicate checking for a probability range} -\usage{ -is.probRange(x, bounds = TRUE) -} -\arguments{ -\item{x}{the object being checked} - -\item{bounds}{whether to include the bounds 0 and 1 (default)} -} -\value{ -Returns \code{TRUE} if \code{x} is a probability range -} -\description{ -Predicate checking for a probability range -} -\keyword{internal} diff --git a/man/is.probability.Rd b/man/is.probability.Rd deleted file mode 100644 index c8335609..00000000 --- a/man/is.probability.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.probability} -\alias{is.probability} -\title{Predicate checking for a probability} -\usage{ -is.probability(x, bounds = TRUE) -} -\arguments{ -\item{x}{the object being checked} - -\item{bounds}{whether to include the bounds 0 and 1 (default)} -} -\value{ -Returns \code{TRUE} if \code{x} is a probability -} -\description{ -Predicate checking for a probability -} -\keyword{internal} diff --git a/man/is.scalar.Rd b/man/is.scalar.Rd deleted file mode 100644 index e8735c12..00000000 --- a/man/is.scalar.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.scalar} -\alias{is.scalar} -\title{Checking for scalar} -\usage{ -is.scalar(x) -} -\arguments{ -\item{x}{the input} -} -\value{ -Returns \code{TRUE} if \code{x} is a length one vector -(i.e., a scalar) -} -\description{ -Checking for scalar -} -\keyword{internal} diff --git a/man/logit.Rd b/man/logit.Rd deleted file mode 100644 index 3eb2ad42..00000000 --- a/man/logit.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{logit} -\alias{logit} -\title{The Logit Function} -\usage{ -logit(x) -} -\arguments{ -\item{x}{(\code{numeric}):\cr probabilities to transform.} -} -\value{ -The logit of \code{x}. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} - -This just calculates the logit. -} -\examples{ -x <- seq(0.1, 0.9, 0.1) -logit(x) -} From ab9ba06d6dabefa1d0a2f9d9e7c4dd3cb1a67299 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 24 May 2024 13:48:38 +0200 Subject: [PATCH 03/35] clean --- R/boundsPostprob.R | 48 +++++++---- man/boundsPostprob.Rd | 30 ++++--- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPostProb.R | 28 +++++++ 4 files changed, 200 insertions(+), 27 deletions(-) create mode 100644 tests/testthat/test-boundsPostProb.R diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 09822eda..1493ec80 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -5,15 +5,11 @@ #' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and #' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL #' -#' @param nvec a vector of number of patients -#' @param p0 the efficacy threshold parameter in the postprob function -#' @param p1 the futility threshold parameter in the postprob function -#' (default = p0) -#' @param tL futility boundary probability threshold -#' @param tU efficacy boundary probability threshold -#' @param a the alpha parameter of the beta prior of treatment group -#' @param b the beta parameter of the beta prior of treatment group -#' @return A matrix where for each sample size in \code{nvec}, this function +#' @inheritParams postprob +#' @inheritParams ocPostprob +#' @typed nvec : numeric +#' a vector of number of patients in each look. +#' @return A matrix where for each sample size in `nvec`, this function #' returns the maximum number of responses that meet the futility #' threshold (xL), its corresponding response rate (pL), posterior probability #' (postL), upper bound of one sided 95% CI for the response rate based on an @@ -23,7 +19,19 @@ #' the lower bound of one sided 95% CI for the response rate based on exact #' binomial test (LciU). #' -#' @importFrom stats binom.test +#' 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` : posterior probability corresponding to `xL`. +#' - `postL`: posterior probability. +#' - `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` : the corresponding response rate. +#' - `postU` : posterior probability. +#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact +#' binomial test. +#' #' #' @example examples/boundsPostprob.R #' @export @@ -43,30 +51,36 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { k <- 0 for (n in nvec) { k <- k + 1 - # initialize so will return NA if 0 or n in "continue" region xL <- NA xU <- NA for (x in 0:n) { postp <- postprob(x, n, p1, parE = c(a, b)) if (postp <= tL) { xL <- x + postL <- postp } if (p0 != p1) { postp <- postprob(x, n, p0, parE = c(a, b)) } if (postp >= tU) { xU <- x - # done: leave innermost for loop - break + postU <- postp + break # needed ? } } - # calculate posterior probabilities at boundaries - postL <- postprob(xL, n, p1, parE = c(a, b)) - postU <- postprob(xU, n, p0, parE = c(a, b)) # 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, postL, UciL, xU, xU / n, postU, LciU) + z[k, ] <- c( + xL, + xL / n, + postL, + UciL, + xU, + xU / n, + postU, + LciU + ) } return(round(data.frame(nvec, z), 4)) } diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 1cb2ae60..a26478ff 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -7,20 +7,15 @@ boundsPostprob(nvec, p0, p1 = p0, tL, tU, a, b) } \arguments{ -\item{nvec}{a vector of number of patients} +\item{nvec}{(\code{numeric}):\cr a vector of number of patients in each look.} -\item{p0}{the efficacy threshold parameter in the postprob function} +\item{p0}{(\code{number}):\cr lower Futility threshold of response rate.} -\item{p1}{the futility threshold parameter in the postprob function -(default = p0)} +\item{p1}{(\code{number}):\cr upper Efficacy threshold of response rate.} -\item{tL}{futility boundary probability threshold} +\item{tL}{(\code{number}):\cr posterior probability threshold for being below \code{p0}.} -\item{tU}{efficacy boundary probability threshold} - -\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{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} } \value{ A matrix where for each sample size in \code{nvec}, this function @@ -32,6 +27,21 @@ the minimal number of responses that meet the efficacy threshold (xU), the corresponding response rate (pU), posterior probability (postU) and the lower bound of one sided 95\% CI for the response rate based on exact binomial test (LciU). + +A matrix for each same size in \code{nvec}. For each sample size, the following is returned: +\itemize{ +\item \code{xL} : the maximum number of responses that meet the futility. +threshold +\item \code{pL} : posterior probability corresponding to \code{xL}. +\item \code{postL}: posterior probability. +\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} : the corresponding response rate. +\item \code{postU} : posterior probability. +\item \code{LciU} : lower bound of one sided 95\% CI for the response rate based on exact +binomial test. +} } \description{ This function is used to identify the efficacy and futility 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-boundsPostProb.R b/tests/testthat/test-boundsPostProb.R new file mode 100644 index 00000000..0ae6eadf --- /dev/null +++ b/tests/testthat/test-boundsPostProb.R @@ -0,0 +1,28 @@ +# boundsPostProb ---- +test_that("h_decision_one_RctPredProbDist gives correct result and list when relativeDelta = TRUE", { + result <- boundsPostprob( + nvec = c(10, 20, 30, 40), + p0 = 0.2, + p1 = 0.2, + tL = 0.10, + tU = 0.90, + a = 1, + b = 1 + ) + expected <- data.frame( + list( + nvec = c(10, 20, 30, 40), + xL = c(0, 1, 2, 4), + pL = c(0, 0.05, 0.0667, 0.1), + postL = c(0.0859, 0.0576, 0.0374, 0.0664), + UciL = c(0.2589, 0.2161, 0.1953, 0.2144), + xU = c(4, 7, 9, 12), + pU = c(0.4, 0.35, 0.3, 0.3), + postU = c(0.9496, 0.9569, 0.9254, 0.9479), + LciU = c(0.15, 0.1773, 0.1663, 0.1831) + ) + ) + expect_equal(result$xL, c(0, 1, 2, 4)) + expect_equal(result$pL, c(0.0000, 0.0500, 0.0667, 0.1000)) + expect_equal(result$UciL, c(0.2589, 0.2161, 0.1953, 0.2144)) +}) From ab510302661d18d4368c4f46c358b7565a643525 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, 24 May 2024 11:51:21 +0000 Subject: [PATCH 04/35] [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 008502dd2c31565eb6ea5e1942897da76afe4102 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 24 May 2024 14:00:43 +0200 Subject: [PATCH 05/35] clean --- R/boundsPostprob.R | 13 +++++++------ man/boundsPostprob.Rd | 13 ++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 1493ec80..f1f32fc8 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -5,6 +5,9 @@ #' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and #' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL #' +#' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and +#' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +#' #' @inheritParams postprob #' @inheritParams ocPostprob #' @typed nvec : numeric @@ -22,20 +25,18 @@ #' 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` : posterior probability corresponding to `xL`. -#' - `postL`: posterior probability. +#' - `pL` : response rate 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` : the corresponding response rate. -#' - `postU` : posterior probability. +#' - `pU` : response rate 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. #' -#' #' @example examples/boundsPostprob.R #' @export -#' @keywords graphics boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { z <- matrix(NA, length(nvec), 6) dimnames(z) <- list(nvec, c( diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index a26478ff..860636e2 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -32,13 +32,13 @@ A matrix for each same size in \code{nvec}. For each sample size, the following \itemize{ \item \code{xL} : the maximum number of responses that meet the futility. threshold -\item \code{pL} : posterior probability corresponding to \code{xL}. -\item \code{postL}: posterior probability. +\item \code{pL} : response rate 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} : the corresponding response rate. -\item \code{postU} : posterior probability. +\item \code{pU} : response rate 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. } @@ -49,6 +49,10 @@ boundaries based on posterior probabilities, i.e.: Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL } +\details{ +Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and +Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +} \examples{ ## 40 pts trial with interim looks after each 10 pts., ## efficacy decision if more than 90\% probability to be above 20\% ORR, @@ -61,4 +65,3 @@ boundsPostprob( ## From this we see e.g. that at the third IA at 30 pts, we would stop for futility ## if 5 or less patients responded, and for efficacy if 9 or more pts responded. } -\keyword{graphics} From 34a2313c0cb2011300a200919c1f8e2e929229e1 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 24 May 2024 14:51:35 +0200 Subject: [PATCH 06/35] empty From 0cd95a75ad572ad32d77147a31485cac1156703e Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 26 May 2024 18:08:04 +0200 Subject: [PATCH 07/35] examples and test there --- R/boundsPostprob.R | 37 +++----- examples/boundsPostprob.R | 14 ++-- man/boundsPostprob.Rd | 34 +++----- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPostProb.R | 31 ++++--- 5 files changed, 167 insertions(+), 70 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index f1f32fc8..f7b5415d 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -1,28 +1,16 @@ #' Decision cutpoints for boundary (based on posterior probability) #' #' This function is used to identify the efficacy and futility -#' boundaries based on posterior probabilities, i.e.: -#' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and -#' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +#' boundaries based on the following rules: #' -#' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and -#' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +#' Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and +#' Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL #' #' @inheritParams postprob #' @inheritParams ocPostprob #' @typed nvec : numeric -#' a vector of number of patients in each look. -#' @return A matrix where for each sample size in `nvec`, this function -#' returns the maximum number of responses that meet the futility -#' threshold (xL), its corresponding response rate (pL), posterior probability -#' (postL), 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), posterior probability (postU) and -#' the lower bound of one sided 95% CI for the response rate based on exact -#' binomial test (LciU). -#' -#' A matrix for each same size in `nvec`. For each sample size, the following is returned: +#' A vector of number of patients in each look. +#' @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`. @@ -52,21 +40,20 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { k <- 0 for (n in nvec) { k <- k + 1 + # initialize so will return NA if 0 or n in "continue" region xL <- NA xU <- NA for (x in 0:n) { - postp <- postprob(x, n, p1, parE = c(a, b)) - if (postp <= tL) { - xL <- x + postp <- 1 - postprob(x, n, p0, parE = c(a, b)) # futility look + if (postp >= tL) { postL <- postp + xL <- x } - if (p0 != p1) { - postp <- postprob(x, n, p0, parE = c(a, b)) - } + postp <- postprob(x, n, p0, parE = c(a, b)) # efficacy look if (postp >= tU) { - xU <- x postU <- postp - break # needed ? + xU <- x + break } } # calculate lower CI at boundaries diff --git a/examples/boundsPostprob.R b/examples/boundsPostprob.R index 97491a9f..f4377968 100644 --- a/examples/boundsPostprob.R +++ b/examples/boundsPostprob.R @@ -1,10 +1,8 @@ -## 40 pts trial with interim looks after each 10 pts., -## efficacy decision if more than 90% probability to be above 20% ORR, -## futility decision if less than 10% probability to be above 20% ORR, -## with uniform prior (i.e. beta(1, 1)) on the ORR: +# 40 pts trial with interim looks after each 10 pts., +# Efficacy decision if more than 60% probability to be above 20% ORR, +# Futility decision if less than 60% probability to be below 20% ORR, +# with uniform prior (i.e. beta(1, 1)) on the ORR: boundsPostprob( - nvec = c(10, 20, 30, 40), p0 = 0.20, - tL = 0.10, tU = 0.90, a = 1, b = 1 + nvec = c(10, 20, 30, 40), p0 = 0.20, p1 = 0.2, + tL = 0.60, tU = 0.60, a = 1, b = 1 ) -## From this we see e.g. that at the third IA at 30 pts, we would stop for futility -## if 5 or less patients responded, and for efficacy if 9 or more pts responded. diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 860636e2..b405a75c 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -7,7 +7,7 @@ boundsPostprob(nvec, p0, p1 = p0, tL, tU, a, b) } \arguments{ -\item{nvec}{(\code{numeric}):\cr a vector of number of patients in each look.} +\item{nvec}{(\code{numeric}):\cr A vector of number of patients in each look.} \item{p0}{(\code{number}):\cr lower Futility threshold of response rate.} @@ -18,16 +18,6 @@ boundsPostprob(nvec, p0, p1 = p0, tL, tU, a, b) \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} } \value{ -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), posterior probability -(postL), 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), posterior probability (postU) and -the lower bound of one sided 95\% CI for the response rate based on exact -binomial test (LciU). - A matrix for each same size in \code{nvec}. For each sample size, the following is returned: \itemize{ \item \code{xL} : the maximum number of responses that meet the futility. @@ -45,23 +35,19 @@ binomial test. } \description{ This function is used to identify the efficacy and futility -boundaries based on posterior probabilities, i.e.: -Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and -Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +boundaries based on the following rules: } \details{ -Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and -Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and +Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL } \examples{ -## 40 pts trial with interim looks after each 10 pts., -## efficacy decision if more than 90\% probability to be above 20\% ORR, -## futility decision if less than 10\% probability to be above 20\% ORR, -## with uniform prior (i.e. beta(1, 1)) on the ORR: +# 40 pts trial with interim looks after each 10 pts., +# Efficacy decision if more than 60\% probability to be above 20\% ORR, +# Futility decision if less than 60\% probability to be below 20\% ORR, +# with uniform prior (i.e. beta(1, 1)) on the ORR: boundsPostprob( - nvec = c(10, 20, 30, 40), p0 = 0.20, - tL = 0.10, tU = 0.90, a = 1, b = 1 + nvec = c(10, 20, 30, 40), p0 = 0.20, p1 = 0.2, + tL = 0.60, tU = 0.60, a = 1, b = 1 ) -## From this we see e.g. that at the third IA at 30 pts, we would stop for futility -## if 5 or less patients responded, and for efficacy if 9 or more pts responded. } 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-boundsPostProb.R b/tests/testthat/test-boundsPostProb.R index 0ae6eadf..ccbc3458 100644 --- a/tests/testthat/test-boundsPostProb.R +++ b/tests/testthat/test-boundsPostProb.R @@ -4,25 +4,30 @@ test_that("h_decision_one_RctPredProbDist gives correct result and list when rel nvec = c(10, 20, 30, 40), p0 = 0.2, p1 = 0.2, - tL = 0.10, - tU = 0.90, + tL = 0.60, + tU = 0.60, a = 1, b = 1 ) expected <- data.frame( list( nvec = c(10, 20, 30, 40), - xL = c(0, 1, 2, 4), - pL = c(0, 0.05, 0.0667, 0.1), - postL = c(0.0859, 0.0576, 0.0374, 0.0664), - UciL = c(0.2589, 0.2161, 0.1953, 0.2144), - xU = c(4, 7, 9, 12), - pU = c(0.4, 0.35, 0.3, 0.3), - postU = c(0.9496, 0.9569, 0.9254, 0.9479), - LciU = c(0.15, 0.1773, 0.1663, 0.1831) + xL = c(1, 3, 5, 6), + pL = c(0.1, 0.15, 0.1667, 0.15), + postL = c(0.6779, 0.6296, 0.6069, 0.739), + UciL = c(0.3942, 0.3437, 0.319, 0.2747), + xU = c(2, 5, 7, 9), + pU = c(0.2, 0.25, 0.2333, 0.225), + postU = c(0.6174, 0.7693, 0.73, 0.704), + LciU = c(0.0368, 0.1041, 0.115, 0.1227) ) ) - expect_equal(result$xL, c(0, 1, 2, 4)) - expect_equal(result$pL, c(0.0000, 0.0500, 0.0667, 0.1000)) - expect_equal(result$UciL, c(0.2589, 0.2161, 0.1953, 0.2144)) + expect_equal(result$xL, c(1, 3, 5, 6)) + expect_equal(result$pL, c(0.1, 0.15, 0.1667, 0.15)) + expect_equal(result$postL, c(0.6779, 0.6296, 0.6069, 0.739)) + expect_equal(result$UciL, c(0.3942, 0.3437, 0.319, 0.2747)) + expect_equal(result$xU, c(2, 5, 7, 9)) + expect_equal(result$pU, c(0.2, 0.25, 0.2333, 0.225)) + expect_equal(result$postU, c(0.6174, 0.7693, 0.73, 0.704)) + expect_equal(result$LciU, c(0.0368, 0.1041, 0.115, 0.1227)) }) From 51db59a10385b06a25807d86c7984374f14a9d28 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 16:10:51 +0000 Subject: [PATCH 08/35] [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 df9a7cacba18258425b9e91e57af6ef286e051f3 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 26 May 2024 18:13:31 +0200 Subject: [PATCH 09/35] clean --- R/boundsPostprob.R | 1 - man/boundsPostprob.Rd | 2 -- tests/testthat/test-boundsPostProb.R | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index f7b5415d..617d3095 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -2,7 +2,6 @@ #' #' This function is used to identify the efficacy and futility #' boundaries based on the following rules: -#' #' Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and #' Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL #' diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index b405a75c..4488c20d 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -36,8 +36,6 @@ binomial test. \description{ This function is used to identify the efficacy and futility boundaries based on the following rules: -} -\details{ Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL } diff --git a/tests/testthat/test-boundsPostProb.R b/tests/testthat/test-boundsPostProb.R index ccbc3458..cbc28b7b 100644 --- a/tests/testthat/test-boundsPostProb.R +++ b/tests/testthat/test-boundsPostProb.R @@ -1,5 +1,5 @@ # boundsPostProb ---- -test_that("h_decision_one_RctPredProbDist gives correct result and list when relativeDelta = TRUE", { +test_that("boundsPostProb gives correct result and list", { result <- boundsPostprob( nvec = c(10, 20, 30, 40), p0 = 0.2, From bd327cc140ad1750c5edd26c1a8915c10edde5f7 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 26 May 2024 18:14:56 +0200 Subject: [PATCH 10/35] NAMESPACE stuff --- NAMESPACE | 1 - man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 3af942e9..9b572e48 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,6 @@ export(dbetaMix) export(dbetabinom) export(dbetabinomMix) export(dbetadiff) -export(logit) export(myPlot) export(myPlotDiff) export(oc2) 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 +} From e25e4fd3df8e84bfc647c591ff9cbe9237a5dd7f 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 16:17:30 +0000 Subject: [PATCH 11/35] [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 c6ec5cc4851db079b1edb3a8e15fdaa3ebb10098 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 27 May 2024 12:08:37 +0200 Subject: [PATCH 12/35] empty From fe22df674048ba24a13c9d07195b58dfdec8e804 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 27 May 2024 14:14:43 +0200 Subject: [PATCH 13/35] add rmarkdown to DESCRIPTIOPM --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index bfdb50be..6fd25763 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ BugReports: https://github.com/genentech/phase1b/issues Depends: R (>= 3.6) Suggests: + rmarkdown, knitr, officer, shiny, From 95a6080e5eb1a143a6e57db3d2042451c4fd6e40 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 27 May 2024 15:27:51 +0200 Subject: [PATCH 14/35] clean --- DESCRIPTION | 2 + R/boundsPostprob.R | 16 ++-- man/boundsPostprob.Rd | 4 +- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPostProb.R | 8 +- 5 files changed, 137 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a7e3765b..7f3faddd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,8 @@ BugReports: https://github.com/genentech/phase1b/issues Depends: R (>= 3.6) Suggests: + rmarkdown, + bookdown, knitr, officer, shiny, diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index 617d3095..b50fee96 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -14,12 +14,12 @@ #' threshold #' - `pL` : response rate 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 `pL` based on an #' exact binomial test. #' - `xU` : the minimal number of responses that meet the efficacy threshold. #' - `pU` : response rate 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 `pU` based on exact #' binomial test. #' #' @example examples/boundsPostprob.R @@ -31,8 +31,8 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { "xU", "pU", "postU" )) znames <- c( - "xL", "pL", "postL", "UciL", - "xU", "pU", "postU", "LciU" + "xL", "pL", "postL", "pL_upper_ci", + "xU", "pU", "postU", "pU_lower_ci" ) z <- matrix(NA, length(nvec), length(znames)) dimnames(z) <- list(nvec, znames) @@ -56,17 +56,17 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { } } # 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) + 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) z[k, ] <- c( xL, xL / n, postL, - UciL, + pL_upper_ci, xU, xU / n, postU, - LciU + pU_lower_ci ) } return(round(data.frame(nvec, z), 4)) diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 4488c20d..4394ef94 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -24,12 +24,12 @@ A matrix for each same size in \code{nvec}. For each sample size, the following threshold \item \code{pL} : response rate 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 \code{pL} 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{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 \code{pU} based on exact binomial test. } } 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-boundsPostProb.R b/tests/testthat/test-boundsPostProb.R index cbc28b7b..3d74d3bc 100644 --- a/tests/testthat/test-boundsPostProb.R +++ b/tests/testthat/test-boundsPostProb.R @@ -15,19 +15,19 @@ test_that("boundsPostProb gives correct result and list", { xL = c(1, 3, 5, 6), pL = c(0.1, 0.15, 0.1667, 0.15), postL = c(0.6779, 0.6296, 0.6069, 0.739), - UciL = c(0.3942, 0.3437, 0.319, 0.2747), + pL_upper_ci = c(0.3942, 0.3437, 0.319, 0.2747), xU = c(2, 5, 7, 9), pU = c(0.2, 0.25, 0.2333, 0.225), postU = c(0.6174, 0.7693, 0.73, 0.704), - LciU = c(0.0368, 0.1041, 0.115, 0.1227) + pU_lower_ci = c(0.0368, 0.1041, 0.115, 0.1227) ) ) expect_equal(result$xL, c(1, 3, 5, 6)) expect_equal(result$pL, c(0.1, 0.15, 0.1667, 0.15)) expect_equal(result$postL, c(0.6779, 0.6296, 0.6069, 0.739)) - expect_equal(result$UciL, c(0.3942, 0.3437, 0.319, 0.2747)) + expect_equal(result$pL_upper_ci, c(0.3942, 0.3437, 0.319, 0.2747)) expect_equal(result$xU, c(2, 5, 7, 9)) expect_equal(result$pU, c(0.2, 0.25, 0.2333, 0.225)) expect_equal(result$postU, c(0.6174, 0.7693, 0.73, 0.704)) - expect_equal(result$LciU, c(0.0368, 0.1041, 0.115, 0.1227)) + expect_equal(result$pU_lower_ci, c(0.0368, 0.1041, 0.115, 0.1227)) }) From 670558da97cd2b4da3246b84013dd105cf89b64f 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: Mon, 27 May 2024 13:31:18 +0000 Subject: [PATCH 15/35] [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 a29fd0fd1921d2e89390f3e1dd3293cf7d62d1f6 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 2 Jun 2024 19:37:45 +0200 Subject: [PATCH 16/35] should pass CMD checks From fe3f37fac2d62b821404a5ebbf9b93b57cccb041 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 3 Jun 2024 08:43:45 +0200 Subject: [PATCH 17/35] see if CMD checks pass now From d4759efe3f9f5940e3025052ba573127ed637a6b Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 11 Jun 2024 10:49:30 +0200 Subject: [PATCH 18/35] clean --- NAMESPACE | 2 +- R/plotBeta.R | 36 +++++++------ inst/WORDLIST | 1 + man/myPlotDiff.Rd | 33 ------------ man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++++ man/plotBetaDist.Rd | 33 ++++++++++++ 6 files changed, 177 insertions(+), 49 deletions(-) delete mode 100644 man/myPlotDiff.Rd create mode 100644 man/plotBetaDist.Rd diff --git a/NAMESPACE b/NAMESPACE index 9b572e48..7221e4b2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,6 @@ export(dbetabinom) export(dbetabinomMix) export(dbetadiff) export(myPlot) -export(myPlotDiff) export(oc2) export(oc3) export(ocPostprob) @@ -18,6 +17,7 @@ export(ocRctPostprobDist) export(ocRctPredprobDist) export(pbetaMix) export(pbetadiff) +export(plotBetaDist) export(plotBounds) export(plotDecision) export(plotOc) diff --git a/R/plotBeta.R b/R/plotBeta.R index d4ebf5a3..00ae90f9 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -41,14 +41,20 @@ myPlot <- function(alpha, beta, ...) { #' #' This function will plot the PDF of a diffience between two Beta distributions #' -#' @param parY non-negative parameters of the treatment Beta distribution. -#' @param parX non-negative parameters of the historical control Beta distribution -#' @param cut_B a meaningful improvement threshold -#' @param cut_W a poor improvement throshold -#' @param shade paint the two areas under the curve, default value=1 as "yes". other numbers stands for "no"; -#' @param note show values of the colored area, default value=1 as "yes". other numbers stands for "no" -#' @param \dots additional arguments to \code{plot} -#' @return nothing, only produces the plot as side effect +#' @typed parY : numeric +#' non-negative parameters of the treatment Beta distribution. +#' @typed parX : numeric +#' non-negative parameters of the historical control Beta distribution +#' @typed cut_B : number +#' a meaningful improvement threshold, the lower boundary of a meaningfully improvement in response rate +#' @typed cut_W : number +#' a poor improvement throshold, the upper boundary of a meaningfully poor improvement in response rate +#' @typed shade : +#' paint the two areas under the curve, default value=1 as "yes". other numbers stands for "no"; +#' @typed note : number +#' show values of the colored area, default value=1 as "yes". other numbers stands for "no" +#' @typed \dots additional arguments to \code{plot} +#' @return a ggplot object #' #' @example examples/myPlotDiff.R #' @@ -57,13 +63,13 @@ myPlot <- function(alpha, beta, ...) { #' #' @export #' @keywords graphics -myPlotDiff <- function(parY, # parameters of phase Ib trial; - parX, # parameters of HC; - cut_B = 0.20, # a meaningful improvement threshold; - cut_W = 0.1, # a poor improvement threshold; - shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no"; - note = 1, # show values of the colored area, default: yes. other numbers stands for "no"; - ...) { +plotBetaDist <- function(parY, # parameters of phase Ib trial; + parX, # parameters of HC; + cut_B = 0.20, # a meaningful improvement threshold; + cut_W = 0.1, # a poor improvement threshold; + shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no"; + note = 1, # show values of the colored area, default: yes. other numbers stands for "no"; + ...) { if (note == 1) { graphics::par(mar = c(5, 15, 1, 15) + .1) } else { diff --git a/inst/WORDLIST b/inst/WORDLIST index f6be2e38..178e3901 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -94,6 +94,7 @@ frac funder generalizable geq +ggplot grayzone grey hier diff --git a/man/myPlotDiff.Rd b/man/myPlotDiff.Rd deleted file mode 100644 index 6be1ecbf..00000000 --- a/man/myPlotDiff.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plotBeta.R -\name{myPlotDiff} -\alias{myPlotDiff} -\title{Plot Diff Between two Beta distributions} -\usage{ -myPlotDiff(parY, parX, cut_B = 0.2, cut_W = 0.1, shade = 1, note = 1, ...) -} -\arguments{ -\item{parY}{non-negative parameters of the treatment Beta distribution.} - -\item{parX}{non-negative parameters of the historical control Beta distribution} - -\item{cut_B}{a meaningful improvement threshold} - -\item{cut_W}{a poor improvement throshold} - -\item{shade}{paint the two areas under the curve, default value=1 as "yes". other numbers stands for "no";} - -\item{note}{show values of the colored area, default value=1 as "yes". other numbers stands for "no"} - -\item{\dots}{additional arguments to \code{plot}} -} -\value{ -nothing, only produces the plot as side effect -} -\description{ -This function will plot the PDF of a diffience between two Beta distributions -} -\examples{ -myPlotDiff(c(5, 10), c(2, 5), 0.2, 0.05, 1, 0) -} -\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 +} diff --git a/man/plotBetaDist.Rd b/man/plotBetaDist.Rd new file mode 100644 index 00000000..1b9c8d5e --- /dev/null +++ b/man/plotBetaDist.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotBeta.R +\name{plotBetaDist} +\alias{plotBetaDist} +\title{Plot Diff Between two Beta distributions} +\usage{ +plotBetaDist(parY, parX, cut_B = 0.2, cut_W = 0.1, shade = 1, note = 1, ...) +} +\arguments{ +\item{parY}{(\code{numeric}):\cr non-negative parameters of the treatment Beta distribution.} + +\item{parX}{(\code{numeric}):\cr non-negative parameters of the historical control Beta distribution} + +\item{cut_B}{(\code{number}):\cr a meaningful improvement threshold, the lower boundary of a meaningfully improvement in response rate} + +\item{cut_W}{(\code{number}):\cr a poor improvement throshold, the upper boundary of a meaningfully poor improvement in response rate} + +\item{shade}{(``):\cr paint the two areas under the curve, default value=1 as "yes". other numbers stands for "no";} + +\item{note}{(\code{number}):\cr show values of the colored area, default value=1 as "yes". other numbers stands for "no"} + +\item{}{(\if{html}{\out{}}):\cr \if{html}{\out{}}} +} +\value{ +a ggplot object +} +\description{ +This function will plot the PDF of a diffience between two Beta distributions +} +\examples{ +myPlotDiff(c(5, 10), c(2, 5), 0.2, 0.05, 1, 0) +} +\keyword{graphics} From 188027d4924193f240e01c642bc8c9126b64fedc 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 09:02:38 +0000 Subject: [PATCH 19/35] [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 40b490e433e134b8d3f24f7f2803d9d170b5ec4f 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: Mon, 16 Sep 2024 12:43:30 +0000 Subject: [PATCH 20/35] [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 97b06858f6cf0a644a8ee77248adf18d1f1aa18f Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 22 Sep 2024 20:37:02 +0200 Subject: [PATCH 21/35] just some first drafts --- R/plotBeta.R | 157 +++++++++++++------------------------------- examples/plotBeta.R | 13 ++++ man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++ man/plotBeta.Rd | 15 ++++- man/plotBetaDiff.Rd | 15 ++--- 5 files changed, 201 insertions(+), 120 deletions(-) diff --git a/R/plotBeta.R b/R/plotBeta.R index e22d383c..8552e6ae 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -2,11 +2,11 @@ #' #' This function will plot the PDF of a beta distribution #' +#' @inheritParams dbetabinom #' @typed alpha : number #' first parameter of the Beta distribution #' @typed beta : number #' second parameter of the Beta distribution -#' #' @return A beta distribution density plot #' #' @importFrom graphics axis @@ -14,7 +14,7 @@ #' @example examples/plotBeta.R #' @export #' @keywords graphics -plotBeta <- function(alpha, beta) { +plotBeta <- function(alpha, beta, ...) { x_support <- seq(from = 0, to = 1, length = 1000) data <- data.frame( grid = x_support, @@ -57,123 +57,58 @@ plotBeta <- function(alpha, beta) { #' #' @export #' @keywords graphics -plotBetaDiff <- function(parY, # parameters of phase Ib trial; - parX, # parameters of HC; - cut_B = 0.20, # a meaningful improvement threshold; - cut_W = 0.1, # a poor improvement threshold; - shade = TRUE, # paint the two areas under the curve, - # default: yes. other numbers stands for "no"; - note = TRUE, # show values of the colored area, - # default: yes. other numbers stands for "no"; - ...) { - if (note == 1) { - graphics::par(mar = c(5, 15, 1, 15) + .1) - } else { - graphics::par(mar = c(5, 5, 1, 5) + .1) - } - grid <- seq(from = -0.5, to = 0.75, length = 1000) - xticks <- seq(from = -1, to = 1, by = 0.25) +plotBetaDiff <- function(parY, # parameters of experimental arm + parX, # parameters of control or SOC + Go_cut = 0.20, # a meaningful improvement threshold + Stop_cut = 0.1, # a poor improvement threshold + shade = TRUE, # paint the two areas under the curve + note = TRUE) { # show values of the colored area + diff <- seq(from = -1, to = 1, length = 1000) + data <- data.frame( + grid = diff, + xticks = seq(from = 0, to = 1, by = 0.25), + density = dbetadiff(z = diff, parY = parY, parX = parX) + ) + data$Stop <- ifelse(diff > -1 & diff < Stop_cut, TRUE, FALSE) + data$Go <- ifelse(diff > Go_cut & diff < 1, TRUE, FALSE) + # shade the AUC for Go if difference was `lower` : - graphics::plot( - x = grid, - y = dbetadiff(grid, parY = parY, parX = parX), - ylab = "", - xaxt = "n", - yaxt = "n", - type = "l", - xaxs = "i", - yaxs = "i", - ... + Go_auc <- integrate( + f = dbetadiff, + parY = parY, + parX = parX, + lower = Go_cut, # Calculate probability of Go, if difference was at least `Go_cut`. + upper = 1 ) - - graphics::axis( - side = 1, at = xticks, - labels = - paste(ifelse(xticks >= 0, "+", ""), - xticks * 100, "%", - sep = "" - ) + Stop_auc <- integrate( + f = dbetadiff, + parY = parY, + parX = parX, + lower = -1, + upper = Stop_cut # Calculate probability of Stop, if difference was at most `Stop_cut`. ) - ## now color the go / stop prob areas + Go_label <- paste("Probability of Go is", round(Go_auc$value * 100, digits = 2), "%") + Stop_label <- paste("Probability of Stop is", round(Stop_auc$value * 100, digits = 2), "%") + plot_title <- paste("According to Beta difference density", Go_label, "and", Stop_label) - if (shade == 1) { - ## first stop: - stopGrid <- grid[grid <= cut_W] - nStop <- length(stopGrid) - - graphics::polygon( - x = - c( - stopGrid, - rev(stopGrid) - ), - y = - c( - rep(0, nStop), - dbetadiff(rev(stopGrid), parY = parY, parX = parX) - ), - col = "red" - ) - - A_value <- stats::integrate( - f = dbetadiff, - parY = parY, - parX = parX, - lower = -1, - upper = cut_W - ) - if (note == 1) { - graphics::mtext( - paste("Prob(diff< ", round(cut_W * 100), "%)=", - sprintf("%1.2f%%", 100 * as.numeric(A_value$value)), - sep = "" - ), - side = 2, line = 1, las = 1, cex = 1 - ) - } - - ## then go: - goGrid <- grid[grid >= cut_B] - nGo <- length(goGrid) - - graphics::polygon( - x = - c( - goGrid, - rev(goGrid) - ), - y = - c( - rep(0, nGo), - dbetadiff(rev(goGrid), parY = parY, parX = parX) - ), - col = "green" - ) + pbetadiff_plot <- ggplot2::ggplot(data = data, mapping = aes(x = grid, y = density)) + + ggplot2::geom_line(colour = "#888888") + + xlab("Difference between treatment") + + ggplot2::ylab(quote(f(x))) + + ggplot2::ggtitle(plot_title) - B_value <- stats::integrate( - f = dbetadiff, - parY = parY, - parX = parX, - lower = cut_B, - upper = 1 - ) + if (shade == TRUE) { + pbetadiff_plot + + ggplot2::geom_area(data = filter(data, Go == TRUE), fill = "#009E73") + + ggplot2::geom_area(data = filter(data, Stop == TRUE), fill = "#D55E00") + } - if (note == 1) { - graphics::mtext( - paste( - sprintf("%1.2f%%", 100 * as.numeric(B_value$value)), - "=Prob(diff> ", - round(cut_B * 100), "%)", - sep = "" - ), - side = 4, - line = 1, - las = 1, - cex = 1 - ) - } + if (note == TRUE) { + pbetadiff_plot + + ggplot2::annotate("text", x = -0.5, y = 4.25, label = Go_label, colour = "#009E73") + + ggplot2::annotate("text", x = -0.5, y = 4.75, label = Stop_label, colour = "#D55E00") } } diff --git a/examples/plotBeta.R b/examples/plotBeta.R index 6e84087b..9fd6a98c 100644 --- a/examples/plotBeta.R +++ b/examples/plotBeta.R @@ -1,2 +1,15 @@ +# plotBeta plotBeta(alpha = 4, beta = 5) plotBeta(alpha = 1, beta = 1) + +# plotBetDiff +parX <- c(1, 52) # parameters of experimental arm +parY <- c(5.5, 20.5) # parameters of control or SOC +plotBetaDiff( + parY = parY, + parX = parX, + Go_cut = 0.3, + Stop_cut = 0.1, + shade = TRUE, + note = TRUE +) 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/man/plotBeta.Rd b/man/plotBeta.Rd index bf45b581..94577edd 100644 --- a/man/plotBeta.Rd +++ b/man/plotBeta.Rd @@ -4,7 +4,7 @@ \alias{plotBeta} \title{Plot the Beta distribution} \usage{ -plotBeta(alpha, beta) +plotBeta(alpha, beta, ...) } \arguments{ \item{alpha}{(\code{number}):\cr first parameter of the Beta distribution} @@ -18,7 +18,20 @@ A beta distribution density plot This function will plot the PDF of a beta distribution } \examples{ +# plotBeta plotBeta(alpha = 4, beta = 5) plotBeta(alpha = 1, beta = 1) + +# plotBetDiff +parX <- c(1, 52) # parameters of experimental arm +parY <- c(5.5, 20.5) # parameters of control or SOC +plotBetaDiff( + parY = parY, + parX = parX, + Go_cut = 0.3, + Stop_cut = 0.1, + shade = TRUE, + note = TRUE +) } \keyword{graphics} diff --git a/man/plotBetaDiff.Rd b/man/plotBetaDiff.Rd index f8be7e5d..1651cf22 100644 --- a/man/plotBetaDiff.Rd +++ b/man/plotBetaDiff.Rd @@ -7,11 +7,10 @@ plotBetaDiff( parY, parX, - cut_B = 0.2, - cut_W = 0.1, + Go_cut = 0.2, + Stop_cut = 0.1, shade = TRUE, - note = TRUE, - ... + note = TRUE ) } \arguments{ @@ -19,14 +18,14 @@ plotBetaDiff( \item{parX}{(\code{numeric}):\cr non-negative parameters of the historical control Beta distribution} -\item{cut_B}{(\code{number}):\cr a meaningful improvement threshold, the lower boundary of a meaningfully improvement in response rate} - -\item{cut_W}{(\code{number}):\cr a poor improvement threshold, the upper boundary of a meaningfully poor improvement in response rate} - \item{shade}{(\code{flag}):\cr paint the two areas under the curve, default value = TRUE} \item{note}{(\code{flag}):\cr show values of the colored area, default value = TRUE} +\item{cut_B}{(\code{number}):\cr a meaningful improvement threshold, the lower boundary of a meaningfully improvement in response rate} + +\item{cut_W}{(\code{number}):\cr a poor improvement threshold, the upper boundary of a meaningfully poor improvement in response rate} + \item{...}{(``):\cr additional arguments to \code{ggplot()}} } \value{ From be2e55b7fe19e0fe1becb198f4cbceefd9e73b83 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, 22 Sep 2024 18:40:30 +0000 Subject: [PATCH 22/35] [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 7e75e6801c6b429e6d1cfeb0a284e4c6a5850e92 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 22 Sep 2024 20:42:35 +0200 Subject: [PATCH 23/35] exame file for plotBetaDiff.R --- R/plotBeta.R | 3 --- examples/myPlotDiff.R | 2 +- examples/plotBeta.R | 12 ------------ examples/plotBetaDiff.R | 11 +++++++++++ man/plotBeta.Rd | 12 ------------ man/plotBetaDiff.Rd | 2 +- 6 files changed, 13 insertions(+), 29 deletions(-) create mode 100644 examples/plotBetaDiff.R diff --git a/R/plotBeta.R b/R/plotBeta.R index 8552e6ae..88e2a5ea 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -69,12 +69,9 @@ plotBetaDiff <- function(parY, # parameters of experimental arm xticks = seq(from = 0, to = 1, by = 0.25), density = dbetadiff(z = diff, parY = parY, parX = parX) ) - data$Stop <- ifelse(diff > -1 & diff < Stop_cut, TRUE, FALSE) data$Go <- ifelse(diff > Go_cut & diff < 1, TRUE, FALSE) - # shade the AUC for Go if difference was `lower` : - Go_auc <- integrate( f = dbetadiff, parY = parY, diff --git a/examples/myPlotDiff.R b/examples/myPlotDiff.R index c9a4795e..991f9fc2 100644 --- a/examples/myPlotDiff.R +++ b/examples/myPlotDiff.R @@ -4,5 +4,5 @@ myPlotDiff( cut_B = 0.2, # a meaningful improvement threshold cut_W = 0.05, # a poor improvement threshold shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no"; - note = 0 + note = 1 ) # show values of the colored area, default: yes. other numbers stands for "no"; diff --git a/examples/plotBeta.R b/examples/plotBeta.R index 9fd6a98c..712b5482 100644 --- a/examples/plotBeta.R +++ b/examples/plotBeta.R @@ -1,15 +1,3 @@ # plotBeta plotBeta(alpha = 4, beta = 5) plotBeta(alpha = 1, beta = 1) - -# plotBetDiff -parX <- c(1, 52) # parameters of experimental arm -parY <- c(5.5, 20.5) # parameters of control or SOC -plotBetaDiff( - parY = parY, - parX = parX, - Go_cut = 0.3, - Stop_cut = 0.1, - shade = TRUE, - note = TRUE -) diff --git a/examples/plotBetaDiff.R b/examples/plotBetaDiff.R new file mode 100644 index 00000000..0a22a11c --- /dev/null +++ b/examples/plotBetaDiff.R @@ -0,0 +1,11 @@ +# plotBetDiff +parX <- c(1, 52) # parameters of experimental arm +parY <- c(5.5, 20.5) # parameters of control or SOC +plotBetaDiff( + parY = parY, + parX = parX, + Go_cut = 0.3, + Stop_cut = 0.1, + shade = TRUE, + note = TRUE +) diff --git a/man/plotBeta.Rd b/man/plotBeta.Rd index 94577edd..a17df369 100644 --- a/man/plotBeta.Rd +++ b/man/plotBeta.Rd @@ -21,17 +21,5 @@ This function will plot the PDF of a beta distribution # plotBeta plotBeta(alpha = 4, beta = 5) plotBeta(alpha = 1, beta = 1) - -# plotBetDiff -parX <- c(1, 52) # parameters of experimental arm -parY <- c(5.5, 20.5) # parameters of control or SOC -plotBetaDiff( - parY = parY, - parX = parX, - Go_cut = 0.3, - Stop_cut = 0.1, - shade = TRUE, - note = TRUE -) } \keyword{graphics} diff --git a/man/plotBetaDiff.Rd b/man/plotBetaDiff.Rd index 1651cf22..6c7b9c4d 100644 --- a/man/plotBetaDiff.Rd +++ b/man/plotBetaDiff.Rd @@ -41,7 +41,7 @@ myPlotDiff( cut_B = 0.2, # a meaningful improvement threshold cut_W = 0.05, # a poor improvement threshold shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no"; - note = 0 + note = 1 ) # show values of the colored area, default: yes. other numbers stands for "no"; } \keyword{graphics} From ec5abb8d7548228ab1e30f069f0664fa362694e3 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 27 May 2024 12:08:37 +0200 Subject: [PATCH 24/35] empty From 2757aab2356968045c393c4ef935913772f7dc23 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 2 Jun 2024 19:37:45 +0200 Subject: [PATCH 25/35] should pass CMD checks From 93f463a9cee89eab60642bf79a616d58ebefc663 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Sun, 22 Sep 2024 20:53:40 +0200 Subject: [PATCH 26/35] clean --- R/boundsPostprob.R | 15 ++-- man/ocPredprob.Rd | 121 +++++++++++++++++++++++++++ tests/testthat/test-boundsPostProb.R | 36 ++++---- 3 files changed, 143 insertions(+), 29 deletions(-) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index b50fee96..e39be43f 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -25,16 +25,11 @@ #' @example examples/boundsPostprob.R #' @export 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, nrow = length(nvec), ncol = 8) znames <- c( "xL", "pL", "postL", "pL_upper_ci", "xU", "pU", "postU", "pU_lower_ci" ) - z <- matrix(NA, length(nvec), length(znames)) dimnames(z) <- list(nvec, znames) k <- 0 for (n in nvec) { @@ -44,12 +39,12 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { xU <- NA for (x in 0:n) { postp <- 1 - postprob(x, n, p0, parE = c(a, b)) # futility look - if (postp >= tL) { + if (postp >= tL) { # Rule is P(RR < p0) > tL postL <- postp xL <- x } - postp <- postprob(x, n, p0, parE = c(a, b)) # efficacy look - if (postp >= tU) { + postp <- postprob(x, n, p1, parE = c(a, b)) # efficacy look + if (postp >= tU) { # Rule is P(RR > p1) > tU postU <- postp xU <- x break @@ -69,5 +64,5 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) { pU_lower_ci ) } - return(round(data.frame(nvec, z), 4)) + round(data.frame(nvec, z), 4) } 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-boundsPostProb.R b/tests/testthat/test-boundsPostProb.R index 3d74d3bc..e31397a8 100644 --- a/tests/testthat/test-boundsPostProb.R +++ b/tests/testthat/test-boundsPostProb.R @@ -10,24 +10,22 @@ test_that("boundsPostProb gives correct result and list", { b = 1 ) expected <- data.frame( - list( - nvec = c(10, 20, 30, 40), - xL = c(1, 3, 5, 6), - pL = c(0.1, 0.15, 0.1667, 0.15), - postL = c(0.6779, 0.6296, 0.6069, 0.739), - pL_upper_ci = c(0.3942, 0.3437, 0.319, 0.2747), - xU = c(2, 5, 7, 9), - pU = c(0.2, 0.25, 0.2333, 0.225), - postU = c(0.6174, 0.7693, 0.73, 0.704), - pU_lower_ci = c(0.0368, 0.1041, 0.115, 0.1227) - ) + nvec = c(10, 20, 30, 40), + xL = c(1, 3, 5, 6), + pL = c(0.1, 0.15, 0.1667, 0.15), + postL = c(0.6779, 0.6296, 0.6069, 0.739), + pL_upper_ci = c(0.3942, 0.3437, 0.319, 0.2747), + xU = c(2, 5, 7, 9), + pU = c(0.2, 0.25, 0.2333, 0.225), + postU = c(0.6174, 0.7693, 0.73, 0.704), + pU_lower_ci = c(0.0368, 0.1041, 0.115, 0.1227) ) - expect_equal(result$xL, c(1, 3, 5, 6)) - expect_equal(result$pL, c(0.1, 0.15, 0.1667, 0.15)) - expect_equal(result$postL, c(0.6779, 0.6296, 0.6069, 0.739)) - expect_equal(result$pL_upper_ci, c(0.3942, 0.3437, 0.319, 0.2747)) - expect_equal(result$xU, c(2, 5, 7, 9)) - expect_equal(result$pU, c(0.2, 0.25, 0.2333, 0.225)) - expect_equal(result$postU, c(0.6174, 0.7693, 0.73, 0.704)) - expect_equal(result$pU_lower_ci, c(0.0368, 0.1041, 0.115, 0.1227)) + expect_equal(result$xL, expected$xL) + expect_equal(result$pL, expected$pL) + expect_equal(result$postL, expected$postL) + expect_equal(result$pL_upper_ci, expected$pL_upper_ci) + expect_equal(result$xU, expected$xU) + expect_equal(result$pU, expected$pU) + expect_equal(result$postU, expected$postU) + expect_equal(result$pU_lower_ci, expected$pU_lower_ci) }) From 27cfdc9c1645a83b71f755cb9d39389592ed0c64 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, 22 Sep 2024 18:56:58 +0000 Subject: [PATCH 27/35] [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 b569a7a316a4ea7c51df1447aed87a5fc96d5a62 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 23 Sep 2024 15:02:25 +0200 Subject: [PATCH 28/35] clean --- R/plotBeta.R | 10 ++-- man/ocPredprob.Rd | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 5 deletions(-) diff --git a/R/plotBeta.R b/R/plotBeta.R index 88e2a5ea..8dfcf795 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -66,7 +66,6 @@ plotBetaDiff <- function(parY, # parameters of experimental arm diff <- seq(from = -1, to = 1, length = 1000) data <- data.frame( grid = diff, - xticks = seq(from = 0, to = 1, by = 0.25), density = dbetadiff(z = diff, parY = parY, parX = parX) ) data$Stop <- ifelse(diff > -1 & diff < Stop_cut, TRUE, FALSE) @@ -98,14 +97,15 @@ plotBetaDiff <- function(parY, # parameters of experimental arm ggplot2::ggtitle(plot_title) if (shade == TRUE) { - pbetadiff_plot + - ggplot2::geom_area(data = filter(data, Go == TRUE), fill = "#009E73") + - ggplot2::geom_area(data = filter(data, Stop == TRUE), fill = "#D55E00") + pbetadiff_plot <- pbetadiff_plot + + ggplot2::geom_area(data = data[data$Go == TRUE, ], fill = "#009E73") + + ggplot2::geom_area(data = data[data$Stop == TRUE, ], fill = "#D55E00") } if (note == TRUE) { - pbetadiff_plot + + pbetadiff_plot <- pbetadiff_plot + ggplot2::annotate("text", x = -0.5, y = 4.25, label = Go_label, colour = "#009E73") + ggplot2::annotate("text", x = -0.5, y = 4.75, label = Stop_label, colour = "#D55E00") } + pbetadiff_plot } 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 db9412de0505bb5006da18017f974b7729b0b985 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 24 May 2024 14:00:43 +0200 Subject: [PATCH 29/35] clean --- R/boundsPostprob.R | 5 +++++ man/boundsPostprob.Rd | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/R/boundsPostprob.R b/R/boundsPostprob.R index e39be43f..eb490e67 100644 --- a/R/boundsPostprob.R +++ b/R/boundsPostprob.R @@ -5,6 +5,9 @@ #' Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and #' Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL #' +#' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and +#' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +#' #' @inheritParams postprob #' @inheritParams ocPostprob #' @typed nvec : numeric @@ -15,11 +18,13 @@ #' - `pL` : response rate corresponding to `xL`. #' - `postL`: posterior probability corresponding to `xL`. #' - `pL_upper_ci` : upper bound of one sided 95% CI for the response rate `pL` based on an +#' - `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`. #' - `postU` : posterior probability corresponding to `xU`. #' - `pU_lower_ci` : lower bound of one sided 95% CI for the response rate `pU` based on exact +#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact #' binomial test. #' #' @example examples/boundsPostprob.R diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 4394ef94..9a664fb9 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -24,12 +24,20 @@ A matrix for each same size in \code{nvec}. For each sample size, the following threshold \item \code{pL} : response rate corresponding to \code{xL}. \item \code{postL}: posterior probability corresponding to \code{xL}. +<<<<<<< HEAD \item \code{pL_upper_ci} : upper bound of one sided 95\% CI for the response rate \code{pL} based on an +======= +\item \code{Ucil} : upper bound of one sided 95\% CI for the response rate based on an +>>>>>>> 008502d (clean) 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{postU} : posterior probability corresponding to \code{xU}. +<<<<<<< HEAD \item \code{pU_lower_ci} : lower bound of one sided 95\% CI for the response rate \code{pU} based on exact +======= +\item \code{LciU} : lower bound of one sided 95\% CI for the response rate based on exact +>>>>>>> 008502d (clean) binomial test. } } @@ -39,6 +47,10 @@ boundaries based on the following rules: Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL } +\details{ +Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and +Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL +} \examples{ # 40 pts trial with interim looks after each 10 pts., # Efficacy decision if more than 60\% probability to be above 20\% ORR, From 6484d12727e09e28d7b7cd2009b3fb2e70c76265 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 23 Sep 2024 15:18:16 +0200 Subject: [PATCH 30/35] clean --- inst/WORDLIST | 3 +++ man/ocPredprob.Rd | 3 +++ 2 files changed, 6 insertions(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index 86e46e6c..be3cf716 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -202,6 +202,8 @@ renewcommand reproducibility responder responders +roxygen +Roxygen Sabanes sabanes Sabanés @@ -244,6 +246,7 @@ USUBJID VAD vanillaBayes vanillaPP +vbump Vehtari WeightedBayes weightedBetaPrior diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 63e17a09..d6480b8d 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -117,6 +117,7 @@ The criteria for Decision 2 for Futility looks are : } } } +<<<<<<< HEAD \examples{ # Here we illustrate an example for Decision 1 with the following assumptions : # True response rate or truep of the treatment group = 40\% @@ -238,3 +239,5 @@ result <- ocPredprob( ) result$oc } +======= +>>>>>>> ab51030 ([skip roxygen] [skip vbump] Roxygen Man Pages Auto Update) From 21f0ee4fd91a8766fc769e760057098721052ddf Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 2 Jan 2025 16:43:52 +0100 Subject: [PATCH 31/35] clean --- R/plotBeta.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/plotBeta.R b/R/plotBeta.R index 8dfcf795..792fc0c0 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -30,7 +30,7 @@ plotBeta <- function(alpha, beta, ...) { ggplot2::scale_x_continuous(labels = scales::percent_format()) } -#' Plot Diff Between two Beta distributions +#' Plot difference Between two Beta distributions #' #' This function will plot the PDF of a difference between two Beta distributions #' @@ -50,7 +50,7 @@ plotBeta <- function(alpha, beta, ...) { #' additional arguments to `ggplot()` #' @return a ggplot object #' -#' @example examples/myPlotDiff.R +#' @example examples/plotBetaDiff.R #' #' @importFrom graphics par axis polygon mtext #' @importFrom stats integrate From f922d4669d1bf4fde0f4e3af397967ff0010ebd8 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Thu, 2 Jan 2025 22:23:26 +0100 Subject: [PATCH 32/35] clean --- R/plotBeta.R | 31 ++++++++++++++++++------------- examples/myPlotDiff.R | 8 -------- examples/plotBetaDiff.R | 3 ++- man/ocPredprob.Rd | 16 ++++++++-------- man/plotBetaDiff.Rd | 22 +++++++++++++--------- 5 files changed, 41 insertions(+), 39 deletions(-) delete mode 100644 examples/myPlotDiff.R diff --git a/R/plotBeta.R b/R/plotBeta.R index 792fc0c0..da475c60 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -86,22 +86,27 @@ plotBetaDiff <- function(parY, # parameters of experimental arm upper = Stop_cut # Calculate probability of Stop, if difference was at most `Stop_cut`. ) - Go_label <- paste("Probability of Go is", round(Go_auc$value * 100, digits = 2), "%") - Stop_label <- paste("Probability of Stop is", round(Stop_auc$value * 100, digits = 2), "%") - plot_title <- paste("According to Beta difference density", Go_label, "and", Stop_label) - - pbetadiff_plot <- ggplot2::ggplot(data = data, mapping = aes(x = grid, y = density)) + - ggplot2::geom_line(colour = "#888888") + - xlab("Difference between treatment") + - ggplot2::ylab(quote(f(x))) + - ggplot2::ggtitle(plot_title) + Go_label <- paste("probability of Go is", round(Go_auc$value * 100, digits = 2), "%") + Stop_label <- paste("probability of Stop is", round(Stop_auc$value * 100, digits = 2), "%") + plot_title <- paste("According to Beta difference density", Go_label, "and\n", Stop_label) if (shade == TRUE) { - pbetadiff_plot <- pbetadiff_plot + - ggplot2::geom_area(data = data[data$Go == TRUE, ], fill = "#009E73") + - ggplot2::geom_area(data = data[data$Stop == TRUE, ], fill = "#D55E00") + pbetadiff_plot <- ggplot2::ggplot(data = data, aes(x = grid, y = density)) + + ggplot2::geom_line(colour = "#888888") + + geom_area(data = data[data$grid < Stop_cut,], fill = "#D55E00", + mapping = aes(x = ifelse(grid < 0.2 & grid < 0.5, grid, 0))) + + geom_area(data = data[data$grid > Go_cut,], fill = "#009E73", + mapping = aes(x = ifelse(grid > 0.3, grid, 0))) + + xlab("Difference between treatment") + + ggplot2::ylab(quote(f(x))) + + ggplot2::ggtitle(plot_title) + } else { + pbetadiff_plot <- ggplot2::ggplot(data = data, aes(x = grid, y = density)) + + ggplot2::geom_line(colour = "#888888") + + xlab("Difference between treatment") + + ggplot2::ylab(quote(f(x))) + + ggplot2::ggtitle(plot_title) } - if (note == TRUE) { pbetadiff_plot <- pbetadiff_plot + ggplot2::annotate("text", x = -0.5, y = 4.25, label = Go_label, colour = "#009E73") + diff --git a/examples/myPlotDiff.R b/examples/myPlotDiff.R deleted file mode 100644 index 991f9fc2..00000000 --- a/examples/myPlotDiff.R +++ /dev/null @@ -1,8 +0,0 @@ -myPlotDiff( - parY = c(5, 10), - parX = c(2, 5), - cut_B = 0.2, # a meaningful improvement threshold - cut_W = 0.05, # a poor improvement threshold - shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no"; - note = 1 -) # show values of the colored area, default: yes. other numbers stands for "no"; diff --git a/examples/plotBetaDiff.R b/examples/plotBetaDiff.R index 0a22a11c..fd8726ec 100644 --- a/examples/plotBetaDiff.R +++ b/examples/plotBetaDiff.R @@ -1,4 +1,5 @@ -# plotBetDiff +# The beta distribution and acceptable bounds for +# a meaningful improvement of 0.20 and worsening of 0.05 parX <- c(1, 52) # parameters of experimental arm parY <- c(5.5, 20.5) # parameters of control or SOC plotBetaDiff( diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index 05595ace..63e17a09 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( RR > p0 | data) > tT -\item Final STOP = P( RR > p0 | data ) < tT +\item Final GO = P( response rate > p0 | data) > tT +\item Final STOP = P( response rate > 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( RR > p0) > tT -\item Final STOP = P( RR < p1) > tF +\item Final GO = P( response rate > p0) > tT +\item Final STOP = P( response rate < p1) > tF } } } @@ -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( RR > 25\% ) > 60\% or P( RR > p0) > tT -# - Final look for Futility: Pr( RR < 25\% ) < 60\% or P(RR > p0) < tT +# - 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. @@ -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( RR > 25\% ) > 60\% or P(RR > p0) > tT -# - Final look for Futility: Pr( RR < 25\% ) < 60\% or P(RR < p1) > tF +# - 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. diff --git a/man/plotBetaDiff.Rd b/man/plotBetaDiff.Rd index 6c7b9c4d..32c0cb7f 100644 --- a/man/plotBetaDiff.Rd +++ b/man/plotBetaDiff.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/plotBeta.R \name{plotBetaDiff} \alias{plotBetaDiff} -\title{Plot Diff Between two Beta distributions} +\title{Plot difference Between two Beta distributions} \usage{ plotBetaDiff( parY, @@ -35,13 +35,17 @@ a ggplot object This function will plot the PDF of a difference between two Beta distributions } \examples{ -myPlotDiff( - parY = c(5, 10), - parX = c(2, 5), - cut_B = 0.2, # a meaningful improvement threshold - cut_W = 0.05, # a poor improvement threshold - shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no"; - note = 1 -) # show values of the colored area, default: yes. other numbers stands for "no"; +# The beta distribution and acceptable bounds for +# a meaningful improvement of 0.20 and worsening of 0.05 +parX <- c(1, 52) # parameters of experimental arm +parY <- c(5.5, 20.5) # parameters of control or SOC +plotBetaDiff( + parY = parY, + parX = parX, + Go_cut = 0.3, + Stop_cut = 0.1, + shade = TRUE, + note = TRUE +) } \keyword{graphics} From 01b8185ab74e712fb92ab3835d241054a70124d1 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 3 Jan 2025 14:39:38 +0100 Subject: [PATCH 33/35] plot and examples added --- R/plotBeta.R | 12 ++++++------ examples/plotBetaDiff.R | 19 +++++++++++++++---- man/plotBetaDiff.Rd | 19 +++++++++++++++---- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/R/plotBeta.R b/R/plotBeta.R index da475c60..d4d71a77 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -86,14 +86,14 @@ plotBetaDiff <- function(parY, # parameters of experimental arm upper = Stop_cut # Calculate probability of Stop, if difference was at most `Stop_cut`. ) - Go_label <- paste("probability of Go is", round(Go_auc$value * 100, digits = 2), "%") - Stop_label <- paste("probability of Stop is", round(Stop_auc$value * 100, digits = 2), "%") - plot_title <- paste("According to Beta difference density", Go_label, "and\n", Stop_label) + Go_label <- paste("P(Go) is", round(Go_auc$value * 100, digits = 2), "%") + Stop_label <- paste("P(S) is", round(Stop_auc$value * 100, digits = 2), "%") + plot_title <- paste("According to Beta difference density", Go_label, "and", Stop_label) if (shade == TRUE) { pbetadiff_plot <- ggplot2::ggplot(data = data, aes(x = grid, y = density)) + ggplot2::geom_line(colour = "#888888") + - geom_area(data = data[data$grid < Stop_cut,], fill = "#D55E00", + geom_area(data = data[data$grid < Stop_cut,], fill = "#FF0046", mapping = aes(x = ifelse(grid < 0.2 & grid < 0.5, grid, 0))) + geom_area(data = data[data$grid > Go_cut,], fill = "#009E73", mapping = aes(x = ifelse(grid > 0.3, grid, 0))) + @@ -109,8 +109,8 @@ plotBetaDiff <- function(parY, # parameters of experimental arm } if (note == TRUE) { pbetadiff_plot <- pbetadiff_plot + - ggplot2::annotate("text", x = -0.5, y = 4.25, label = Go_label, colour = "#009E73") + - ggplot2::annotate("text", x = -0.5, y = 4.75, label = Stop_label, colour = "#D55E00") + ggplot2::annotate("text", x = -0.5, y = 3.75, size = 5, label = Stop_label, colour = "#FF0046") + + ggplot2::annotate("text", x = -0.5, y = 3.25, size = 5, label = Go_label, colour = "#009E73") } pbetadiff_plot } diff --git a/examples/plotBetaDiff.R b/examples/plotBetaDiff.R index fd8726ec..277e175e 100644 --- a/examples/plotBetaDiff.R +++ b/examples/plotBetaDiff.R @@ -1,12 +1,23 @@ # The beta distribution and acceptable bounds for -# a meaningful improvement of 0.20 and worsening of 0.05 -parX <- c(1, 52) # parameters of experimental arm -parY <- c(5.5, 20.5) # parameters of control or SOC +# a meaningful improvement of 0.20 and worsening of 0.1 +parX <- c(1, 52) # prior parameters of experimental arm +parY <- c(5.5, 20.5) # prior parameters of control or SOC plotBetaDiff( parY = parY, parX = parX, Go_cut = 0.3, - Stop_cut = 0.1, + Stop_cut = 0.1, # below a difference of 10%, is an unsuccesful trial + shade = TRUE, + note = TRUE +) + + +# a larger Go_cut with uniform prior +plotBetaDiff( + parY = c(1, 1), # prior parameters for experimental arm + parX = c(1, 1), # prior parameters for control or SOC arm + Go_cut = 0.3, + Stop_cut = 0.1, # below a difference of 10%, is an unsuccesful trial shade = TRUE, note = TRUE ) diff --git a/man/plotBetaDiff.Rd b/man/plotBetaDiff.Rd index 32c0cb7f..ac715de5 100644 --- a/man/plotBetaDiff.Rd +++ b/man/plotBetaDiff.Rd @@ -36,14 +36,25 @@ This function will plot the PDF of a difference between two Beta distributions } \examples{ # The beta distribution and acceptable bounds for -# a meaningful improvement of 0.20 and worsening of 0.05 -parX <- c(1, 52) # parameters of experimental arm -parY <- c(5.5, 20.5) # parameters of control or SOC +# a meaningful improvement of 0.20 and worsening of 0.1 +parX <- c(1, 52) # prior parameters of experimental arm +parY <- c(5.5, 20.5) # prior parameters of control or SOC plotBetaDiff( parY = parY, parX = parX, Go_cut = 0.3, - Stop_cut = 0.1, + Stop_cut = 0.1, # below a difference of 10\%, is an unsuccesful trial + shade = TRUE, + note = TRUE +) + + +# a larger Go_cut with uniform prior +plotBetaDiff( + parY = c(1, 1), # prior parameters for experimental arm + parX = c(1, 1), # prior parameters for control or SOC arm + Go_cut = 0.3, + Stop_cut = 0.1, # below a difference of 10\%, is an unsuccesful trial shade = TRUE, note = TRUE ) From c475a98d816fa45dda6bddad34a8ab401625671d Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Fri, 3 Jan 2025 14:59:31 +0100 Subject: [PATCH 34/35] for PR review before .svg files for test --- tests/testthat/test-plotBetaDiff.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/testthat/test-plotBetaDiff.R diff --git a/tests/testthat/test-plotBetaDiff.R b/tests/testthat/test-plotBetaDiff.R new file mode 100644 index 00000000..e7c2a091 --- /dev/null +++ b/tests/testthat/test-plotBetaDiff.R @@ -0,0 +1,22 @@ +# plotBetaDiff +test_that("plotBetaDiff works as expected", { + result <- plotBetaDiff( + parY = c(1, 1), + parX = c(6, 10), + Go_cut = 0.3, + Stop_cut = 0.1, # below a difference of 10%, is an unsuccesful trial + shade = TRUE, + note = TRUE + ) + result <- plotBetaDiff( + parY = c(2, 3), + parX = c(4, 10), + Go_cut = 0.3, + Stop_cut = 0.1, # below a difference of 10%, is an unsuccesful trial + shade = TRUE, + note = TRUE + ) + vdiffr::expect_doppelganger("", result) + vdiffr::expect_doppelganger("", result) + +}) From 3a65c36ac6b78e8708c9d19f75947e990d8f40ba Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:24:21 +0000 Subject: [PATCH 35/35] [skip style] [skip vbump] Restyle files --- R/plotBeta.R | 12 ++++++++---- tests/testthat/test-plotBetaDiff.R | 1 - 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/R/plotBeta.R b/R/plotBeta.R index d4d71a77..b51f0370 100644 --- a/R/plotBeta.R +++ b/R/plotBeta.R @@ -93,10 +93,14 @@ plotBetaDiff <- function(parY, # parameters of experimental arm if (shade == TRUE) { pbetadiff_plot <- ggplot2::ggplot(data = data, aes(x = grid, y = density)) + ggplot2::geom_line(colour = "#888888") + - geom_area(data = data[data$grid < Stop_cut,], fill = "#FF0046", - mapping = aes(x = ifelse(grid < 0.2 & grid < 0.5, grid, 0))) + - geom_area(data = data[data$grid > Go_cut,], fill = "#009E73", - mapping = aes(x = ifelse(grid > 0.3, grid, 0))) + + geom_area( + data = data[data$grid < Stop_cut, ], fill = "#FF0046", + mapping = aes(x = ifelse(grid < 0.2 & grid < 0.5, grid, 0)) + ) + + geom_area( + data = data[data$grid > Go_cut, ], fill = "#009E73", + mapping = aes(x = ifelse(grid > 0.3, grid, 0)) + ) + xlab("Difference between treatment") + ggplot2::ylab(quote(f(x))) + ggplot2::ggtitle(plot_title) diff --git a/tests/testthat/test-plotBetaDiff.R b/tests/testthat/test-plotBetaDiff.R index e7c2a091..1ee0a36e 100644 --- a/tests/testthat/test-plotBetaDiff.R +++ b/tests/testthat/test-plotBetaDiff.R @@ -18,5 +18,4 @@ test_that("plotBetaDiff works as expected", { ) vdiffr::expect_doppelganger("", result) vdiffr::expect_doppelganger("", result) - })