Skip to content

Commit

Permalink
fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyyeoCH committed Oct 10, 2024
2 parents d9cc2e3 + 945a2b9 commit 73b3d65
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 88 deletions.
53 changes: 27 additions & 26 deletions R/boundsPredprob.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
#' @inheritParams predprob
#' @inheritParams ocPredprob
#' @inheritParams boundsPostprob
#' @return A matrix for each same size in `nvec`. For each sample size, the following is returned:
#' @return A matrix for each same size in `looks`. For each sample size, the following is returned:
#' - `xL` : the maximum number of responses that meet the futility.
#' threshold
#' - `pL` : response rate corresponding to `xL`.
#' - `ppL` : predictive probability corresponding to `xL`
#' - `predL` : predictive probability corresponding to `xL`
#' - `postL`: posterior probability corresponding to `xL`.
#' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an
#' exact binomial test.
#' - `xU` : the minimal number of responses that meet the efficacy threshold.
#' - `pU` : response rate corresponding to `xU`.
#' - `predU` : predictive probability corresponding to `xU`
#' - `postL`: posterior probability corresponding to `xU`.
#' - `ppU` : predictive probability corresponding to `xU`
#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact
#' binomial test.
#'
Expand All @@ -30,29 +30,32 @@
#' @example examples/boundsPredprob.R
#' @export
#' @keywords graphics
boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) {
boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = c(1, 1), weights) {
assert_numeric(looks)
assert_number(p0, lower = 0, upper = 1)
assert_number(tT, lower = 0, upper = 1)
assert_numeric(parE, min.len = 2, any.missing = FALSE)
znames <- c(
"xL", "pL", "ppL", "postL", "UciL",
"xU", "pU", "ppU", "postU", "LciU"
"xL", "pL", "predL", "postL", "UciL",
"xU", "pU", "predU", "postU", "LciU"
)
z <- matrix(NA, length(nvec), length(znames))
dimnames(z) <- list(nvec, znames)
z <- matrix(NA, length(looks), length(znames))
dimnames(z) <- list(looks, znames)
k <- 0
for (n in nvec) {
for (n in looks) {
k <- k + 1
# initialize so will return NA if 0 or n in "continue" region
xL <- NA
xU <- NA
for (x in 0:n) {
pp <- predprob(x, n, Nmax, p0, tT, parE = c(a, b))$result
if (pp <= phiL) {
predprob <- predprob(x = x, n = n, Nmax = max(looks), p = p0, thetaT = tT, parE = parE, weights = weights)$result
if (predprob <= phiL) { # Futility look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL
xL <- x
ppL <- pp
predL <- predprob
}
if (pp >= phiU) {
if (predprob >= phiU) { # Efficacy look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU,
xU <- x
ppU <- ppL
# done: leave innermost for loop
predU <- predprob
break
}
}
Expand All @@ -61,25 +64,23 @@ boundsPredprob <- function(nvec, Nmax = max(nvec), p0, tT, phiL, phiU, a, b) {
xU <- NA
}
# calculate predictive and posterior probabilities at boundaries
ppL <- predprob(xL, n, Nmax, p0, tT, parE = c(a, b))$result
ppU <- predprob(xU, n, Nmax, p0, tT, parE = c(a, b))$result
postL <- postprob(xL, n, p0, parE = c(a, b))
postU <- postprob(xU, n, p0, parE = c(a, b))
postL <- postprob(xL, n, p0, parE = parE)
postU <- postprob(xU, n, p0, parE = parE)
# calculate lower CI at boundaries
UciL <- ifelse(!is.na(xL), stats::binom.test(xL, n, alt = "less")$conf.int[2], NA)
LciU <- ifelse(!is.na(xU), stats::binom.test(xU, n, alt = "greater")$conf.int[1], NA)
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,
ppL,
predL,
postL,
UciL,
pL_upper_ci,
xU,
xU / n,
ppU,
predU,
postU,
LciU
pU_lower_ci
)
}
return(round(data.frame(nvec, z), 4))
round(data.frame(looks, z), 4)
}
2 changes: 1 addition & 1 deletion R/predprob.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ predprob <- function(x, n, Nmax, p, thetaT, parE = c(1, 1),
betamixPost,
dbetabinomMix(x = 0:m, m = m, par = par, weights = weights)
)
assert_numeric(density, lower = 0, upper = 1, finite = TRUE, any.missing = FALSE)
assert_numeric(density, lower = 0, upper = 1 + .Machine$double.eps, finite = TRUE, any.missing = FALSE)
assert_number(thetaT, lower = 0, upper = 1, finite = TRUE)
# posterior probabilities to be above threshold p
posterior <- postprob(x = x + c(0:m), n = Nmax, p = p, parE = parE, weights = weights)
Expand Down
39 changes: 30 additions & 9 deletions examples/boundsPredprob.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# 40 pts trial with interim looks after each 10 pts.,
# final efficacy decision if more than 80% probability to be above 20% ORR,
# final futility decision otherwise.
# Interim efficacy decision if more than 90% predictive probability reach this,
# interim futility decision if less than 10% predictive probability.
# 40 pts trial with interim looks after each 10 patients.
# Final efficacy decision if more than 80% probability to be above 20% ORR,
# Final futility decision otherwise.
# Interim efficacy decision if more than 90% predictive probability reach this or
# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU,
# Interim futility decision if less than 10% predictive probability or
# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL
# Uniform prior (i.e. beta(1, 1)) on the ORR:
boundsPredprob(
nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80,
phiL = 0.10, phiU = 0.90, a = 1, b = 1
looks = c(10, 20, 30, 40),
p0 = 0.20,
tT = 0.80,
phiL = 0.60,
phiU = 0.90
)

# 25 pts trial with interim looks at 7 and 15 pts.
# Efficacy decision if more than 80% probability to be above 20% ORR,
# Final futility decision otherwise.
# Interim efficacy decision if more than 90% predictive probability reach this or
# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU,
# Interim futility decision if less than 60% predictive probability or
# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi
# with mixed prior and weights:
boundsPredprob(
looks = c(7, 15, 25),
p0 = 0.20,
tT = 0.80,
phiL = 0.60,
phiU = 0.90,
parE = cbind(c(1, 1), c(3, 10)),
weights = c(0.2, 0.8)
)
# From this we see e.g. that at the first IA at 10 pts, we would stop for futility
# if no patient responded, and for efficacy if 4 or more pts responded.
22 changes: 13 additions & 9 deletions examples/ocPredprobDist.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# - Interim look for Efficacy:
# Pr( success at final ) > 80% or P(success at final) > phiU
# - Interim look for Futility:
# Pr( failure at final ) < 20% or P(success at final) < phiL
# Pr( success at final ) < 20% or P(success at final) < phiL
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.

set.seed(20)
Expand Down Expand Up @@ -41,10 +41,14 @@ result$oc
# Desired difference to Standard of Care for Efficacy and Futility is 10% and -10% respectively.
# Grey zone occurs due to different posterior probability distribution in the Efficacy and Futility rules.
# Delta calculation is absolute case. The following are the Final Stop rules respectively :
# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT
# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT
# - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU
# - Interim look for Futility: Pr( failure at final ) < 20% or P(success at final) < phiL
# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or
# P(response rate + deltaE > p0) > tT
# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or
# P(response rate + deltaF > p0) < tT
# - Interim look for Efficacy: Pr( success at final ) > 80% or
# P(success at final) > phiU
# - Interim look for Futility: Pr( failure at final ) < 20% or
# P(success at final) < phiL
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.
#
set.seed(20)
Expand Down Expand Up @@ -111,10 +115,10 @@ result$oc
# True response rate or truep of the treatment group = 40%
# Desired difference to Standard of Care for Efficacy and Futility = 50%
# Delta calculation is relative case. The following are the Final Stop rules respectively :
# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25% ) > 60% or P( P_S + (1-P_S)*deltaE > p0) > tT
# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25% ) < 60% or P( P_S + (1-P_S)*deltaF > p0) < tT
# - Interim look for Efficacy: P( success at final ) > 80% or P(success at final) > phiU
# - Interim look for Futility: P( failure at final ) < 20% or P(success at final) < phiL
# - Final look for Efficacy: P( P_S + (1-P_S)*deltaE > 25% ) > 60%
# - Final look for Futility: P( P_S + (1-P_S)*deltaEF < 25% ) < 60%
# - Interim look for Efficacy: P( success at final ) > 80%
# - Interim look for Futility: P( failure at final ) < 20%
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.

set.seed(20)
Expand Down
8 changes: 0 additions & 8 deletions examples/plotBounds.R
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
# examples
plotBounds(boundsPredprob(
nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80,
phiL = 0.10, phiU = 0.90, a = 1, b = 1
), yt = "x")
plotBounds(boundsPredprob(
nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80,
phiL = 0.10, phiU = 0.90, a = 1, b = 1
), yt = "p")
63 changes: 50 additions & 13 deletions man/boundsPredprob.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions man/ocPredprobDist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions man/plotBounds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 73b3d65

Please sign in to comment.