Skip to content

Commit 9694d1b

Browse files
authored
Merge branch 'main' into 109_myPlotDiff
2 parents 6484d12 + 9fbc3ba commit 9694d1b

File tree

12 files changed

+158
-104
lines changed

12 files changed

+158
-104
lines changed

R/boundsPostprob.R

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,60 @@
22
#'
33
#' This function is used to identify the efficacy and futility
44
#' boundaries based on the following rules:
5-
#' Efficacy boundary: find minimum x (xU) where Pr(P > p1 |x, n, a, b) >= tU and
6-
#' Futility boundary: find maximum x (xL) where Pr(P < p0 | x, n, a, b) >= tL
7-
#'
8-
#' Efficacy boundary: find minimum x (xU) where Pr(P>p0|x,n,a,b) >= tU and
9-
#' Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL
5+
#' Efficacy boundary: find minimum x (xU) where Pr(RR > p1 | x, n, a, b) >= tU and
6+
#' Futility boundary: find maximum x (xL) where Pr(RR < p0 | x, n, a, b) >= tL
107
#'
118
#' @inheritParams postprob
129
#' @inheritParams ocPostprob
13-
#' @typed nvec : numeric
10+
#' @typed looks : numeric
1411
#' A vector of number of patients in each look.
15-
#' @return A matrix for each same size in `nvec`. For each sample size, the following is returned:
16-
#' - `xL` : the maximum number of responses that meet the futility.
17-
#' threshold
12+
#' @return A matrix for each same size in `looks`. For each sample size, the following is returned:
13+
#' - `xL` : the maximum number of responses that meet the futility threshold.
1814
#' - `pL` : response rate corresponding to `xL`.
19-
#' - `postL`: posterior probability corresponding to `xL`.
15+
#' - `postL`: posterior probability corresponding to `xL`, i.e. Pr(RR < p0 | xL, n, a, b).
2016
#' - `pL_upper_ci` : upper bound of one sided 95% CI for the response rate `pL` based on an
21-
#' - `Ucil` : upper bound of one sided 95% CI for the response rate based on an
2217
#' exact binomial test.
2318
#' - `xU` : the minimal number of responses that meet the efficacy threshold.
2419
#' - `pU` : response rate corresponding to `xU`.
25-
#' - `postU` : posterior probability corresponding to `xU`.
20+
#' - `postU` : posterior probability corresponding to `xU`, i.e. Pr(RR > p1 |xU, n, a, b).
2621
#' - `pU_lower_ci` : lower bound of one sided 95% CI for the response rate `pU` based on exact
27-
#' - `LciU` : lower bound of one sided 95% CI for the response rate based on exact
2822
#' binomial test.
2923
#'
3024
#' @example examples/boundsPostprob.R
3125
#' @export
32-
boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) {
33-
z <- matrix(NA, nrow = length(nvec), ncol = 8)
26+
boundsPostprob <- function(looks, p0, p1 = p0, tL, tU, parE = c(1, 1), weights) {
27+
assert_numeric(looks)
28+
assert_number(p0, lower = 0, upper = 1)
29+
assert_number(p1, lower = 0, upper = 1)
30+
assert_number(tL, lower = 0, upper = 1)
31+
assert_number(tU, lower = 0, upper = 1)
32+
assert_numeric(parE, min.len = 2, any.missing = FALSE)
33+
z <- matrix(NA, nrow = length(looks), ncol = 8)
3434
znames <- c(
3535
"xL", "pL", "postL", "pL_upper_ci",
3636
"xU", "pU", "postU", "pU_lower_ci"
3737
)
38-
dimnames(z) <- list(nvec, znames)
38+
dimnames(z) <- list(looks, znames)
3939
k <- 0
40-
for (n in nvec) {
40+
parE <- t(parE)
41+
if (missing(weights)) {
42+
weights <- rep(1, nrow(parE))
43+
}
44+
assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE)
45+
for (n in looks) {
4146
k <- k + 1
4247
# initialize so will return NA if 0 or n in "continue" region
4348
xL <- NA
4449
xU <- NA
4550
for (x in 0:n) {
46-
postp <- 1 - postprob(x, n, p0, parE = c(a, b)) # futility look
47-
if (postp >= tL) { # Rule is P(RR < p0) > tL
48-
postL <- postp
51+
postp_fut <- 1 - postprob(x = x, n = n, p = p0, parE = parE, weights = weights) # futility look
52+
if (postp_fut >= tL) { # Rule is P(RR < p0) > tL
53+
postL <- postp_fut
4954
xL <- x
5055
}
51-
postp <- postprob(x, n, p1, parE = c(a, b)) # efficacy look
52-
if (postp >= tU) { # Rule is P(RR > p1) > tU
53-
postU <- postp
56+
postp_eff <- postprob(x = x, n = n, p = p1, parE = parE, weights = weights) # efficacy look
57+
if (postp_eff >= tU) { # Rule is P(RR > p1) > tU
58+
postU <- postp_eff
5459
xU <- x
5560
break
5661
}
@@ -69,5 +74,5 @@ boundsPostprob <- function(nvec, p0, p1 = p0, tL, tU, a, b) {
6974
pU_lower_ci
7075
)
7176
}
72-
round(data.frame(nvec, z), 4)
77+
round(data.frame(looks, z), 4)
7378
}

R/ocPostprob.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ h_get_oc <- function(all_sizes, Nmax, decision) {
187187
#'
188188
#' Stop criteria for Efficacy :
189189
#'
190-
#' `Pr(truep > p1) > tU`
190+
#' `Pr(RR > p1) > tU`
191191
#'
192192
#' Stop criteria for Futility :
193193
#'
194-
#' `Pr(truep < p0) > tL`
194+
#' `Pr(RR < p0) > tL`
195195
#'
196196
#' Resulting operating characteristics include the following:
197197
#'

examples/boundsPostprob.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
# 40 pts trial with interim looks after each 10 pts.,
2-
# Efficacy decision if more than 60% probability to be above 20% ORR,
3-
# Futility decision if less than 60% probability to be below 20% ORR,
2+
# Efficacy decision if more than 80% probability to be above 20% ORR,
3+
# Futility decision if more than 60% probability to be below 15% ORR,
44
# with uniform prior (i.e. beta(1, 1)) on the ORR:
55
boundsPostprob(
6-
nvec = c(10, 20, 30, 40), p0 = 0.20, p1 = 0.2,
7-
tL = 0.60, tU = 0.60, a = 1, b = 1
6+
looks = c(10, 20, 30, 40),
7+
p0 = 0.15,
8+
p1 = 0.20,
9+
tL = 0.60,
10+
tU = 0.80,
11+
parE = c(1, 1)
12+
)
13+
14+
# 40 pts trial with interim looks at 7 and 20 pts.
15+
# Efficacy decision if more than 80% probability to be above 20% ORR,
16+
# Futility decision if more than 60% probability to be below 15% ORR,
17+
# with mixed prior and weights:
18+
boundsPostprob(
19+
looks = c(7, 20, 40),
20+
p0 = 0.15,
21+
p1 = 0.20,
22+
tL = 0.60,
23+
tU = 0.80,
24+
parE = rbind(c(1, 19), c(2, 10)),
25+
weights = c(0.2, 0.8)
826
)

examples/ocPredprobDist.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ result$oc
7474
# True response rate or truep of the treatment group = 40%
7575
# Desired difference to Standard of Care for Efficacy and Futility = 50%
7676
# Delta calculation is absolute case. The following are the Final Stop rules respectively :
77-
# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or P(response rate + deltaE > p0) > tT
78-
# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or P(response rate + deltaF > p0) < tT
79-
# - Interim look for Efficacy: Pr( success at final ) > 80% or P(success at final) > phiU
80-
# - Interim look for Futility: Pr( failure at final ) < 20% or P(success at final) < phiL
77+
# - Final look for Efficacy: Pr( response rate + deltaE > 25% ) > 60% or
78+
# P(response rate + deltaE > p0) > tT
79+
# - Final look for Futility: Pr( response rate + deltaF < 25% ) < 60% or
80+
# P(response rate + deltaF > p0) < tT
81+
# - Interim look for Efficacy: Pr( success at final ) > 80% or
82+
# P(success at final) > phiU
83+
# - Interim look for Futility: Pr( failure at final ) < 20% or
84+
# P(success at final) < phiL
8185
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.
8286

8387
set.seed(20)

examples/plotBounds.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,3 @@ plotBounds(boundsPredprob(
77
nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80,
88
phiL = 0.10, phiU = 0.90, a = 1, b = 1
99
), yt = "p")
10-
plotBounds(
11-
boundsPostprob(
12-
nvec = c(10, 20, 30, 40), p0 = 0.20,
13-
tL = 0.10, tU = 0.90, a = 1, b = 1
14-
),
15-
yt = "p", add = TRUE
16-
)

man/boundsPostprob.Rd

Lines changed: 35 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ocPostprob.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ocPredprob.Rd

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ocPredprobDist.Rd

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)