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}
0 commit comments