From c94e9943f1b2f2ed2ac0cdfcb50c08c373e64123 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 09:48:28 +0100 Subject: [PATCH 01/10] clean --- R/ocPostprobDist.R | 98 +++++++++++++++++++++++++++++++++++++++ man/h_get_decisionDist.Rd | 64 +++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 man/h_get_decisionDist.Rd diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index 160939c7..82d9d1f6 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -1,6 +1,104 @@ #' @include postprobDist.R NULL +#' Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials. +#' +#' The helper function to evaluate generated posteriors and create an "array" +#' or "vector" of decision results based on user defined thresholds. +#' `h_get_decisionDist` was adapted by incorporating `postprobDist()` +#' instead of `postprob()` to evaluate this posterior. +#' The methodology is from Thall & Simon 1994 (Biometrics). +#' +#' @typed nnr : numeric +#' the union of `nnE`and `nnF`. +#' @typed nnrE +#' the result for Efficacy looks with random distance added. +#' @typed nnrF +#' the result for Futility looks with random distance added. +#' @typed truep : number +#' assumed true response rate or true rate (scenario). +#' @typed parE : +#' alpha and beta parameters for the prior on the treatment population. +#' Default set at alpha = 1, beta = 1, or uniform prior. +#' @typed parS : +#' alpha and beta parameters for the prior on the control population. +#' Default set at alpha = 1, beta = 1, or uniform prior. +#' @typed tL : number +#' posterior probability threshold for being below `p0`. +#' @typed tU : number +#' posterior probability threshold for being above `p1`. +#' @typed deltaF : +#' delta for efficacy: `P(P_E > P_S + deltaE)` should be large +#' to stop for efficacy. +#' @typed deltaE : +#' margin by which the response rate in the treatment group should +#' be better than in the standard of care or control or `S` group. +#' @typed relativeDelta : flag +#' If `TRUE`, then a `relativeDelta` is used. Represents that a minimum +#' response rate in magnitude of `delta` of the `S` non-responding patients +#' exists and is used if `TRUE`. +#' See [postprobDist()]. +#' +#' @return A list of the following objects : +#' - `decision` : resulting numeric of decision, one of `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone. +#' - `all_sizes` : resulting numeric of look size, anything below maximum +#' look size is an indicated interim, Futility or Efficacy or both. +#' +#' @keywords internal +#' +h_get_decisionDist <- function(nnr, + nnrE, + nnrF, + truep, + parE = c(1, 1), + parS = c(1, 1), + tL, + tU, + deltaF, + deltaE, + relativeDelta) { + index_look <- 1 + size_look <- nnr[index_look] + all_sizes <- decision <- NA + response <- stats::rbinom(max(nnr), size = 1, truep) + + while (is.na(decision) && index_look <= length(nnr)) { + if (size_look %in% nnrF) { + qL <- postprobDist( + x = 0, + n = 0, + xS = sum(response[1:size_look]), + nS = size_look, + delta = deltaF, + relativeDelta = relativeDelta, + parE = parS, + parS = parE + ) + decision <- ifelse(qL >= tL, FALSE, NA) + } + if (size_look %in% nnrE) { + qU <- postprobDist( + x = sum(response[1:size_look]), + n = size_look, + xS = 0, + nS = 0, + delta = deltaE, + relativeDelta = relativeDelta, + parE = parE, + parS = parS + ) + decision <- ifelse(qU < tU, decision, TRUE) + } + all_sizes <- size_look + index_look <- index_look + 1 + size_look <- nnr[index_look] + } + list( + decision = decision, + all_sizes = all_sizes + ) +} + #' Calculate operating characteristics for posterior probability method #' with beta prior on SOC #' diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd new file mode 100644 index 00000000..7d735338 --- /dev/null +++ b/man/h_get_decisionDist.Rd @@ -0,0 +1,64 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ocPostprobDist.R +\name{h_get_decisionDist} +\alias{h_get_decisionDist} +\title{Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials.} +\usage{ +h_get_decisionDist( + nnr, + nnrE, + nnrF, + truep, + parE = c(1, 1), + parS = c(1, 1), + tL, + tU, + deltaF, + deltaE, + relativeDelta +) +} +\arguments{ +\item{nnr}{(\code{numeric}):\cr the union of \code{nnE}and \code{nnF}.} + +\item{truep}{(\code{number}):\cr assumed true response rate or true rate (scenario).} + +\item{parE}{(``):\cr alpha and beta parameters for the prior on the treatment population. +Default set at alpha = 1, beta = 1, or uniform prior.} + +\item{parS}{(``):\cr alpha and beta parameters for the prior on the control population. +Default set at alpha = 1, beta = 1, or uniform prior.} + +\item{tL}{(\code{number}):\cr posterior probability threshold for being below \code{p0}.} + +\item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} + +\item{deltaF}{(``):\cr delta for efficacy: \code{P(P_E > P_S + deltaE)} should be large +to stop for efficacy.} + +\item{deltaE}{(``):\cr margin by which the response rate in the treatment group should +be better than in the standard of care or control or \code{S} group.} + +\item{relativeDelta}{(\code{flag}):\cr If \code{TRUE}, then a \code{relativeDelta} is used. Represents that a minimum +response rate in magnitude of \code{delta} of the \code{S} non-responding patients +exists and is used if \code{TRUE}. +See \code{\link[=postprobDist]{postprobDist()}}.} + +\item{}{(\if{html}{\out{}}):\cr \if{html}{\out{}}} +} +\value{ +A list of the following objects : +\itemize{ +\item \code{decision} : resulting numeric of decision, one of \code{TRUE} for Go, \code{FALSE} for Stop, \code{NA} for Gray zone. +\item \code{all_sizes} : resulting numeric of look size, anything below maximum +look size is an indicated interim, Futility or Efficacy or both. +} +} +\description{ +The helper function to evaluate generated posteriors and create an "array" +or "vector" of decision results based on user defined thresholds. +\code{h_get_decisionDist} was adapted by incorporating \code{postprobDist()} +instead of \code{postprob()} to evaluate this posterior. +The methodology is from Thall & Simon 1994 (Biometrics). +} +\keyword{internal} From fd8cc200b082e1e9ae631ebf9f3c5ee296ea4041 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 12:57:33 +0100 Subject: [PATCH 02/10] clean --- .gitignore | 3 ++ R/ocPostprobDist.R | 24 ++++++--- man/h_get_decisionDist.Rd | 20 ++++---- tests/testthat/test-ocPostprobDist.R | 73 ++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 tests/testthat/test-ocPostprobDist.R diff --git a/.gitignore b/.gitignore index 94c80c02..3da01702 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,10 @@ vignettes/*.md vignettes/*.R coverage.* .vscode/ +.rds tests/testthat/junit-result.xml tests/unit_testing_results.rds + +tests/testthat/testthat-problems.rds diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index 82d9d1f6..0a383fca 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -1,7 +1,7 @@ #' @include postprobDist.R NULL -#' Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials. +#' Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials #' #' The helper function to evaluate generated posteriors and create an "array" #' or "vector" of decision results based on user defined thresholds. @@ -11,16 +11,16 @@ NULL #' #' @typed nnr : numeric #' the union of `nnE`and `nnF`. -#' @typed nnrE +#' @typed nnrE : numeric #' the result for Efficacy looks with random distance added. -#' @typed nnrF +#' @typed nnrF : numeric #' the result for Futility looks with random distance added. #' @typed truep : number #' assumed true response rate or true rate (scenario). -#' @typed parE : +#' @typed parE : "`numeric` or `matrix`" #' alpha and beta parameters for the prior on the treatment population. #' Default set at alpha = 1, beta = 1, or uniform prior. -#' @typed parS : +#' @typed parS : "`numeric` or `matrix`" #' alpha and beta parameters for the prior on the control population. #' Default set at alpha = 1, beta = 1, or uniform prior. #' @typed tL : number @@ -54,9 +54,21 @@ h_get_decisionDist <- function(nnr, parS = c(1, 1), tL, tU, - deltaF, deltaE, + deltaF, relativeDelta) { + assert_numeric(nnr, finite = TRUE, any.missing = FALSE) + assert_numeric(nnrE, max.len = length(nnr), any.missing = FALSE) + assert_numeric(nnrF, max.len = length(nnr), any.missing = FALSE) + assert_number(truep, lower = 0, upper = 1) + assert_numeric(parE, lower = 0, finite = TRUE, any.missing = FALSE) + assert_numeric(parS, lower = 0, finite = TRUE, any.missing = FALSE) + assert_number(tL, lower = 0, upper = 1) + assert_number(tU, lower = 0, upper = 1) + assert_number(deltaE, lower = 0, upper = 1) + assert_number(deltaF, lower = 0, upper = 1) + assert_flag(relativeDelta) + index_look <- 1 size_look <- nnr[index_look] all_sizes <- decision <- NA diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd index 7d735338..b7535beb 100644 --- a/man/h_get_decisionDist.Rd +++ b/man/h_get_decisionDist.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/ocPostprobDist.R \name{h_get_decisionDist} \alias{h_get_decisionDist} -\title{Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials.} +\title{Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials} \usage{ h_get_decisionDist( nnr, @@ -13,38 +13,40 @@ h_get_decisionDist( parS = c(1, 1), tL, tU, - deltaF, deltaE, + deltaF, relativeDelta ) } \arguments{ \item{nnr}{(\code{numeric}):\cr the union of \code{nnE}and \code{nnF}.} +\item{nnrE}{(\code{numeric}):\cr the result for Efficacy looks with random distance added.} + +\item{nnrF}{(\code{numeric}):\cr the result for Futility looks with random distance added.} + \item{truep}{(\code{number}):\cr assumed true response rate or true rate (scenario).} -\item{parE}{(``):\cr alpha and beta parameters for the prior on the treatment population. +\item{parE}{(\code{numeric} or \code{matrix}):\cr alpha and beta parameters for the prior on the treatment population. Default set at alpha = 1, beta = 1, or uniform prior.} -\item{parS}{(``):\cr alpha and beta parameters for the prior on the control population. +\item{parS}{(\code{numeric} or \code{matrix}):\cr alpha and beta parameters for the prior on the control population. Default set at alpha = 1, beta = 1, or uniform prior.} \item{tL}{(\code{number}):\cr posterior probability threshold for being below \code{p0}.} \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} -\item{deltaF}{(``):\cr delta for efficacy: \code{P(P_E > P_S + deltaE)} should be large -to stop for efficacy.} - \item{deltaE}{(``):\cr margin by which the response rate in the treatment group should be better than in the standard of care or control or \code{S} group.} +\item{deltaF}{(``):\cr delta for efficacy: \code{P(P_E > P_S + deltaE)} should be large +to stop for efficacy.} + \item{relativeDelta}{(\code{flag}):\cr If \code{TRUE}, then a \code{relativeDelta} is used. Represents that a minimum response rate in magnitude of \code{delta} of the \code{S} non-responding patients exists and is used if \code{TRUE}. See \code{\link[=postprobDist]{postprobDist()}}.} - -\item{}{(\if{html}{\out{}}):\cr \if{html}{\out{}}} } \value{ A list of the following objects : diff --git a/tests/testthat/test-ocPostprobDist.R b/tests/testthat/test-ocPostprobDist.R new file mode 100644 index 00000000..003804b3 --- /dev/null +++ b/tests/testthat/test-ocPostprobDist.R @@ -0,0 +1,73 @@ +# h_get_decisionDist ---- +test_that("h_get_decisionDist gives correct result when relativeDelta = TRUE", { + example_dist <- h_get_distance(nn = c(10, 20, 30)) + looks <- h_get_looks(dist = example_dist, nnE = c(10, 20, 30), nnF = c(10, 20, 30)) + looks_nnrE <- looks$nnrE + looks_nnrF <- looks$nnrF + + # input values from above arguments + result <- h_get_decisionDist( + nnr = c(10, 20, 30), + nnrE = looks_nnrE, + nnrF = looks_nnrF, + truep = 0.4, + parE = c(1, 1), + tL = 0.8, + tU = 0.6, + deltaF = 0.1, + deltaE = 0.2, + relativeDelta = TRUE + ) + expect_list(result, any.missing = FALSE) + expect_equal(result$decision, NA) + expect_equal(result$all_sizes, 30) +}) + +test_that("h_get_decisionDist gives correct result relativeDelta = FALSE", { + example_dist <- h_get_distance(nn = c(10, 20, 30)) + looks <- h_get_looks(dist = example_dist, nnE = c(10, 20, 30), nnF = c(10, 20, 30)) + looks_nnrE <- looks$nnrE + looks_nnrF <- looks$nnrF + + # input values from above arguments + result <- h_get_decisionDist( + nnr = c(10, 20, 30), + nnrE = looks_nnrE, + nnrF = looks_nnrF, + truep = 0.4, + parE = c(1, 1), + tL = 0.8, + tU = 0.6, + deltaF = 0.1, + deltaE = 0.2, + relativeDelta = FALSE + ) + expect_list(result, any.missing = FALSE) + expect_equal(result$all_sizes, 30) + expect_equal(result$decision, NA) +}) + + +test_that("h_get_decisionDist gives correct result when nnE nnF", { + example_dist <- h_get_distance(nn = c(10, 20, 30)) + looks <- h_get_looks(dist = example_dist, nnE = c(10, 20, 30), nnF = c(10, 20)) + looks_nnrE <- looks$nnrE + looks_nnrF <- looks$nnrF + + # input values from above arguments + result <- h_get_decisionDist( + nnr = c(10, 20, 30), + nnrE = looks_nnrE, + nnrF = looks_nnrF, + truep = 0.4, + parE = c(1, 1), + tL = 0.8, + tU = 0.6, + deltaF = 0.1, + deltaE = 0.2, + relativeDelta = FALSE + ) + expect_list(result, any.missing = FALSE) + expect_equal(result$decision, NA) + expect_equal(result$all_sizes, 30) +}) From 426d18031c1c4b232e0af6bdc093152ef3189a46 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 13:32:17 +0100 Subject: [PATCH 03/10] clean --- R/ocPostprob.R | 6 ++--- R/ocPostprobDist.R | 45 +++++++------------------------- man/h_get_decision.Rd | 6 ++--- man/h_get_decisionDist.Rd | 39 +++++++++------------------ man/ocPostprob.Rd | 2 +- tests/testthat/test-ocPostprob.R | 5 ++-- 6 files changed, 31 insertions(+), 72 deletions(-) diff --git a/R/ocPostprob.R b/R/ocPostprob.R index 24d52df2..3e3eb900 100644 --- a/R/ocPostprob.R +++ b/R/ocPostprob.R @@ -75,12 +75,12 @@ h_get_looks <- function(dist, nnE, nnF) { #' @typed tU : number #' posterior probability threshold for being above `p1`. #' @typed parE : numeric -#' alpha and beta parameters for the prior on the treatment proportion. +#' alpha and beta parameters for the prior on the treatment population. #' Default set at alpha = 1, beta = 1, or uniform prior. #' #' @return A list of the following objects : -#' - `decision` : resulting numeric of decision, one of `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone. -#' - `all_sizes` : resulting numeric of look size, anything below maximum +#' - `decision` : resulting vector of decision, one of `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone. +#' - `all_sizes` : resulting number of look size, anything below maximum #' look size is an indicated interim, Futility or Efficacy or both. #' #' @keywords internal diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index 0a383fca..0838133c 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -1,48 +1,21 @@ #' @include postprobDist.R NULL -#' Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials +#' Evaluate Posteriors based on Efficacy and Futility thresholds in Two-armed trials #' -#' The helper function to evaluate generated posteriors and create an "array" -#' or "vector" of decision results based on user defined thresholds. -#' `h_get_decisionDist` was adapted by incorporating `postprobDist()` -#' instead of `postprob()` to evaluate this posterior. -#' The methodology is from Thall & Simon 1994 (Biometrics). +#' A helper function adapted from `h_get_decision()` from `ocPostprob.R` by +#' replacing the internal use of `postprob()` with `postprobDist()` +#' to generate numeric of `decisions` and random looks `all_sizes`. #' -#' @typed nnr : numeric -#' the union of `nnE`and `nnF`. -#' @typed nnrE : numeric -#' the result for Efficacy looks with random distance added. -#' @typed nnrF : numeric -#' the result for Futility looks with random distance added. -#' @typed truep : number -#' assumed true response rate or true rate (scenario). -#' @typed parE : "`numeric` or `matrix`" -#' alpha and beta parameters for the prior on the treatment population. -#' Default set at alpha = 1, beta = 1, or uniform prior. -#' @typed parS : "`numeric` or `matrix`" -#' alpha and beta parameters for the prior on the control population. -#' Default set at alpha = 1, beta = 1, or uniform prior. -#' @typed tL : number -#' posterior probability threshold for being below `p0`. -#' @typed tU : number -#' posterior probability threshold for being above `p1`. -#' @typed deltaF : +#' +#' @inheritParams h_get_decision +#' @inheritParams postprobDist +#' @typed deltaF : number #' delta for efficacy: `P(P_E > P_S + deltaE)` should be large #' to stop for efficacy. -#' @typed deltaE : +#' @typed deltaE : number #' margin by which the response rate in the treatment group should #' be better than in the standard of care or control or `S` group. -#' @typed relativeDelta : flag -#' If `TRUE`, then a `relativeDelta` is used. Represents that a minimum -#' response rate in magnitude of `delta` of the `S` non-responding patients -#' exists and is used if `TRUE`. -#' See [postprobDist()]. -#' -#' @return A list of the following objects : -#' - `decision` : resulting numeric of decision, one of `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone. -#' - `all_sizes` : resulting numeric of look size, anything below maximum -#' look size is an indicated interim, Futility or Efficacy or both. #' #' @keywords internal #' diff --git a/man/h_get_decision.Rd b/man/h_get_decision.Rd index 3acdb5de..2c4bf6fa 100644 --- a/man/h_get_decision.Rd +++ b/man/h_get_decision.Rd @@ -15,7 +15,7 @@ h_get_decision(nnr, truep, p0, p1, parE = c(1, 1), nnE, nnF, tL, tU) \item{p1}{(\code{number}):\cr upper Efficacy threshold of response rate.} -\item{parE}{(\code{numeric}):\cr alpha and beta parameters for the prior on the treatment proportion. +\item{parE}{(\code{numeric}):\cr alpha and beta parameters for the prior on the treatment population. Default set at alpha = 1, beta = 1, or uniform prior.} \item{nnE}{(\code{numeric}):\cr sample size or sizes where study can be stopped for Efficacy decision. If different for Futility decision, @@ -30,8 +30,8 @@ specify in \code{nnF}.} \value{ A list of the following objects : \itemize{ -\item \code{decision} : resulting numeric of decision, one of \code{TRUE} for Go, \code{FALSE} for Stop, \code{NA} for Gray zone. -\item \code{all_sizes} : resulting numeric of look size, anything below maximum +\item \code{decision} : resulting vector of decision, one of \code{TRUE} for Go, \code{FALSE} for Stop, \code{NA} for Gray zone. +\item \code{all_sizes} : resulting number of look size, anything below maximum look size is an indicated interim, Futility or Efficacy or both. } } diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd index b7535beb..48f17b87 100644 --- a/man/h_get_decisionDist.Rd +++ b/man/h_get_decisionDist.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/ocPostprobDist.R \name{h_get_decisionDist} \alias{h_get_decisionDist} -\title{Evaluate posteriors based on Efficacy and Futility thresholds in two-armed trials} +\title{Evaluate Posteriors based on Efficacy and Futility thresholds in Two-armed trials} \usage{ h_get_decisionDist( nnr, @@ -19,48 +19,33 @@ h_get_decisionDist( ) } \arguments{ -\item{nnr}{(\code{numeric}):\cr the union of \code{nnE}and \code{nnF}.} - -\item{nnrE}{(\code{numeric}):\cr the result for Efficacy looks with random distance added.} - -\item{nnrF}{(\code{numeric}):\cr the result for Futility looks with random distance added.} +\item{nnr}{(\code{numeric}):\cr union of \code{nnE}and \code{nnF}.} \item{truep}{(\code{number}):\cr assumed true response rate or true rate (scenario).} -\item{parE}{(\code{numeric} or \code{matrix}):\cr alpha and beta parameters for the prior on the treatment population. +\item{parE}{(\code{numeric}):\cr alpha and beta parameters for the prior on the treatment population. Default set at alpha = 1, beta = 1, or uniform prior.} -\item{parS}{(\code{numeric} or \code{matrix}):\cr alpha and beta parameters for the prior on the control population. -Default set at alpha = 1, beta = 1, or uniform prior.} +\item{parS}{(\code{numeric} or \code{matrix}):\cr parameters for beta distribution. If it is a matrix, it needs to have 2 columns, +and each row corresponds to each component of a beta-mixture distribution +for the \code{S} group. See details.} \item{tL}{(\code{number}):\cr posterior probability threshold for being below \code{p0}.} \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} -\item{deltaE}{(``):\cr margin by which the response rate in the treatment group should +\item{deltaE}{(\code{number}):\cr margin by which the response rate in the treatment group should be better than in the standard of care or control or \code{S} group.} -\item{deltaF}{(``):\cr delta for efficacy: \code{P(P_E > P_S + deltaE)} should be large +\item{deltaF}{(\code{number}):\cr delta for efficacy: \code{P(P_E > P_S + deltaE)} should be large to stop for efficacy.} \item{relativeDelta}{(\code{flag}):\cr If \code{TRUE}, then a \code{relativeDelta} is used. Represents that a minimum -response rate in magnitude of \code{delta} of the \code{S} non-responding patients -exists and is used if \code{TRUE}. -See \code{\link[=postprobDist]{postprobDist()}}.} -} -\value{ -A list of the following objects : -\itemize{ -\item \code{decision} : resulting numeric of decision, one of \code{TRUE} for Go, \code{FALSE} for Stop, \code{NA} for Gray zone. -\item \code{all_sizes} : resulting numeric of look size, anything below maximum -look size is an indicated interim, Futility or Efficacy or both. -} +response rate in magnitude of \code{delta} of the \code{S} non-responding patients. See note.} } \description{ -The helper function to evaluate generated posteriors and create an "array" -or "vector" of decision results based on user defined thresholds. -\code{h_get_decisionDist} was adapted by incorporating \code{postprobDist()} -instead of \code{postprob()} to evaluate this posterior. -The methodology is from Thall & Simon 1994 (Biometrics). +A helper function adapted from \code{h_get_decision()} from \code{ocPostprob.R} by +replacing the internal use of \code{postprob()} with \code{postprobDist()} +to generate numeric of \code{decisions} and random looks \code{all_sizes}. } \keyword{internal} diff --git a/man/ocPostprob.Rd b/man/ocPostprob.Rd index 7633070d..4d2affbb 100644 --- a/man/ocPostprob.Rd +++ b/man/ocPostprob.Rd @@ -32,7 +32,7 @@ specify in \code{nnF}.} \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} -\item{parE}{(\code{numeric}):\cr alpha and beta parameters for the prior on the treatment proportion. +\item{parE}{(\code{numeric}):\cr alpha and beta parameters for the prior on the treatment population. Default set at alpha = 1, beta = 1, or uniform prior.} \item{sim}{(\code{number}):\cr number of simulations.} diff --git a/tests/testthat/test-ocPostprob.R b/tests/testthat/test-ocPostprob.R index c57b70d1..81cf6c5f 100644 --- a/tests/testthat/test-ocPostprob.R +++ b/tests/testthat/test-ocPostprob.R @@ -30,7 +30,7 @@ test_that("h_get_looks gives correct results if input is identical", { # h_get_decision ---- test_that("get_decision will give GO decision in favourable conditions", { - tmp <- h_get_decision( + result <- h_get_decision( nnr = c(10, 20, 30), truep = 0.5, # Go criteria is P_E(p > p1) > tU, where P_E(truep > 0.30) > 0.2 @@ -42,7 +42,8 @@ test_that("get_decision will give GO decision in favourable conditions", { nnE = c(10, 20, 30), nnF = c(10, 20, 30) ) - expect_equal(tmp$decision, TRUE) + expect_equal(result$decision, TRUE) + expect_equal(result$all_sizes, 10) }) # h_get_oc ---- From edc4be15e5ce38d6a0294c65ef229bb91ebd9336 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 13:57:44 +0100 Subject: [PATCH 04/10] clean --- R/ocPostprobDist.R | 33 ++++++++++++++++++++++++++++----- R/postprobDist.R | 3 ++- man/h_get_decisionDist.Rd | 34 +++++++++++++++++++++++++++++----- man/postprobDist.Rd | 3 ++- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index 0838133c..a41209a7 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -10,12 +10,35 @@ NULL #' #' @inheritParams h_get_decision #' @inheritParams postprobDist -#' @typed deltaF : number -#' delta for efficacy: `P(P_E > P_S + deltaE)` should be large -#' to stop for efficacy. #' @typed deltaE : number -#' margin by which the response rate in the treatment group should -#' be better than in the standard of care or control or `S` group. +#' margin by which the response rate in the treatment group should be better +#' than in the standard of care of `group`. Delta for efficacy is used to +#' calculate `P(P_E > P_S + deltaE)` which should +#' exceed threshold `tU` to to stop for efficacy. +#' Note that this can also be negative, e.g. when non-inferiority is being assessed. +#' @typed deltaF : number +#' margin by which the response rate in the treatment group should be better +#' than in the standard of care of `group`. Delta for futility is used to +#' calculate `P(P_E > P_S + deltaS)` which should +#' exceed threshold `tL` to stop for futility. +#' Note that this can also be negative, e.g. when non-inferiority is being assessed. +#' +#' @note +#' +#' ## Delta : +#' +#' The desired improvement is denoted as `delta`. There are two options in using `delta`. +#' The absolute case when `relativeDelta = FALSE` and relative as when `relativeDelta = TRUE`. +#' +#' 1. The absolute case is when we define an absolute delta, greater than `P_S`, +#' the response rate of the standard of care or control or `S` group such that +#' the posterior is `Pr(P_E > P_S + deltaE | data)` for efficacy looks +#' or `Pr(P_E > P_S + deltaF | data)` for futility looks. +#' +#' 2. In the relative case, we suppose that the treatment group's +#' response rate is assumed to be greater than `P_S + (1-P_S) * delta` such that +#' the posterior is `Pr(P_E > P_S + (1 - P_S) * deltaE | data)` for efficacy looks +#' or `Pr(P_E > P_S + (1 - P_S) * deltaF | data)` for futility looks. #' #' @keywords internal #' diff --git a/R/postprobDist.R b/R/postprobDist.R index 22dc6aa5..8aa2af4e 100644 --- a/R/postprobDist.R +++ b/R/postprobDist.R @@ -102,7 +102,8 @@ h_get_bounds <- function(controlBetamixPost) { #' number of patients in the `S` group. #' @typed relativeDelta : flag #' If `TRUE`, then a `relativeDelta` is used. Represents that a minimum -#' response rate in magnitude of `delta` of the `S` non-responding patients. See note. +#' response rate in magnitude of `delta` of the `S` non-responding patients +#' is included as the margin between treatment and control group. See note. #' @typed parE : "`numeric` or `matrix`" #' parameters for beta distribution. If it is a matrix, it needs to have 2 columns, #' and each row corresponds to each component of a beta-mixture distribution diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd index 48f17b87..30998060 100644 --- a/man/h_get_decisionDist.Rd +++ b/man/h_get_decisionDist.Rd @@ -34,18 +34,42 @@ for the \code{S} group. See details.} \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} -\item{deltaE}{(\code{number}):\cr margin by which the response rate in the treatment group should -be better than in the standard of care or control or \code{S} group.} +\item{deltaE}{(\code{number}):\cr margin by which the response rate in the treatment group should be better +than in the standard of care of \code{group}. Delta for efficacy is used to +calculate \code{P(P_E > P_S + deltaE)} which should +exceed threshold \code{tU} to to stop for efficacy. +Note that this can also be negative, e.g. when non-inferiority is being assessed.} -\item{deltaF}{(\code{number}):\cr delta for efficacy: \code{P(P_E > P_S + deltaE)} should be large -to stop for efficacy.} +\item{deltaF}{(\code{number}):\cr margin by which the response rate in the treatment group should be better +than in the standard of care of \code{group}. Delta for futility is used to +calculate \code{P(P_E > P_S + deltaS)} which should +exceed threshold \code{tL} to stop for futility. +Note that this can also be negative, e.g. when non-inferiority is being assessed.} \item{relativeDelta}{(\code{flag}):\cr If \code{TRUE}, then a \code{relativeDelta} is used. Represents that a minimum -response rate in magnitude of \code{delta} of the \code{S} non-responding patients. See note.} +response rate in magnitude of \code{delta} of the \code{S} non-responding patients +is included as the margin between treatment and control group. See note.} } \description{ A helper function adapted from \code{h_get_decision()} from \code{ocPostprob.R} by replacing the internal use of \code{postprob()} with \code{postprobDist()} to generate numeric of \code{decisions} and random looks \code{all_sizes}. } +\note{ +\subsection{Delta :}{ + +The desired improvement is denoted as \code{delta}. There are two options in using \code{delta}. +The absolute case when \code{relativeDelta = FALSE} and relative as when \code{relativeDelta = TRUE}. +\enumerate{ +\item The absolute case is when we define an absolute delta, greater than \code{P_S}, +the response rate of the standard of care or control or \code{S} group such that +the posterior is \code{Pr(P_E > P_S + deltaE | data)} for efficacy looks +or \code{Pr(P_E > P_S + deltaF | data)} for futility looks. +\item In the relative case, we suppose that the treatment group's +response rate is assumed to be greater than \code{P_S + (1-P_S) * delta} such that +the posterior is \code{Pr(P_E > P_S + (1 - P_S) * deltaE | data)} for efficacy looks +or \code{Pr(P_E > P_S + (1 - P_S) * deltaF | data)} for futility looks. +} +} +} \keyword{internal} diff --git a/man/postprobDist.Rd b/man/postprobDist.Rd index 9eb8653b..ebeefd3a 100644 --- a/man/postprobDist.Rd +++ b/man/postprobDist.Rd @@ -31,7 +31,8 @@ be better than in the standard of care or control or \code{S} group. Note that this can also be negative, e.g. when non-inferiority is being assessed.} \item{relativeDelta}{(\code{flag}):\cr If \code{TRUE}, then a \code{relativeDelta} is used. Represents that a minimum -response rate in magnitude of \code{delta} of the \code{S} non-responding patients. See note.} +response rate in magnitude of \code{delta} of the \code{S} non-responding patients +is included as the margin between treatment and control group. See note.} \item{parE}{(\code{numeric} or \code{matrix}):\cr parameters for beta distribution. If it is a matrix, it needs to have 2 columns, and each row corresponds to each component of a beta-mixture distribution From b40bd94bdcbf3120bc81b5db0133b692a2d1cc09 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 14:42:42 +0100 Subject: [PATCH 05/10] Update R/ocPostprobDist.R Co-authored-by: Daniel Sabanes Bove --- R/ocPostprobDist.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index a41209a7..ceef6a50 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -3,9 +3,9 @@ NULL #' Evaluate Posteriors based on Efficacy and Futility thresholds in Two-armed trials #' -#' A helper function adapted from `h_get_decision()` from `ocPostprob.R` by -#' replacing the internal use of `postprob()` with `postprobDist()` -#' to generate numeric of `decisions` and random looks `all_sizes`. +#' A helper function adapted from [h_get_decision()] by +#' replacing the internal use of [postprob()] with [postprobDist()] +#' to generate the `decision` and random looks `all_sizes`. #' #' #' @inheritParams h_get_decision From 3cd77032a5cdbf8d3e5c741c11b9ee9ef83b75b2 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 14:43:58 +0100 Subject: [PATCH 06/10] clean --- R/ocPostprob.R | 2 +- R/ocPostprobDist.R | 2 +- man/h_get_decision.Rd | 2 +- man/h_get_decisionDist.Rd | 2 +- tests/testthat/test-betadiff.R | 2 +- tests/testthat/test-ocPostprob.R | 3 +++ 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/R/ocPostprob.R b/R/ocPostprob.R index 3e3eb900..d2b7a338 100644 --- a/R/ocPostprob.R +++ b/R/ocPostprob.R @@ -79,7 +79,7 @@ h_get_looks <- function(dist, nnE, nnF) { #' Default set at alpha = 1, beta = 1, or uniform prior. #' #' @return A list of the following objects : -#' - `decision` : resulting vector of decision, one of `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone. +#' - `decision` : decision `flag` with `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone. #' - `all_sizes` : resulting number of look size, anything below maximum #' look size is an indicated interim, Futility or Efficacy or both. #' diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index a41209a7..ed155304 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -1,7 +1,7 @@ #' @include postprobDist.R NULL -#' Evaluate Posteriors based on Efficacy and Futility thresholds in Two-armed trials +#' Evaluate Posteriors based on Efficacy and Futility Thresholds in Two-Armed trials #' #' A helper function adapted from `h_get_decision()` from `ocPostprob.R` by #' replacing the internal use of `postprob()` with `postprobDist()` diff --git a/man/h_get_decision.Rd b/man/h_get_decision.Rd index 2c4bf6fa..479fe8ae 100644 --- a/man/h_get_decision.Rd +++ b/man/h_get_decision.Rd @@ -30,7 +30,7 @@ specify in \code{nnF}.} \value{ A list of the following objects : \itemize{ -\item \code{decision} : resulting vector of decision, one of \code{TRUE} for Go, \code{FALSE} for Stop, \code{NA} for Gray zone. +\item \code{decision} : decision \code{flag} with \code{TRUE} for Go, \code{FALSE} for Stop, \code{NA} for Gray zone. \item \code{all_sizes} : resulting number of look size, anything below maximum look size is an indicated interim, Futility or Efficacy or both. } diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd index 30998060..0e162910 100644 --- a/man/h_get_decisionDist.Rd +++ b/man/h_get_decisionDist.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/ocPostprobDist.R \name{h_get_decisionDist} \alias{h_get_decisionDist} -\title{Evaluate Posteriors based on Efficacy and Futility thresholds in Two-armed trials} +\title{Evaluate Posteriors based on Efficacy and Futility Thresholds in Two-Armed trials} \usage{ h_get_decisionDist( nnr, diff --git a/tests/testthat/test-betadiff.R b/tests/testthat/test-betadiff.R index d412ad04..34cedabd 100644 --- a/tests/testthat/test-betadiff.R +++ b/tests/testthat/test-betadiff.R @@ -17,7 +17,7 @@ test_that("Monte Carlo result converges to Go probability", { upper = 1 ) expected <- mean(rbeta(n = 1e6, parY[1], parY[2]) - rbeta(n = 1e6, parX[1], parX[2]) > 0.15) - expect_equal(results$value, expected, tolerance = 1e-3) + expect_equal(results$value, expected, tolerance = 1e-9) }) test_that("Monte Carlo result converges to Stop probability", { diff --git a/tests/testthat/test-ocPostprob.R b/tests/testthat/test-ocPostprob.R index 81cf6c5f..67432ca2 100644 --- a/tests/testthat/test-ocPostprob.R +++ b/tests/testthat/test-ocPostprob.R @@ -30,6 +30,7 @@ test_that("h_get_looks gives correct results if input is identical", { # h_get_decision ---- test_that("get_decision will give GO decision in favourable conditions", { + set.seed(1989) result <- h_get_decision( nnr = c(10, 20, 30), truep = 0.5, @@ -48,6 +49,7 @@ test_that("get_decision will give GO decision in favourable conditions", { # h_get_oc ---- test_that("the probability results of get_oc are less than 1", { + set.seed(1989) oc <- h_get_oc( all_sizes = sample(c(11, 14, 20), size = 10000, replace = TRUE), decision = sample(c(NA, TRUE, FALSE), size = 10000, replace = TRUE), @@ -58,6 +60,7 @@ test_that("the probability results of get_oc are less than 1", { }) test_that("the ExpectedN is within range based on vector of looks", { + set.seed(1989) all_sizes <- sample(c(11, 14, 20), size = 10000, replace = TRUE) oc <- h_get_oc( all_sizes = all_sizes, From c12a191ab3d95a388f2d73053ba5bcb9d6f37d65 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 14:50:36 +0100 Subject: [PATCH 07/10] clean --- R/ocPostprobDist.R | 18 ------------------ man/h_get_decisionDist.Rd | 23 +++-------------------- 2 files changed, 3 insertions(+), 38 deletions(-) diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index bd40c1df..eccc619d 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -7,7 +7,6 @@ NULL #' replacing the internal use of [postprob()] with [postprobDist()] #' to generate the `decision` and random looks `all_sizes`. #' -#' #' @inheritParams h_get_decision #' @inheritParams postprobDist #' @typed deltaE : number @@ -23,23 +22,6 @@ NULL #' exceed threshold `tL` to stop for futility. #' Note that this can also be negative, e.g. when non-inferiority is being assessed. #' -#' @note -#' -#' ## Delta : -#' -#' The desired improvement is denoted as `delta`. There are two options in using `delta`. -#' The absolute case when `relativeDelta = FALSE` and relative as when `relativeDelta = TRUE`. -#' -#' 1. The absolute case is when we define an absolute delta, greater than `P_S`, -#' the response rate of the standard of care or control or `S` group such that -#' the posterior is `Pr(P_E > P_S + deltaE | data)` for efficacy looks -#' or `Pr(P_E > P_S + deltaF | data)` for futility looks. -#' -#' 2. In the relative case, we suppose that the treatment group's -#' response rate is assumed to be greater than `P_S + (1-P_S) * delta` such that -#' the posterior is `Pr(P_E > P_S + (1 - P_S) * deltaE | data)` for efficacy looks -#' or `Pr(P_E > P_S + (1 - P_S) * deltaF | data)` for futility looks. -#' #' @keywords internal #' h_get_decisionDist <- function(nnr, diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd index 0e162910..d6f94834 100644 --- a/man/h_get_decisionDist.Rd +++ b/man/h_get_decisionDist.Rd @@ -51,25 +51,8 @@ response rate in magnitude of \code{delta} of the \code{S} non-responding patien is included as the margin between treatment and control group. See note.} } \description{ -A helper function adapted from \code{h_get_decision()} from \code{ocPostprob.R} by -replacing the internal use of \code{postprob()} with \code{postprobDist()} -to generate numeric of \code{decisions} and random looks \code{all_sizes}. -} -\note{ -\subsection{Delta :}{ - -The desired improvement is denoted as \code{delta}. There are two options in using \code{delta}. -The absolute case when \code{relativeDelta = FALSE} and relative as when \code{relativeDelta = TRUE}. -\enumerate{ -\item The absolute case is when we define an absolute delta, greater than \code{P_S}, -the response rate of the standard of care or control or \code{S} group such that -the posterior is \code{Pr(P_E > P_S + deltaE | data)} for efficacy looks -or \code{Pr(P_E > P_S + deltaF | data)} for futility looks. -\item In the relative case, we suppose that the treatment group's -response rate is assumed to be greater than \code{P_S + (1-P_S) * delta} such that -the posterior is \code{Pr(P_E > P_S + (1 - P_S) * deltaE | data)} for efficacy looks -or \code{Pr(P_E > P_S + (1 - P_S) * deltaF | data)} for futility looks. -} -} +A helper function adapted from \code{\link[=h_get_decision]{h_get_decision()}} by +replacing the internal use of \code{\link[=postprob]{postprob()}} with \code{\link[=postprobDist]{postprobDist()}} +to generate the \code{decision} and random looks \code{all_sizes}. } \keyword{internal} From 82d390627fbdf212c436e8d8d27ec4955a317967 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 14:56:13 +0100 Subject: [PATCH 08/10] clean --- R/ocPostprobDist.R | 10 ++-------- man/h_get_decisionDist.Rd | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/R/ocPostprobDist.R b/R/ocPostprobDist.R index eccc619d..06513229 100644 --- a/R/ocPostprobDist.R +++ b/R/ocPostprobDist.R @@ -11,16 +11,10 @@ NULL #' @inheritParams postprobDist #' @typed deltaE : number #' margin by which the response rate in the treatment group should be better -#' than in the standard of care of `group`. Delta for efficacy is used to -#' calculate `P(P_E > P_S + deltaE)` which should -#' exceed threshold `tU` to to stop for efficacy. -#' Note that this can also be negative, e.g. when non-inferiority is being assessed. +#' than in the standard of care of `group` in efficacy looks. #' @typed deltaF : number #' margin by which the response rate in the treatment group should be better -#' than in the standard of care of `group`. Delta for futility is used to -#' calculate `P(P_E > P_S + deltaS)` which should -#' exceed threshold `tL` to stop for futility. -#' Note that this can also be negative, e.g. when non-inferiority is being assessed. +#' than in the standard of care of `group` in futility looks. #' #' @keywords internal #' diff --git a/man/h_get_decisionDist.Rd b/man/h_get_decisionDist.Rd index d6f94834..e854d346 100644 --- a/man/h_get_decisionDist.Rd +++ b/man/h_get_decisionDist.Rd @@ -35,16 +35,10 @@ for the \code{S} group. See details.} \item{tU}{(\code{number}):\cr posterior probability threshold for being above \code{p1}.} \item{deltaE}{(\code{number}):\cr margin by which the response rate in the treatment group should be better -than in the standard of care of \code{group}. Delta for efficacy is used to -calculate \code{P(P_E > P_S + deltaE)} which should -exceed threshold \code{tU} to to stop for efficacy. -Note that this can also be negative, e.g. when non-inferiority is being assessed.} +than in the standard of care of \code{group} in efficacy looks.} \item{deltaF}{(\code{number}):\cr margin by which the response rate in the treatment group should be better -than in the standard of care of \code{group}. Delta for futility is used to -calculate \code{P(P_E > P_S + deltaS)} which should -exceed threshold \code{tL} to stop for futility. -Note that this can also be negative, e.g. when non-inferiority is being assessed.} +than in the standard of care of \code{group} in futility looks.} \item{relativeDelta}{(\code{flag}):\cr If \code{TRUE}, then a \code{relativeDelta} is used. Represents that a minimum response rate in magnitude of \code{delta} of the \code{S} non-responding patients From 1faee8d655f8f05b4e43eefd7e08b541e4c1c122 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 15:10:36 +0100 Subject: [PATCH 09/10] set other seeds --- tests/testthat/test-ocPostprobDist.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testthat/test-ocPostprobDist.R b/tests/testthat/test-ocPostprobDist.R index 003804b3..1b2ee8c2 100644 --- a/tests/testthat/test-ocPostprobDist.R +++ b/tests/testthat/test-ocPostprobDist.R @@ -1,5 +1,6 @@ # h_get_decisionDist ---- test_that("h_get_decisionDist gives correct result when relativeDelta = TRUE", { + set.seed(1989) example_dist <- h_get_distance(nn = c(10, 20, 30)) looks <- h_get_looks(dist = example_dist, nnE = c(10, 20, 30), nnF = c(10, 20, 30)) looks_nnrE <- looks$nnrE @@ -24,6 +25,7 @@ test_that("h_get_decisionDist gives correct result when relativeDelta = TRUE", { }) test_that("h_get_decisionDist gives correct result relativeDelta = FALSE", { + set.seed(1989) example_dist <- h_get_distance(nn = c(10, 20, 30)) looks <- h_get_looks(dist = example_dist, nnE = c(10, 20, 30), nnF = c(10, 20, 30)) looks_nnrE <- looks$nnrE @@ -49,6 +51,7 @@ test_that("h_get_decisionDist gives correct result relativeDelta = FALSE", { test_that("h_get_decisionDist gives correct result when nnE nnF", { + set.seed(1989) example_dist <- h_get_distance(nn = c(10, 20, 30)) looks <- h_get_looks(dist = example_dist, nnE = c(10, 20, 30), nnF = c(10, 20)) looks_nnrE <- looks$nnrE From dee7c07a83ab5c7ac0065341de6faa8684492474 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 2 Jan 2024 15:13:41 +0100 Subject: [PATCH 10/10] set other seeds --- tests/testthat/test-betadiff.R | 4 +++- tests/testthat/test-ocPostprob.R | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-betadiff.R b/tests/testthat/test-betadiff.R index 34cedabd..33b80346 100644 --- a/tests/testthat/test-betadiff.R +++ b/tests/testthat/test-betadiff.R @@ -9,6 +9,7 @@ test_that("dbetadiff gives error with empty numeric for z", { }) test_that("Monte Carlo result converges to Go probability", { + set.seed(1989) results <- integrate( f = dbetadiff, parY = parY, @@ -17,10 +18,11 @@ test_that("Monte Carlo result converges to Go probability", { upper = 1 ) expected <- mean(rbeta(n = 1e6, parY[1], parY[2]) - rbeta(n = 1e6, parX[1], parX[2]) > 0.15) - expect_equal(results$value, expected, tolerance = 1e-9) + expect_equal(results$value, expected, tolerance = 1e-4) }) test_that("Monte Carlo result converges to Stop probability", { + set.seed(1989) results <- integrate( f = dbetadiff, parY = parY, diff --git a/tests/testthat/test-ocPostprob.R b/tests/testthat/test-ocPostprob.R index 67432ca2..9c6f1c3c 100644 --- a/tests/testthat/test-ocPostprob.R +++ b/tests/testthat/test-ocPostprob.R @@ -44,7 +44,7 @@ test_that("get_decision will give GO decision in favourable conditions", { nnF = c(10, 20, 30) ) expect_equal(result$decision, TRUE) - expect_equal(result$all_sizes, 10) + expect_equal(result$all_sizes, 20) }) # h_get_oc ----