Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

96 bounds predprob #105

Merged
merged 65 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4f8d4c8
Merge remote-tracking branch 'origin/HEAD'
audreyyeoCH May 17, 2024
d4f13d0
examples and test
audreyyeoCH May 26, 2024
7e605bf
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 26, 2024
bc25aeb
Merge branch 'main' into 96_boundsPredprob
audreyyeoCH May 26, 2024
3aa565b
clean
audreyyeoCH Jun 11, 2024
7e50f1c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jun 11, 2024
d3a54b7
Merge branch 'main' into 96_boundsPredprob
audreyyeoCH Jun 26, 2024
75b676e
it works
audreyyeoCH Jun 26, 2024
a5134f0
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jun 26, 2024
dd94883
Merge branch 'main' into 96_boundsPredprob
audreyyeoCH Jun 27, 2024
1b7df26
some syntax changes
audreyyeoCH Sep 26, 2024
bdcf2a3
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 26, 2024
e180429
clean
audreyyeoCH Sep 27, 2024
942e0f7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 27, 2024
23a06f3
clean
audreyyeoCH Sep 27, 2024
9ffba4c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 27, 2024
f6faec2
clean
audreyyeoCH Oct 1, 2024
93e054c
Merge branch 'main' into 96_boundsPredprob
audreyyeoCH Oct 1, 2024
3d7daf5
fix conflicts
audreyyeoCH Oct 1, 2024
cefe1a9
clean
audreyyeoCH Oct 1, 2024
aee5fb6
clean
audreyyeoCH Oct 2, 2024
e585093
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 2, 2024
eba4d49
clean
audreyyeoCH Oct 2, 2024
e4864b5
test case with pred prob passes with missing weights argument
audreyyeoCH Oct 10, 2024
945a2b9
clean
audreyyeoCH Oct 10, 2024
d9cc2e3
resolve conflict when rebasing feature off main
audreyyeoCH Oct 10, 2024
73b3d65
fixing conflicts
audreyyeoCH Oct 10, 2024
eca1581
fixing conflicts
audreyyeoCH Oct 10, 2024
74e160d
conclude merge
audreyyeoCH Oct 10, 2024
a2194d7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jun 11, 2024
e42ce48
clean
audreyyeoCH Oct 10, 2024
f544973
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jun 26, 2024
db70515
clean
audreyyeoCH Oct 10, 2024
ea185a8
clean
audreyyeoCH Oct 10, 2024
9e42113
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 26, 2024
0e94535
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 27, 2024
c990774
clean
audreyyeoCH Oct 10, 2024
49d2847
Merge branch 'main' into 96_boundsPredprob
audreyyeoCH Oct 10, 2024
bb749b9
clean
audreyyeoCH Oct 11, 2024
fc3bd8e
clean
audreyyeoCH Oct 11, 2024
7ab498b
clean
audreyyeoCH Oct 11, 2024
053547d
clean
audreyyeoCH Oct 11, 2024
f416788
empty
audreyyeoCH Oct 15, 2024
abe8a2c
empty
audreyyeoCH Oct 15, 2024
855dc8e
added plotBounds(boundsPredprob()) examples
audreyyeoCH Oct 16, 2024
a133d92
added plotBounds(boundsPredprob()) examples and plotBounds(
audreyyeoCH Oct 16, 2024
ed3aea6
Update R/boundsPredprob.R
audreyyeoCH Oct 19, 2024
17fbce4
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 19, 2024
2d1ed94
clean
audreyyeoCH Oct 19, 2024
09a3744
make sure helper functions are written with all input arguments
audreyyeoCH Oct 19, 2024
5dce59e
clean
audreyyeoCH Oct 19, 2024
07359b7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 19, 2024
9db05d7
clean
audreyyeoCH Nov 21, 2024
ea10141
clean
audreyyeoCH Nov 22, 2024
47d5155
clean
audreyyeoCH Dec 30, 2024
4110893
RR documentation
audreyyeoCH Dec 30, 2024
cdcc320
clean
audreyyeoCH Dec 31, 2024
c661bdf
clean
audreyyeoCH Dec 31, 2024
5083088
clean
audreyyeoCH Dec 31, 2024
69f7ae9
Update examples/boundsPredprob.R
audreyyeoCH Jan 9, 2025
d7d04ef
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jan 9, 2025
8776035
debugging on parE issue with giving correct results and other documen…
audreyyeoCH Jan 13, 2025
9b912bd
[skip style] [skip vbump] Restyle files
github-actions[bot] Jan 13, 2025
258ae08
clean
audreyyeoCH Jan 14, 2025
d3ebc38
clean
audreyyeoCH Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions R/boundsPostprob.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' Decision cutpoints for boundary (based on posterior probability)
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' This function is used to identify the efficacy and futility
#' boundaries based on the following rules:
#' Efficacy boundary: find minimum x (xU) where Pr(RR > p1 |x, n, a, b) >= tU and
#' Efficacy boundary: find minimum x (xU) where Pr(RR > p1 | x, n, a, b) >= tU and
#' Futility boundary: find maximum x (xL) where Pr(RR < p0 | x, n, a, b) >= tL
#'
#' @inheritParams postprob
Expand All @@ -24,7 +26,7 @@
#' @example examples/boundsPostprob.R
#' @export
boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) {
assert_numeric(looks)
assert_numeric(looks, any.missing = FALSE)
assert_number(p0, lower = 0, upper = 1)
assert_number(p1, lower = 0, upper = 1)
assert_number(tL, lower = 0, upper = 1)
Expand All @@ -48,12 +50,12 @@ boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights)
xL <- NA
xU <- NA
for (x in 0:n) {
postp_fut <- 1 - postprob(x, n, p0, parE, weights) # futility look
postp_fut <- 1 - postprob(x = x, n = n, p = p0, parE = parE, weights = weights) # futility look
if (postp_fut >= tL) { # Rule is P(RR < p0) > tL
postL <- postp_fut
xL <- x
}
postp_eff <- postprob(x, n, p1, parE, weights) # efficacy look
postp_eff <- postprob(x = x, n = n, p = p1, parE = parE, weights = weights) # efficacy look
if (postp_eff >= tU) { # Rule is P(RR > p1) > tU
postU <- postp_eff
xU <- x
Expand Down
39 changes: 26 additions & 13 deletions R/boundsPredprob.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
#' Decision cutpoints for boundary (based on predictive probability) for Decision 1 rule.
audreyyeoCH marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' This function is used to identify the efficacy boundary and futility
#' boundary based on rules in @details.
#'
#' @inheritParams predprob
#' @inheritParams ocPredprob
#' @inheritParams boundsPostprob
#' @return A matrix for each same size in `looks`. For each sample size, the following is returned:
#' - `xL` : the maximum number of responses that meet the futility.
#' threshold
#' - `xL` : the maximum number of responses that meet the futility
#' threshold.
#' - `pL` : response rate corresponding to `xL`.
#' - `predL` : predictive probability corresponding to `xL`
#' - `postL`: posterior probability corresponding to `xL`.
#' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an
#' - `pL_upper_ci` : upper bound of one sided 95% CI for the response rate based on an
#' exact binomial test.
#' - `xU` : the minimal number of responses that meet the efficacy threshold.
#' - `pU` : response rate corresponding to `xU`.
#' - `predU` : predictive probability corresponding to `xU`
#' - `predU` : predictive probability corresponding to `xU`.
#' - `postU`: posterior probability corresponding to `xU`.
#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact
#' - `pU_lower_ci` : lower bound of one sided 95% CI for the response rate based on exact
#' binomial test.
#'
#' @importFrom stats binom.test
#'
#' @details see also `predprob()`
#' The following rules are Decision 1 rules:
#' Efficacy boundary: find minimum x (xU) where
#' Pr(Pr(response rate > p0 | data) >= tT | x) >= phiU,
#' Pr(Pr(RR > p0 | data) >= tT | x) >= phiU,
#' Futility boundary: find maximum x (xL) where
#' Pr(Pr(response rate > p0 | data) >= tT | x) =< phiL
#' Pr(Pr(RR > p0 | data) >= tT | x) =< phiL
#'
#' @example examples/boundsPredprob.R
#' @export
#' @keywords graphics
boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE = c(1, 1), weights) {
assert_numeric(looks)
assert_numeric(looks, any.missing = FALSE)
assert_number(p0, lower = 0, upper = 1)
assert_number(tT, lower = 0, upper = 1)
assert_number(phiL, lower = 0, upper = 1)
assert_number(phiU, lower = 0, upper = 1)
assert_numeric(parE, min.len = 2, any.missing = FALSE)
audreyyeoCH marked this conversation as resolved.
Show resolved Hide resolved
znames <- c(
"xL", "pL", "predL", "postL", "UciL",
Expand All @@ -45,18 +49,27 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE =
z <- matrix(NA, length(looks), length(znames))
dimnames(z) <- list(looks, znames)
k <- 0
assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE)
audreyyeoCH marked this conversation as resolved.
Show resolved Hide resolved
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) {
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
predprob <- predprob(
x = x,
n = n,
Nmax = max(looks),
p = p0,
thetaT = tT,
parE = parE,
weights = weights
)$result
if (predprob <= phiL) { # Futility look, Rule Pr(Pr( RR > p0 | x, Y) >= tT | x) =< phiL
xL <- x
predL <- predprob
}
if (predprob >= phiU) { # Efficacy look, Rule Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU,
if (predprob >= phiU) { # Efficacy look, Rule Pr(Pr( RR > p0 | x, Y) >= tT | x) >= phiU,
xU <- x
predU <- predprob
break
Expand All @@ -67,8 +80,8 @@ boundsPredprob <- function(looks, Nmax = max(looks), p0, tT, phiL, phiU, parE =
xU <- NA
}
# calculate predictive and posterior probabilities at boundaries
postL <- postprob(xL, n, p0, parE = parE)
postU <- postprob(xU, n, p0, parE = parE)
postL <- postprob(x = xL, n = n, p = p0, parE = parE, weights = weights, log.p = FALSE)
postU <- postprob(x = xU, n = n, p = p0, parE = parE, weights = weights, log.p = FALSE)
# calculate lower CI at boundaries
pL_upper_ci <- ifelse(!is.na(xL), stats::binom.test(xL, n, alt = "less")$conf.int[2], NA)
pU_lower_ci <- ifelse(!is.na(xU), stats::binom.test(xU, n, alt = "greater")$conf.int[1], NA)
Expand Down
4 changes: 2 additions & 2 deletions R/ocPostprobDist.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ h_get_decisionDist <- function(nnr,
#'
#' Stop criteria for Efficacy :
#'
#' `Pr(truep > P_S + deltaE) > tU`
#' `Pr(RR > P_S + deltaE) > tU`
#'
#' Stop criteria for Futility :
#'
#' `Pr(truep < P_S + deltaF) > tL`
#' `Pr(RR < P_S + deltaF) > tL`
#'
#' Where `truep` is the assumed true rate of response and `p1` and `p0` respectively are
#' the thresholds for Efficacy and Futility respectively.
Expand Down
8 changes: 4 additions & 4 deletions R/ocPredprob.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ h_get_decision_two_predprob <- function(nnr, truep, p0, p1, parE = c(1, 1), nnE,
#' - interim STOP = P(successful trial at final) < phiL
#'
#' The criteria for Decision 1 for Final looks are:
#' - Final GO = P( response rate > p0 | data) > tT
#' - Final STOP = P( response rate > p0 | data ) < tT
#' - Final GO = P( RR > p0 | data) > tT
#' - Final STOP = P( RR > p0 | data ) < tT
#'
#' ## Decision 2:
#' The criteria for Decision 2 for Interim looks are :
#' - Interim GO : P ( success at final) > phiU
#' - Interim STOP : P (failure at final ) > phiFu
#'
#' The criteria for Decision 2 for Futility looks are :
#' - Final GO = P( response rate > p0) > tT
#' - Final STOP = P( response rate < p1) > tF
#' - Final GO = P( RR > p0) > tT
#' - Final STOP = P( RR < p1) > tF
#'
#' @inheritParams h_get_decision_one_predprob
#' @inheritParams h_get_decision_two_predprob
Expand Down
8 changes: 4 additions & 4 deletions examples/boundsPredprob.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Final efficacy decision if more than 80% probability to be above 20% ORR,
# Final futility decision otherwise.
# Interim efficacy decision if more than 90% predictive probability reach this or
# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU,
# Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU,
# Interim futility decision if less than 10% predictive probability or
# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phiL
# Futility look Pr(Pr(RR) > p0 | x, Y) >= tT | x) =< phiL
audreyyeoCH marked this conversation as resolved.
Show resolved Hide resolved
# Uniform prior (i.e. beta(1, 1)) on the ORR:
boundsPredprob(
looks = c(10, 20, 30, 40),
Expand All @@ -18,9 +18,9 @@ boundsPredprob(
# Efficacy decision if more than 80% probability to be above 20% ORR,
# Final futility decision otherwise.
# Interim efficacy decision if more than 90% predictive probability reach this or
# Efficacy look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) >= phiU,
# Efficacy look Pr(Pr(RR > p0 | x, Y) >= tT | x) >= phiU,
# Interim futility decision if less than 60% predictive probability or
# Futility look Pr(Pr(P > p0 | x, Y, a, b) >= tT | x) =< phi
# Futility look Pr(Pr(RR > p0 | x, Y) >= tT | x) =< phi
# with mixed prior and weights:
boundsPredprob(
looks = c(7, 15, 25),
Expand Down
4 changes: 2 additions & 2 deletions examples/ocPostprob.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# For three looks of 10, 20 and 30 we have the following assumptions :
# True response rate or truep of the treatment group = 40%
# The following are the Stop rules respectively :
# Look for Efficacy: Pr(truep > 30% )> 80%
# Look for Futility: Pr(truep < 20% )> 60%
# Look for Efficacy: Pr(RR > 30% )> 80%
# Look for Futility: Pr(RR < 20% )> 60%
# Prior of treatment arm parE= Beta(1,1).
res <- ocPostprob(
nnE = c(10, 20, 30), truep = 0.40, p0 = 0.20, p1 = 0.30, tL = 0.60, tU = 0.80, parE = c(1, 1),
Expand Down
2 changes: 0 additions & 2 deletions examples/ocPostprobDist.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# True response rate or truep of the treatment group = 40%
# The following are the Go and Stop rules respectively :
# Prior of treatment arm parE= Beta(1,1).
# stop for efficacy (deltaE): Pr(truep > P_S + deltaE) > tU
# stop for futility (deltaF): Pr(truep < P_S + deltaF) > tL
# Without random distance allowed for Futility and Efficacy Looks.
res1 <- ocPostprobDist(
nnE = c(10, 20, 30),
Expand Down
8 changes: 4 additions & 4 deletions examples/ocPredprob.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Here we illustrate an example for Decision 1 with the following assumptions :
# True response rate or truep of the treatment group = 40%
# The following are the Final Stop rules respectively :
# - Final look for Efficacy: Pr( response rate > 25% ) > 60% or P(response rate > p0) > tT
# - Final look for Futility: Pr( response rate < 25% ) < 60% or P(response rate > p0) < tT
# - Final look for Efficacy: Pr( RR > 25% ) > 60% or P( RR > p0) > tT
# - Final look for Futility: Pr( RR < 25% ) < 60% or P(RR > p0) < tT
# - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU
# - Interim look for Futility: Pr( failure at final ) < 20% or P(success at final) < phiL
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.
Expand Down Expand Up @@ -76,8 +76,8 @@ result$oc
# Here we illustrate an example for Decision 2 with the following assumptions :
# True response rate or truep of the treatment group = 60%
# The following are the Final Stop rules respectively :
# - Final look for Efficacy: Pr( response rate > 25% ) > 60% or P(response rate > p0) > tT
# - Final look for Futility: Pr( response rate < 25% ) < 60% or P(response rate < p1) > tF
# - Final look for Efficacy: Pr( RR > 25% ) > 60% or P(RR > p0) > tT
# - Final look for Futility: Pr( RR < 25% ) < 60% or P(RR < p1) > tF
# - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU
# - Interim look for Futility: Pr( failure at final ) > 80% or P(failure at final) > phiFu
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.
Expand Down
35 changes: 12 additions & 23 deletions examples/ocPredprobDist.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
# Efficacy Looks and Futility looks are identical at sample size of 10, 20 and 30.
# True response rate or truep of the treatment group = 40%
# Desired difference to Standard of Care for Efficacy and Futility = 10%
# Delta calculation is absolute case. The following are the Final Stop rules respectively :
# - Final look for Efficacy:
# Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT
# - Final look for Futility:
# Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT
# - Interim look for Efficacy:
# Pr( success at final ) > 80% or P(success at final) > phiU
# - Interim look for Futility:
# Pr( success at final ) < 20% or P(success at final) < phiL
# The following are the Final Stop rules respectively :
# - Final look for Efficacy: Pr( RR + deltaE > 25% ) > 60%
# - Final look for Futility: Pr( RR + deltaF < 25% ) < 60%
# - Interim look for Efficacy: Pr( success at final ) > 80%
# - Interim look for Futility: Pr( failure at final ) < 20%
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.

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

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

24 changes: 13 additions & 11 deletions man/boundsPredprob.Rd

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

4 changes: 2 additions & 2 deletions man/ocPostprob.Rd

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

Loading
Loading