diff --git a/.lintr b/.lintr index c2b2094f..f3e3fb1d 100644 --- a/.lintr +++ b/.lintr @@ -1,5 +1,6 @@ linters: with_defaults( line_length_linter = line_length_linter(120), cyclocomp_linter = NULL, - object_usage_linter = NULL + object_usage_linter = NULL, + object_name_linter = NULL ) diff --git a/DESCRIPTION b/DESCRIPTION index 9bb0f8cf..88616c81 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,7 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 Collate: 'Phase1b-package.R' 'betadiff.R' diff --git a/R/dbetabinom.R b/R/dbetabinom.R index cb95108e..a2a9d5c7 100644 --- a/R/dbetabinom.R +++ b/R/dbetabinom.R @@ -127,8 +127,8 @@ dbetaMix <- Vectorize(dbetaMix, vectorize.args = "x") ##' @param par the beta parameters matrix, with K rows and 2 columns, ##' corresponding to the beta parameters of the K components ##' @param weights the mixture weights of the beta mixture prior -##' @param lower.tail logical; if TRUE (default), probabilities are P[X <= x], -##' and otherwise P[X > x] +##' @param lower.tail logical; if TRUE (default), probabilities are `P[X <= x]`, +##' and otherwise `P[X > x]` ##' @return the (one minus) cdf value ##' ##' @export diff --git a/R/plotBounds.R b/R/plotBounds.R index 5b4bdb54..e05b2efd 100644 --- a/R/plotBounds.R +++ b/R/plotBounds.R @@ -15,8 +15,8 @@ ##' @param yt indicate the y axis: response rate is "p", number of responses ##' is "x" ##' @param add add the boundary lines or not -##' @param cols specific the color of [1] efficacy area [2] futility area -##' [3] efficacy boundary [4] futility boundary +##' @param cols specific the color of `[1]` efficacy area `[2]` futility area +##' `[3]` efficacy boundary `[4]` futility boundary ##' @param lwds line width (a two dimensional vector) ##' @param ltype line type ##' @param lpch a value of plotting characters or symbols diff --git a/R/postprob.R b/R/postprob.R index 766f2f72..1f6d65b4 100644 --- a/R/postprob.R +++ b/R/postprob.R @@ -29,9 +29,9 @@ postprobOld <- function(x, n, p, a = 1, b = 1) { ##' Compute the posterior probability to be above threshold, ##' with a beta mixture prior on the response rate. ##' -##' Computes the posterior probability Pr(P_E > p | data). Prior is P_E ~ -##' sum(weights * beta(parE[, 1], parE[, 2])), i.e., a mixture of beta priors. -##' Default is one component only with uniform or beta(1,1). +##' Computes the posterior probability `Pr(P_E > p | data)`. Prior is +##' `P_E ~ sum(weights * beta(parE[, 1], parE[, 2]))`, i.e., a mixture of beta priors. +##' Default is one component only with uniform or `beta(1,1)`. ##' ##' We observed x successes in n trials. Note that \code{x} can be a vector. ##' diff --git a/man/betadiff.Rd b/man/betadiff.Rd index 640f54b3..acc76da1 100644 --- a/man/betadiff.Rd +++ b/man/betadiff.Rd @@ -38,40 +38,49 @@ the distribution of the difference of two beta distributions with parameters par parX <- c(1, 52) parY <- c(5.5, 20.5) -z <- seq(from=-1, to=1, length=100) -plot(z, dbetadiff(z, parY=parY, parX=parX), - type="l") +z <- seq(from = -1, to = 1, length = 100) +plot(z, dbetadiff(z, parY = parY, parX = parX), + type = "l" +) ## calculate probability ## for Go: -test <- integrate(f=dbetadiff, - parY=parY, - parX=parX, - lower=0.15, - upper=1) +test <- integrate( + f = dbetadiff, + parY = parY, + parX = parX, + lower = 0.15, + upper = 1 +) str(test) test$value ## vary close to the Monte Carlo result: -mean(rbeta(n=1e6, parY[1], parY[2]) - - rbeta(n=1e6, parX[1], parX[2]) > 0.15) +mean(rbeta(n = 1e6, parY[1], parY[2]) - + rbeta(n = 1e6, parX[1], parX[2]) > 0.15) ## similar case for Stop: -integrate(f=dbetadiff, - parY=parY, - parX=parX, - lower=-1, - upper=0.5) +integrate( + f = dbetadiff, + parY = parY, + parX = parX, + lower = -1, + upper = 0.5 +) -mean(rbeta(n=1e6, parY[1], parY[2]) - - rbeta(n=1e6, parX[1], parX[2]) < 0.5) +mean(rbeta(n = 1e6, parY[1], parY[2]) - + rbeta(n = 1e6, parX[1], parX[2]) < 0.5) -test <- qbetadiff(p=0.2, - parY=parY, - parX=parX) -pbetadiff(q=test, - parY=parY, - parX=parX) +test <- qbetadiff( + p = 0.2, + parY = parY, + parX = parX +) +pbetadiff( + q = test, + parY = parY, + parX = parX +) } diff --git a/man/boundsPostprob.Rd b/man/boundsPostprob.Rd index 68b9a947..1cb2ae60 100644 --- a/man/boundsPostprob.Rd +++ b/man/boundsPostprob.Rd @@ -44,8 +44,10 @@ Futility boundary: find maximum x (xL) where Pr(P>p1|x,n,a,b) <= tL ## efficacy decision if more than 90\% probability to be above 20\% ORR, ## futility decision if less than 10\% probability to be above 20\% ORR, ## with uniform prior (i.e. beta(1, 1)) on the ORR: -boundsPostprob(nvec=c(10,20,30,40), p0=0.20, - tL=0.10, tU=0.90, a=1, b=1) +boundsPostprob( + nvec = c(10, 20, 30, 40), p0 = 0.20, + tL = 0.10, tU = 0.90, a = 1, b = 1 +) ## From this we see e.g. that at the third IA at 30 pts, we would stop for futility ## if 5 or less patients responded, and for efficacy if 9 or more pts responded. } diff --git a/man/boundsPredprob.Rd b/man/boundsPredprob.Rd index 89420347..e0e28cce 100644 --- a/man/boundsPredprob.Rd +++ b/man/boundsPredprob.Rd @@ -51,10 +51,11 @@ Pr(Pr(P > p | x, Y) >= tT | x) < phiL ## Interim efficacy decision if more than 90\% predictive probability reach this, ## interim futility decision if less than 10\% predictive probability. ## 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) +boundsPredprob( + nvec = c(10, 20, 30, 40), p = 0.20, tT = 0.80, + phiL = 0.10, phiU = 0.90, a = 1, b = 1 +) ## 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. - } \keyword{graphics} diff --git a/man/dbetabinom.Rd b/man/dbetabinom.Rd index fcedbabb..d4ede788 100644 --- a/man/dbetabinom.Rd +++ b/man/dbetabinom.Rd @@ -28,14 +28,14 @@ The beta-binomial density function has the following form: \deqn{p(x) = (m! / (x!*(m-x)!)) * Beta(x+a,m-x+b) / Beta(a,b)} } \examples{ -## Calculating the beta binomial density +## Calculating the beta binomial density ## x = 2; m = 29; a = 0.2; b = 0.4 -## p(x) = choose(29,2)*beta(2.2,27.4)/beta(0.2,0.4) = 0.04286893 +## p(x) = choose(29,2)*beta(2.2,27.4)/beta(0.2,0.4) = 0.04286893 ## -dbetabinom(2,29,0.2,0.4) +dbetabinom(2, 29, 0.2, 0.4) ## Can also specify x as a vector ## x = 1:28 ## -dbetabinom(1:28,29,0.2,0.4) +dbetabinom(1:28, 29, 0.2, 0.4) } diff --git a/man/getBetamixPost.Rd b/man/getBetamixPost.Rd index e2141bf5..7758bbd5 100644 --- a/man/getBetamixPost.Rd +++ b/man/getBetamixPost.Rd @@ -24,12 +24,15 @@ Computes the posterior parameters of a beta mixture } \examples{ ## example from Lee and Liu: -getBetamixPost(x=16, n=23, par=t(c(0.6, 0.4)), weights=1) - -getBetamixPost(x=16, n=23, - par= - rbind(c(0.6, 0.4), - c(1, 1)), - weights=c(0.6, 0.4)) +getBetamixPost(x = 16, n = 23, par = t(c(0.6, 0.4)), weights = 1) +getBetamixPost( + x = 16, n = 23, + par = + rbind( + c(0.6, 0.4), + c(1, 1) + ), + weights = c(0.6, 0.4) +) } diff --git a/man/logit.Rd b/man/logit.Rd index 372502f0..f09556bc 100644 --- a/man/logit.Rd +++ b/man/logit.Rd @@ -24,7 +24,7 @@ logit(x) ## Can also be a vector of probabilities ## -x <- seq(0.1,0.9,0.1) +x <- seq(0.1, 0.9, 0.1) logit(x) } \keyword{programming} diff --git a/man/myPlot.Rd b/man/myPlot.Rd index 45a23e55..b583c635 100644 --- a/man/myPlot.Rd +++ b/man/myPlot.Rd @@ -20,7 +20,7 @@ nothing, only produces the plot as side effect This function will plot the PDF of a beta distribution } \examples{ -myPlot(1,2) -myPlot(1,1) +myPlot(1, 2) +myPlot(1, 1) } \keyword{graphics} diff --git a/man/myPlotDiff.Rd b/man/myPlotDiff.Rd index bcc0fb5e..6246d973 100644 --- a/man/myPlotDiff.Rd +++ b/man/myPlotDiff.Rd @@ -28,8 +28,8 @@ nothing, only produces the plot as side effect This function will plot the PDF of a diffience between two Beta distributions } \examples{ -myPlotDiff(c(5,10),c(2,5),0.2,0.05,1,0) -myPlotDiff(c(5,10),c(2,5),0.2,0.05,1) -myPlotDiff(c(5,10),c(2,5),0.2,0.05,0) +myPlotDiff(c(5, 10), c(2, 5), 0.2, 0.05, 1, 0) +myPlotDiff(c(5, 10), c(2, 5), 0.2, 0.05, 1) +myPlotDiff(c(5, 10), c(2, 5), 0.2, 0.05, 0) } \keyword{graphics} diff --git a/man/oc2.Rd b/man/oc2.Rd index 8e7a3306..555694ef 100644 --- a/man/oc2.Rd +++ b/man/oc2.Rd @@ -106,149 +106,167 @@ approximately equal distance between the looks. } \examples{ ## this looks OK now: -oc2(method="Prior.PP", - histSize=1e5L, - trialSize=100, - drift=0, - controlRate=0.5, - nmeRate=0.70, - nSim=20, - delta=0.15) +oc2( + method = "Prior.PP", + histSize = 1e5L, + trialSize = 100, + drift = 0, + controlRate = 0.5, + nmeRate = 0.70, + nSim = 20, + delta = 0.15 +) ## this one as well: -oc2(method="Prior.Bayes", - histSize=1e6L, - trialSize=100, - drift=0, - controlRate=0.5, - nmeRate=0.65, - nSim=20, - delta=0.15) +oc2( + method = "Prior.Bayes", + histSize = 1e6L, + trialSize = 100, + drift = 0, + controlRate = 0.5, + nmeRate = 0.65, + nSim = 20, + delta = 0.15 +) ## this example takes longer to run, therefore we don't execute it here: -if(FALSE) -{ -## the different methods we are looking at: -methods <- c("PointMass.Bayes", "Prior.Bayes", "RCT.Bayes", "RCTvanilla.Bayes", - "PointMass.PP", "Prior.PP", "RCT.PP", "RCTvanilla.PP") - -## the control rate will always be 50\% -## but the historical data will be generated randomly from that -## binomial distribution! - -## delta will be 0.15 - -## 200 simulations - -## the different prior sample sizes (historical data size) -## histSizes <- c(10, 20, 50, 150) -## later: add very large size, but with heterogeneity => -## mixture of beta priors -histSizes <- c(20, 150) - -## the trial sample size (total) -trialSizes <- c(40) - -## the drift -drift <- c(0, 0.1, 0.2) - -## the different true rates for the NME: -## nmeRates <- seq(from=0.05, to=0.95, by=0.05) -nmeRates <- c(0.4, 0.5, 0.6, 0.7, 0.8) - -## so the whole grid is -wholeGrid <- expand.grid(method=methods, - drift=drift, - histSize=histSizes, - trialSize=trialSizes, - nmeRate=nmeRates, stringsAsFactors = FALSE) - -## summarize the methods - -## compute the operating characteristics for all combinations -if(file.exists(savefile <- "allSims4.RData")) -{ +if (FALSE) { + ## the different methods we are looking at: + methods <- c( + "PointMass.Bayes", "Prior.Bayes", "RCT.Bayes", "RCTvanilla.Bayes", + "PointMass.PP", "Prior.PP", "RCT.PP", "RCTvanilla.PP" + ) + + ## the control rate will always be 50\% + ## but the historical data will be generated randomly from that + ## binomial distribution! + + ## delta will be 0.15 + + ## 200 simulations + + ## the different prior sample sizes (historical data size) + ## histSizes <- c(10, 20, 50, 150) + ## later: add very large size, but with heterogeneity => + ## mixture of beta priors + histSizes <- c(20, 150) + + ## the trial sample size (total) + trialSizes <- c(40) + + ## the drift + drift <- c(0, 0.1, 0.2) + + ## the different true rates for the NME: + ## nmeRates <- seq(from=0.05, to=0.95, by=0.05) + nmeRates <- c(0.4, 0.5, 0.6, 0.7, 0.8) + + ## so the whole grid is + wholeGrid <- expand.grid( + method = methods, + drift = drift, + histSize = histSizes, + trialSize = trialSizes, + nmeRate = nmeRates, stringsAsFactors = FALSE + ) + + ## summarize the methods + + ## compute the operating characteristics for all combinations + if (file.exists(savefile <- "allSims4.RData")) { load(savefile) -} else { + } else { ## setup the result list - allOcs <- vector(mode="list", - length=nrow(wholeGrid)) + allOcs <- vector( + mode = "list", + length = nrow(wholeGrid) + ) - for(i in seq_len(nrow(wholeGrid))) + for (i in seq_len(nrow(wholeGrid))) { - set.seed(i) - allOcs[[i]] <- with(wholeGrid[i, ], - oc2(method=method, - histSize=histSize, - trialSize=trialSize, - drift=drift, - controlRate=0.5, - nmeRate=nmeRate, - nSim=200, - delta=0.15)) + set.seed(i) + allOcs[[i]] <- with( + wholeGrid[i, ], + oc2( + method = method, + histSize = histSize, + trialSize = trialSize, + drift = drift, + controlRate = 0.5, + nmeRate = nmeRate, + nSim = 200, + delta = 0.15 + ) + ) } save(allOcs, - file=savefile) -} + file = savefile + ) + } -length(allOcs) -allOcs + length(allOcs) + allOcs -allOcs[[1]] + allOcs[[1]] -allPossibleNames <- colnames(allOcs[[1]]) -allPossibleNames + allPossibleNames <- colnames(allOcs[[1]]) + allPossibleNames -allOcsMatrix <- -t(sapply(allOcs, - function(x){ - res <- rep(NA, length(allPossibleNames)) - names(res) <- allPossibleNames - res[colnames(x)] <- x - res - })) + allOcsMatrix <- + t(sapply( + allOcs, + function(x) { + res <- rep(NA, length(allPossibleNames)) + names(res) <- allPossibleNames + res[colnames(x)] <- x + res + } + )) -allOcsMatrix -wholeMatrix <- cbind(wholeGrid, allOcsMatrix) + allOcsMatrix + wholeMatrix <- cbind(wholeGrid, allOcsMatrix) -library(reshape) + library(reshape) -## write a table to a Word file in the current directory -outputTab <- function(tab, - out="output.docx", # name of the output file - digits=2) # how many digits for numbers? -{ + ## write a table to a Word file in the current directory + outputTab <- function(tab, + out = "output.docx", # name of the output file + digits = 2) # how many digits for numbers? + { library(officer) doc <- read_docx() dat <- as.data.frame(tab) whichNum <- which(sapply(dat, is.numeric)) - whichInt <- which(sapply(dat, function(x) {is.numeric(x) && all(x == round(x))})) - for(i in whichNum) + whichInt <- which(sapply(dat, function(x) { + is.numeric(x) && all(x == round(x)) + })) + for (i in whichNum) { - if(i \%in\% whichInt) - { - dat[[i]] <- format(dat[[i]], nsmall=0) - } else { - dat[[i]] <- format(dat[[i]], digits=digits, nsmall=digits) - } + if (i \%in\% whichInt) { + dat[[i]] <- format(dat[[i]], nsmall = 0) + } else { + dat[[i]] <- format(dat[[i]], digits = digits, nsmall = digits) + } } doc <- body_add_table(doc, dat, style = "Normal Table") print(doc, target = paste0(getwd(), "/myreport.docx")) -} - - -## -------------------------------------------------- -## derive the tables -## (here change drift and histSize values manually to get the -## different tables for the slides) -tab1 <- subset(wholeMatrix, - (drift==0.2) & - (histSize == 150) & - (method \%in\% ppNames)) + } + + + ## -------------------------------------------------- + ## derive the tables + ## (here change drift and histSize values manually to get the + ## different tables for the slides) + tab1 <- subset( + wholeMatrix, + (drift == 0.2) & + (histSize == 150) & + (method \%in\% ppNames) + ) } } diff --git a/man/oc3.Rd b/man/oc3.Rd index 6efcfea6..84c5b5bd 100644 --- a/man/oc3.Rd +++ b/man/oc3.Rd @@ -103,141 +103,165 @@ approximately equal distance between the looks. } \examples{ ## this looks OK now: -oc3(method="Prior.PP", - histSize=1e5L, - trialSize=100, - controlRateDist=function(){rbeta(n=1, 10, 10)}, - nmeRate=0.70, - nSim=20, - delta=0.15) +oc3( + method = "Prior.PP", + histSize = 1e5L, + trialSize = 100, + controlRateDist = function() { + rbeta(n = 1, 10, 10) + }, + nmeRate = 0.70, + nSim = 20, + delta = 0.15 +) ## this one as well: -oc3(method="Prior.Bayes", - histSize=1e6L, - trialSize=100, - controlRateDist=function(){rbeta(n=1, 10, 10)}, - nmeRate=0.65, - nSim=20, - delta=0.15) +oc3( + method = "Prior.Bayes", + histSize = 1e6L, + trialSize = 100, + controlRateDist = function() { + rbeta(n = 1, 10, 10) + }, + nmeRate = 0.65, + nSim = 20, + delta = 0.15 +) ## this example takes longer to run, therefore we don't execute it here: -if(FALSE) -{ -## the different methods we are looking at: -methods <- c("PointMass.Bayes", "Prior.Bayes", "RCT.Bayes", "RCTvanilla.Bayes", - "PointMass.PP", "Prior.PP", "RCT.PP", "RCTvanilla.PP") - -## the control rate will come from a Beta(10, 10) distribution -## and the historical data will be generated randomly from the resulting -## binomial distribution! - -## delta will be 0.15 - -## 200 simulations - -## the different prior sample sizes (historical data size) -## histSizes <- c(10, 20, 50, 150) -## later: add very large size, but with heterogeneity => -## mixture of beta priors -histSizes <- c(20, 150) - -## the trial sample size (total) -trialSizes <- c(40) - -## the different true rates for the NME: -## nmeRates <- seq(from=0.05, to=0.95, by=0.05) -nmeRates <- c(0.4, 0.5, 0.6, 0.7, 0.8) - -## so the whole grid is -wholeGrid <- expand.grid(method=methods, - histSize=histSizes, - trialSize=trialSizes, - nmeRate=nmeRates, stringsAsFactors = FALSE) - -## summarize the methods - -## compute the operating characteristics for all combinations -if(file.exists(savefile <- "allSims4.RData")) -{ +if (FALSE) { + ## the different methods we are looking at: + methods <- c( + "PointMass.Bayes", "Prior.Bayes", "RCT.Bayes", "RCTvanilla.Bayes", + "PointMass.PP", "Prior.PP", "RCT.PP", "RCTvanilla.PP" + ) + + ## the control rate will come from a Beta(10, 10) distribution + ## and the historical data will be generated randomly from the resulting + ## binomial distribution! + + ## delta will be 0.15 + + ## 200 simulations + + ## the different prior sample sizes (historical data size) + ## histSizes <- c(10, 20, 50, 150) + ## later: add very large size, but with heterogeneity => + ## mixture of beta priors + histSizes <- c(20, 150) + + ## the trial sample size (total) + trialSizes <- c(40) + + ## the different true rates for the NME: + ## nmeRates <- seq(from=0.05, to=0.95, by=0.05) + nmeRates <- c(0.4, 0.5, 0.6, 0.7, 0.8) + + ## so the whole grid is + wholeGrid <- expand.grid( + method = methods, + histSize = histSizes, + trialSize = trialSizes, + nmeRate = nmeRates, stringsAsFactors = FALSE + ) + + ## summarize the methods + + ## compute the operating characteristics for all combinations + if (file.exists(savefile <- "allSims4.RData")) { load(savefile) -} else { + } else { ## setup the result list - allOcs <- vector(mode="list", - length=nrow(wholeGrid)) + allOcs <- vector( + mode = "list", + length = nrow(wholeGrid) + ) - for(i in seq_len(nrow(wholeGrid))) + for (i in seq_len(nrow(wholeGrid))) { - set.seed(i) - allOcs[[i]] <- with(wholeGrid[i, ], - oc3(method=method, - histSize=histSize, - trialSize=trialSize, - controlRateDist=function(){rbeta(n=1, 10, 10)}, - nmeRate=nmeRate, - nSim=200, - delta=0.15)) + set.seed(i) + allOcs[[i]] <- with( + wholeGrid[i, ], + oc3( + method = method, + histSize = histSize, + trialSize = trialSize, + controlRateDist = function() { + rbeta(n = 1, 10, 10) + }, + nmeRate = nmeRate, + nSim = 200, + delta = 0.15 + ) + ) } save(allOcs, - file=savefile) -} + file = savefile + ) + } -length(allOcs) -allOcs + length(allOcs) + allOcs -allOcs[[1]] + allOcs[[1]] -allPossibleNames <- colnames(allOcs[[1]]) -allPossibleNames + allPossibleNames <- colnames(allOcs[[1]]) + allPossibleNames -allOcsMatrix <- -t(sapply(allOcs, - function(x){ - res <- rep(NA, length(allPossibleNames)) - names(res) <- allPossibleNames - res[colnames(x)] <- x - res - })) + allOcsMatrix <- + t(sapply( + allOcs, + function(x) { + res <- rep(NA, length(allPossibleNames)) + names(res) <- allPossibleNames + res[colnames(x)] <- x + res + } + )) -allOcsMatrix -wholeMatrix <- cbind(wholeGrid, allOcsMatrix) + allOcsMatrix + wholeMatrix <- cbind(wholeGrid, allOcsMatrix) -library(reshape) + library(reshape) -## write a table to a Word file in the current directory -outputTab <- function(tab, - out="output.docx", # name of the output file - digits=2) # how many digits for numbers? -{ + ## write a table to a Word file in the current directory + outputTab <- function(tab, + out = "output.docx", # name of the output file + digits = 2) # how many digits for numbers? + { library(officer) doc <- read_docx() dat <- as.data.frame(tab) whichNum <- which(sapply(dat, is.numeric)) - whichInt <- which(sapply(dat, function(x) {is.numeric(x) && all(x == round(x))})) - for(i in whichNum) + whichInt <- which(sapply(dat, function(x) { + is.numeric(x) && all(x == round(x)) + })) + for (i in whichNum) { - if(i \%in\% whichInt) - { - dat[[i]] <- format(dat[[i]], nsmall=0) - } else { - dat[[i]] <- format(dat[[i]], digits=digits, nsmall=digits) - } + if (i \%in\% whichInt) { + dat[[i]] <- format(dat[[i]], nsmall = 0) + } else { + dat[[i]] <- format(dat[[i]], digits = digits, nsmall = digits) + } } doc <- body_add_table(doc, dat, style = "Normal Table") writeDoc(doc, target = paste0(getwd(), "/myreport.docx")) -} - - -## -------------------------------------------------- -## derive the tables -## (here change drift and histSize values manually to get the -## different tables for the slides) -tab1 <- subset(wholeMatrix, - (histSize == 150) & - (method \%in\% ppNames)) + } + + + ## -------------------------------------------------- + ## derive the tables + ## (here change drift and histSize values manually to get the + ## different tables for the slides) + tab1 <- subset( + wholeMatrix, + (histSize == 150) & + (method \%in\% ppNames) + ) } } diff --git a/man/ocPostprob.Rd b/man/ocPostprob.Rd index bb95c5d0..a60b2d55 100644 --- a/man/ocPostprob.Rd +++ b/man/ocPostprob.Rd @@ -78,28 +78,36 @@ PrGrayZone: probability of no decision at the end ("gray zone") # multiple looks @ 10, 20, 30 patietns # True response rate of the treatment group=40\% # stop for futility: P(response rate < 20\% )> 60\% -#s top for efficacy: P(response rate > 30\% )> 80\% +# s top for efficacy: P(response rate > 30\% )> 80\% # prior of treatment arm parE= Beta(1,1) -res1<-ocPostprob(nn=c(10,20,30), p=0.4, p0=0.2, p1=0.3, tL=0.6, tU=0.8, - parE = c(1, 1), ns = 1000) +res1 <- ocPostprob( + nn = c(10, 20, 30), p = 0.4, p0 = 0.2, p1 = 0.3, tL = 0.6, tU = 0.8, + parE = c(1, 1), ns = 1000 +) res1$oc # this call will generate d (distance for random looks around the look locations) # based on "floor(min(nn - c(0,nn[-length(nn)]))/2)" as d is missing: -res2<-ocPostprob(nn=c(10,20,30), p=0.4, p0=0.2, p1=0.3, tL=0.6, tU=0.8, - parE = c(1, 1), ns = 1000, nr=TRUE) +res2 <- ocPostprob( + nn = c(10, 20, 30), p = 0.4, p0 = 0.2, p1 = 0.3, tL = 0.6, tU = 0.8, + parE = c(1, 1), ns = 1000, nr = TRUE +) res2$oc # now d is specified: -res3<-ocPostprob(nn=c(10,20,30), p=0.4, p0=0.2, p1=0.3, tL=0.6, tU=0.8, - parE = c(1, 1), ns = 1000, nr=TRUE, d=5) +res3 <- ocPostprob( + nn = c(10, 20, 30), p = 0.4, p0 = 0.2, p1 = 0.3, tL = 0.6, tU = 0.8, + parE = c(1, 1), ns = 1000, nr = TRUE, d = 5 +) res3$oc -# finally, we can also have separate specification of efficacy and +# finally, we can also have separate specification of efficacy and # futility analyses. E.g. here have futility decisions only at the final analysis: -res4<-ocPostprob(nn=c(10,20,30), p=0.4, p0=0.2, p1=0.3, tL=0.6, tU=0.8, - parE = c(1, 1), ns = 1000, nr=TRUE, d=5, - nnF=c(30)) +res4 <- ocPostprob( + nn = c(10, 20, 30), p = 0.4, p0 = 0.2, p1 = 0.3, tL = 0.6, tU = 0.8, + parE = c(1, 1), ns = 1000, nr = TRUE, d = 5, + nnF = c(30) +) res4$oc # compared to res3, we see that there is no early futility stopping anymore, # and the overall probability for stopping for futility (which is the type II error here) diff --git a/man/ocPostprobDist.Rd b/man/ocPostprobDist.Rd index 9dac7837..045a7bc5 100644 --- a/man/ocPostprobDist.Rd +++ b/man/ocPostprobDist.Rd @@ -84,20 +84,22 @@ PrFutility: probability to decide for futility PrGrayZone: probability of no decision at the end ("gray zone") } \examples{ -#operating characteristics for posterior probability method with beta prior on SOC +# operating characteristics for posterior probability method with beta prior on SOC -#design details -#multiple looks @ 10, 20, 30 patietns -#True response rate of the treatment group=0.4 +# design details +# multiple looks @ 10, 20, 30 patietns +# True response rate of the treatment group=0.4 # stop for efficacy (deltaE): P(pE > pS + deltaE) >tU # stop for futility (deltaF): P(pE < pS - deltaF) >tL -# where pE is the response rate of treatment group, pS is the response rate of +# where pE is the response rate of treatment group, pS is the response rate of # control group. Both of them are random variables. -res1<-ocPostprobDist(nn=c(10,20,30),p=0.4,deltaE=0.1,deltaF=-0.1,tL=0.6,tU=0.6, - parE=c(1,1),parS=c(5,25),ns=100) +res1 <- ocPostprobDist( + nn = c(10, 20, 30), p = 0.4, deltaE = 0.1, deltaF = -0.1, tL = 0.6, tU = 0.6, + parE = c(1, 1), parS = c(5, 25), ns = 100 +) res1$oc @@ -105,22 +107,28 @@ res1$oc # generate random look locations around 10,20,30 patients # this call will generate d (distance for random looks around the look locations) # based on "floor(min(nn - c(0,nn[-length(nn)]))/2)" as d is missing: -res2<-ocPostprobDist(nn=c(10,20,30),p=0.4,deltaE=0.1,deltaF=-0.1,tL=0.6,tU=0.6, - parE=c(1,1),parS=c(5,25),ns=100,nr=TRUE) +res2 <- ocPostprobDist( + nn = c(10, 20, 30), p = 0.4, deltaE = 0.1, deltaF = -0.1, tL = 0.6, tU = 0.6, + parE = c(1, 1), parS = c(5, 25), ns = 100, nr = TRUE +) res2$oc -#specify the distance for random looks around the look locations in nn (d=5 for illustration) -res3<-ocPostprobDist(nn=c(10,20,30),p=0.4,deltaE=0.1,deltaF=-0.1,tL=0.6,tU=0.6, - parE=c(1,1),parS=c(5,25),ns=100,nr=TRUE,d=5) +# specify the distance for random looks around the look locations in nn (d=5 for illustration) +res3 <- ocPostprobDist( + nn = c(10, 20, 30), p = 0.4, deltaE = 0.1, deltaF = -0.1, tL = 0.6, tU = 0.6, + parE = c(1, 1), parS = c(5, 25), ns = 100, nr = TRUE, d = 5 +) res3$oc -# finally, we can also have separate specification of efficacy and futility analyses. E.g. +# finally, we can also have separate specification of efficacy and futility analyses. E.g. # here have futility decisions only at the final analysis: -res4<-ocPostprobDist(nn=c(10,20,30),p=0.4,deltaE=0.1,deltaF=-0.1,tL=0.6,tU=0.6, - parE=c(1,1),parS=c(5,25),ns=100,nr=TRUE,d=5,nnF=c(30)) +res4 <- ocPostprobDist( + nn = c(10, 20, 30), p = 0.4, deltaE = 0.1, deltaF = -0.1, tL = 0.6, tU = 0.6, + parE = c(1, 1), parS = c(5, 25), ns = 100, nr = TRUE, d = 5, nnF = c(30) +) res4$oc # compared to res3, we see that there is no early futility stopping anymore, # and the overall probability for stopping for futility (which is the type II error here) diff --git a/man/ocPredprob.Rd b/man/ocPredprob.Rd index c2137341..e797f03f 100644 --- a/man/ocPredprob.Rd +++ b/man/ocPredprob.Rd @@ -93,31 +93,37 @@ PrGrayZone: probability of no decision at the end ("gray zone") } \examples{ ## to examine operating characteristics of a phase Ib design with 2 interim analyses -##(sample size @ 10, 20 using predictive probability) and one final analysis (sample size @ 30); +## (sample size @ 10, 20 using predictive probability) and one final analysis (sample size @ 30); -#design details -#multiple looks @ 10, 20, 30 patietns -#True response rate of the treatment group=40\% -#control response rate=25\% +# design details +# multiple looks @ 10, 20, 30 patietns +# True response rate of the treatment group=40\% +# control response rate=25\% -#denote treatment response rate as RRS -#trial success is defined as: P(RRS>control)>tT +# denote treatment response rate as RRS +# trial success is defined as: P(RRS>control)>tT set.seed(20) -res1<-ocPredprob(c(10,20,30), p=0.4, p0=0.25, tT=0.6, phiL=0.2, - phiU=0.8, parE = c(1, 1), ns = 100) +res1 <- ocPredprob(c(10, 20, 30), + p = 0.4, p0 = 0.25, tT = 0.6, phiL = 0.2, + phiU = 0.8, parE = c(1, 1), ns = 100 +) res1$oc # this call will generate d (distance for random looks around the look locations) # based on "floor(min(nn - c(0,nn[-length(nn)]))/2)" as d is missing: -res2<-ocPredprob(c(10,20,30),0.4,p0=0.25,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),ns=100,nr=TRUE) +res2 <- ocPredprob(c(10, 20, 30), 0.4, + p0 = 0.25, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), ns = 100, nr = TRUE +) res2$oc # now d is specified. note that d has to be a positive value; -res3<-ocPredprob(c(10,20,30),0.4,p0=0.25,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),ns=100,nr=TRUE,d=5) +res3 <- ocPredprob(c(10, 20, 30), 0.4, + p0 = 0.25, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), ns = 100, nr = TRUE, d = 5 +) res3$oc @@ -125,25 +131,29 @@ res3$oc # here have futility decisions only at the final analysis: -res4<-ocPredprob(c(10,20,30),0.4,p0=0.25,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),ns=100,nr=TRUE,d=5,nnF=c(30)) +res4 <- ocPredprob(c(10, 20, 30), 0.4, + p0 = 0.25, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), ns = 100, nr = TRUE, d = 5, nnF = c(30) +) res4$oc # compared to res3, we see that there is no early futility stopping anymore, # and the overall probability for stopping for futility (which is the type II error here) # is much lower. -#2) -#to examine operating characteristics of a phase Ib design with a seperate +# 2) +# to examine operating characteristics of a phase Ib design with a seperate # rule for futility at final analysis -#denote treatment response rate as RRS -#trial success is defined as: P(RRS>p0)>tT -#trial failure is defined as: P(RRStFu -#(gray zone could occur in the final analysis) +# denote treatment response rate as RRS +# trial success is defined as: P(RRS>p0)>tT +# trial failure is defined as: P(RRStFu +# (gray zone could occur in the final analysis) -#when tFu=1-tT and phiFu=1-phiL, this decisian rule (res5) is the same as the res1 +# when tFu=1-tT and phiFu=1-phiL, this decisian rule (res5) is the same as the res1 set.seed(20) -res5<-ocPredprob(c(10,20,30), p=0.4, p0=0.25, tT=0.6, tFu=0.4, phiFu=0.8, - phiU=0.8, parE = c(1, 1), ns = 100) +res5 <- ocPredprob(c(10, 20, 30), + p = 0.4, p0 = 0.25, tT = 0.6, tFu = 0.4, phiFu = 0.8, + phiU = 0.8, parE = c(1, 1), ns = 100 +) res5$oc } diff --git a/man/ocPredprobDist.Rd b/man/ocPredprobDist.Rd index 04fdab18..5911b8e6 100644 --- a/man/ocPredprobDist.Rd +++ b/man/ocPredprobDist.Rd @@ -101,36 +101,42 @@ PrGrayZone: probability of no decision at the end ("gray zone") } \examples{ ## to examine operating characteristics of a phase Ib design with 2 interim analyses -##(sample size @ 10, 20 using predictive probability) and one final analysis +## (sample size @ 10, 20 using predictive probability) and one final analysis ## (sample size @ 30); -#design details -#multiple looks @ 10, 20, 30 patients -#True response rate of the treatment group=0.4 -#response rate improvement (delta)=10\% as an absolute value (default) -#1) -#denote treatment response rate as RRS -#trial success is defined as: P(RRS>control+delta)>tT -#note: ns is suggested to be a larger value than 10 in a real study in order to -#achieve correct results +# design details +# multiple looks @ 10, 20, 30 patients +# True response rate of the treatment group=0.4 +# response rate improvement (delta)=10\% as an absolute value (default) +# 1) +# denote treatment response rate as RRS +# trial success is defined as: P(RRS>control+delta)>tT +# note: ns is suggested to be a larger value than 10 in a real study in order to +# achieve correct results set.seed(20) -res1<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),parS=c(5,25),ns=10) +res1 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), parS = c(5, 25), ns = 10 +) res1$oc -#this function will generate d based on "floor(min(nn - c(0,nn[-length(nn)]))/2)" -#if d is missing -res2<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),parS=c(5,25),ns=10,nr=TRUE) +# this function will generate d based on "floor(min(nn - c(0,nn[-length(nn)]))/2)" +# if d is missing +res2 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), parS = c(5, 25), ns = 10, nr = TRUE +) res2$oc -#note that d has to be a positive value; -res3<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),parS=c(5,25),ns=10,nr=TRUE,d=5) +# note that d has to be a positive value; +res3 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), parS = c(5, 25), ns = 10, nr = TRUE, d = 5 +) res3$oc @@ -138,38 +144,45 @@ res3$oc # here have futility decisions only at the final analysis: -res4<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,tT=0.6,phiL=0.2,phiU=0.8, - parE=c(1,1),parS=c(5,25),ns=10,nr=TRUE,d=5,nnF=c(30)) +res4 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, tT = 0.6, phiL = 0.2, phiU = 0.8, + parE = c(1, 1), parS = c(5, 25), ns = 10, nr = TRUE, d = 5, nnF = c(30) +) res4$oc # compared to res3, we see that there is no early futility stopping anymore, # and the overall probability for stopping for futility (which is the type II error here) # is much lower. -#2) -#to examine operating characteristics of a phase Ib design with a -#seperate rule for futility at final analysis -#denote treatment response rate as RRS -#trial success is defined as: P(RRS>control+delta)>tT -#trial failure is defined as: P(RRStFu -#(gray zone could occur in the final analysis) +# 2) +# to examine operating characteristics of a phase Ib design with a +# seperate rule for futility at final analysis +# denote treatment response rate as RRS +# trial success is defined as: P(RRS>control+delta)>tT +# trial failure is defined as: P(RRStFu +# (gray zone could occur in the final analysis) set.seed(20) -res5<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,deltaFu = 0.05,tT=0.6,tFu=0.6, phiFu=0.8, - phiU=0.8, parE=c(1,1),parS=c(5,25),ns=10) +res5 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, deltaFu = 0.05, tT = 0.6, tFu = 0.6, phiFu = 0.8, + phiU = 0.8, parE = c(1, 1), parS = c(5, 25), ns = 10 +) res5$oc -#when tFu=1-tT and phiFu=1-phiL, this decisian rule (res6) is the same as the res1 +# when tFu=1-tT and phiFu=1-phiL, this decisian rule (res6) is the same as the res1 set.seed(20) -res6<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,tT=0.6,tFu=0.4, phiFu=0.8,phiU=0.8, - parE=c(1,1),parS=c(5,25),ns=10) +res6 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, tT = 0.6, tFu = 0.4, phiFu = 0.8, phiU = 0.8, + parE = c(1, 1), parS = c(5, 25), ns = 10 +) res6$oc -#If both phiL and phiFu arguments are specified, phiL will be overwrite by 1-phiFu. +# If both phiL and phiFu arguments are specified, phiL will be overwrite by 1-phiFu. # See warning message. set.seed(20) -res7<-ocPredprobDist(c(10,20,30),0.4,delta=0.1,tT=0.6,tFu=0.4, phiL=0.1,phiFu=0.8,phiU=0.8, - parE=c(1,1),parS=c(5,25),ns=10) +res7 <- ocPredprobDist(c(10, 20, 30), 0.4, + delta = 0.1, tT = 0.6, tFu = 0.4, phiL = 0.1, phiFu = 0.8, phiU = 0.8, + parE = c(1, 1), parS = c(5, 25), ns = 10 +) res7$oc - } diff --git a/man/ocRctPostprobDist.Rd b/man/ocRctPostprobDist.Rd index 30b704a2..35dd2916 100644 --- a/man/ocRctPostprobDist.Rd +++ b/man/ocRctPostprobDist.Rd @@ -107,55 +107,63 @@ PrFutility: probability to decide for futility PrGrayZone: probability of no decision at the end ("gray zone") } \examples{ -#note, deltaF has to be a value between 0 and 1 including the bounds, or NULL. +# note, deltaF has to be a value between 0 and 1 including the bounds, or NULL. -res<-ocRctPostprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, deltaE=0.15,deltaF=0.05, - relativeDelta=FALSE, - tL=0.8, tU=0.8, - parE=c(a=1, b=1), - parS=c(a=1, b=1), - randRatio=1, - ns = 100, nr = FALSE, d = NULL) +res <- ocRctPostprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, deltaE = 0.15, deltaF = 0.05, + relativeDelta = FALSE, + tL = 0.8, tU = 0.8, + parE = c(a = 1, b = 1), + parS = c(a = 1, b = 1), + randRatio = 1, + ns = 100, nr = FALSE, d = NULL +) res$oc -# separate specification of efficacy and futility analyses can be performed. E.g. +# separate specification of efficacy and futility analyses can be performed. E.g. # here have futility decisions only at the final analysis: -res2<-ocRctPostprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, deltaE=0.15,deltaF=0.05, - relativeDelta=FALSE, - tL=0.8, tU=0.8, - parE=c(a=1, b=1), - parS=c(a=1, b=1), - randRatio=1, - ns = 100, nr = FALSE, d = NULL,nnF=c(30)) +res2 <- ocRctPostprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, deltaE = 0.15, deltaF = 0.05, + relativeDelta = FALSE, + tL = 0.8, tU = 0.8, + parE = c(a = 1, b = 1), + parS = c(a = 1, b = 1), + randRatio = 1, + ns = 100, nr = FALSE, d = NULL, nnF = c(30) +) res2$oc # compared to res3, we see that there is no early futility stopping anymore, # and the overall probability for stopping for futility (which is the type II error here) # is much lower. -# Also, when deltaF is set to NULL, the futility decision is made when the probability to +# Also, when deltaF is set to NULL, the futility decision is made when the probability to # be deltaE better than the control is lower than 1 - tL. i.e. Pr(pE-pS>deltaE)<1-tL -res3<-ocRctPostprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, deltaE=0.15,deltaF=NULL, - relativeDelta=FALSE, - tL=0.2, tU=0.8, - parE=c(a=1, b=1), - parS=c(a=1, b=1), - randRatio=1, - ns = 100, nr = FALSE, d = NULL) +res3 <- ocRctPostprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, deltaE = 0.15, deltaF = NULL, + relativeDelta = FALSE, + tL = 0.2, tU = 0.8, + parE = c(a = 1, b = 1), + parS = c(a = 1, b = 1), + randRatio = 1, + ns = 100, nr = FALSE, d = NULL +) res3$oc # As when deltaF is set to null, it sometimes makes sense for a futility decision # to be made even when the treatment is better than the control, e.g. when that difference # is small. This can be accomplished by specifying a negative value for deltaF. -res4 <- ocRctPostprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, - deltaE=0.15, deltaF=-0.05, - relativeDelta=FALSE, - tL=0.2, tU=0.8, - parE=c(a=1, b=1), - parS=c(a=1, b=1), - randRatio=1, - ns = 100, nr = FALSE, d = NULL) +res4 <- ocRctPostprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, + deltaE = 0.15, deltaF = -0.05, + relativeDelta = FALSE, + tL = 0.2, tU = 0.8, + parE = c(a = 1, b = 1), + parS = c(a = 1, b = 1), + randRatio = 1, + ns = 100, nr = FALSE, d = NULL +) res4$oc } diff --git a/man/ocRctPredprobDist.Rd b/man/ocRctPredprobDist.Rd index fd02a1e2..8d4b46fb 100644 --- a/man/ocRctPredprobDist.Rd +++ b/man/ocRctPredprobDist.Rd @@ -118,50 +118,56 @@ PrFutility: probability to decide for futility PrGrayZone: probability of no decision at the end ("gray zone") } \examples{ -#similar input parameters as the oc.predprobDist function -#default simulation number is 10000. for illustration, the ns is set as 100 to -#save program running time. Please note that 10 simulation run (ns=10) may not -#be sufficient for a consistent OC evaluation. -#1) +# similar input parameters as the oc.predprobDist function +# default simulation number is 10000. for illustration, the ns is set as 100 to +# save program running time. Please note that 10 simulation run (ns=10) may not +# be sufficient for a consistent OC evaluation. +# 1) set.seed(20) -res<-ocRctPredprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, delta=0.1, - relativeDelta=FALSE, tT=0.6, - phiL=0.2, phiU=0.8, - parE=c(a=1, b=1), parS=c(a=1, b=1), - randRatio=1, - ns = 10, nr = FALSE, d = NULL) +res <- ocRctPredprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, delta = 0.1, + relativeDelta = FALSE, tT = 0.6, + phiL = 0.2, phiU = 0.8, + parE = c(a = 1, b = 1), parS = c(a = 1, b = 1), + randRatio = 1, + ns = 10, nr = FALSE, d = NULL +) res$oc -# separate specification of efficacy and futility analyses can be performed. E.g. +# separate specification of efficacy and futility analyses can be performed. E.g. # here have futility decisions only at the final analysis: set.seed(20) -res1<-ocRctPredprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, delta=0.1, relativeDelta=FALSE, - tT=0.6, - phiL=0.2, phiU=0.8, - parE=c(a=1, b=1), parS=c(a=1, b=1), - randRatio=1, - ns = 10, nr = FALSE, d = NULL,nnF=c(30)) +res1 <- ocRctPredprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, delta = 0.1, relativeDelta = FALSE, + tT = 0.6, + phiL = 0.2, phiU = 0.8, + parE = c(a = 1, b = 1), parS = c(a = 1, b = 1), + randRatio = 1, + ns = 10, nr = FALSE, d = NULL, nnF = c(30) +) res1$oc -#2) -#to examine operating characters of a phase Ib design with a -#seperate rule for futility -#at final analysis -#denote treatment response rate as RRS -#trial success is defined as: P(RRS>control+delta)>tT -#trial failure is defined as: P(RRStFu -#(gray zone could occur in the final analysis) +# 2) +# to examine operating characters of a phase Ib design with a +# seperate rule for futility +# at final analysis +# denote treatment response rate as RRS +# trial success is defined as: P(RRS>control+delta)>tT +# trial failure is defined as: P(RRStFu +# (gray zone could occur in the final analysis) set.seed(20) -res2<-ocRctPredprobDist(nn=c(10,20,30), pE=0.4, pS=0.3, delta=0.1, deltaFu=0.05, - relativeDelta=FALSE, - tT=0.6,tFu=0.6, - phiFu=0.8, phiU=0.8, - parE=c(a=1, b=1), parS=c(a=1, b=1), - randRatio=1, - ns = 10, nr = FALSE, d = NULL) +res2 <- ocRctPredprobDist( + nn = c(10, 20, 30), pE = 0.4, pS = 0.3, delta = 0.1, deltaFu = 0.05, + relativeDelta = FALSE, + tT = 0.6, tFu = 0.6, + phiFu = 0.8, phiU = 0.8, + parE = c(a = 1, b = 1), parS = c(a = 1, b = 1), + randRatio = 1, + ns = 10, nr = FALSE, d = NULL +) res2$oc } diff --git a/man/pbetaMix.Rd b/man/pbetaMix.Rd index 2990548c..2b875742 100644 --- a/man/pbetaMix.Rd +++ b/man/pbetaMix.Rd @@ -14,8 +14,8 @@ corresponding to the beta parameters of the K components} \item{weights}{the mixture weights of the beta mixture prior} -\item{lower.tail}{logical; if TRUE (default), probabilities are P\link{X <= x}, -and otherwise P\link{X > x}} +\item{lower.tail}{logical; if TRUE (default), probabilities are \code{P[X <= x]}, +and otherwise \code{P[X > x]}} } \value{ the (one minus) cdf value diff --git a/man/plotBounds.Rd b/man/plotBounds.Rd index 71fd2d5c..92b38a4c 100644 --- a/man/plotBounds.Rd +++ b/man/plotBounds.Rd @@ -31,8 +31,8 @@ is "x"} \item{add}{add the boundary lines or not} -\item{cols}{specific the color of \link{1} efficacy area \link{2} futility area -\link{3} efficacy boundary \link{4} futility boundary} +\item{cols}{specific the color of \verb{[1]} efficacy area \verb{[2]} futility area +\verb{[3]} efficacy boundary \verb{[4]} futility boundary} \item{lwds}{line width (a two dimensional vector)} @@ -56,12 +56,19 @@ and \code{\link{boundsPostprob}} } \examples{ # 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") -plotBounds(boundsPostprob(nvec=c(10,20,30,40), p0=0.20, - tL=0.10, tU=0.90, a=1, b=1), - yt="p", add=TRUE) +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") +plotBounds(boundsPostprob( + nvec = c(10, 20, 30, 40), p0 = 0.20, + tL = 0.10, tU = 0.90, a = 1, b = 1 +), +yt = "p", add = TRUE +) } \keyword{graphics} diff --git a/man/plotDecision.Rd b/man/plotDecision.Rd index 88325829..7465a052 100644 --- a/man/plotDecision.Rd +++ b/man/plotDecision.Rd @@ -22,8 +22,8 @@ and a curve of the prob of a poor improvement over estunated diff } \examples{ -summaries<-do.call(cbind,lapply(c(0:8),sumTable,TotalSample=25,parX=c(1,52),cut_B=0.2,cut_W=0.05)) +summaries <- do.call(cbind, lapply(c(0:8), sumTable, TotalSample = 25, parX = c(1, 52), cut_B = 0.2, cut_W = 0.05)) -plotDecision(summaries,Pos_cut=60,Neg_cut=60) +plotDecision(summaries, Pos_cut = 60, Neg_cut = 60) } \keyword{graphics} diff --git a/man/plotOc.Rd b/man/plotOc.Rd index 50816c37..67bef454 100644 --- a/man/plotOc.Rd +++ b/man/plotOc.Rd @@ -17,9 +17,9 @@ Reads results from \code{\link{ocPredprob}}, \code{\link{ocPostprob}} etc. and displays a bar plot of the operating characteristics } \examples{ -#get operating character result from oc.postprob +# get operating character result from oc.postprob -res1<-ocPostprob(nn=c(10,20,30), p=0.4, p0=0.2, p1=0.3, tL=0.6, tU=0.8, parE = c(1, 1), ns = 10000) +res1 <- ocPostprob(nn = c(10, 20, 30), p = 0.4, p0 = 0.2, p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), ns = 10000) res1$oc plotOc(res1) diff --git a/man/postprob.Rd b/man/postprob.Rd index 6b5deb33..a19ea1b9 100644 --- a/man/postprob.Rd +++ b/man/postprob.Rd @@ -31,9 +31,9 @@ the other arguments (except \code{p} and \code{log.p} of course)} The posterior probability that the response rate P_E is above p. } \description{ -Computes the posterior probability Pr(P_E > p | data). Prior is P_E ~ -sum(weights * beta(parE\link{, 1}, parE\link{, 2})), i.e., a mixture of beta priors. -Default is one component only with uniform or beta(1,1). +Computes the posterior probability \code{Pr(P_E > p | data)}. Prior is +\code{P_E ~ sum(weights * beta(parE[, 1], parE[, 2]))}, i.e., a mixture of beta priors. +Default is one component only with uniform or \code{beta(1,1)}. } \details{ We observed x successes in n trials. Note that \code{x} can be a vector. @@ -51,7 +51,7 @@ and beta parameters. ## Pr(P_E > p | data) = 0.836 ## -postprob(x=16, n=23, p=0.60, par=c(0.6, 0.4)) +postprob(x = 16, n = 23, p = 0.60, par = c(0.6, 0.4)) ## We could instead specify a mixture prior ## 2 component beta mixture prior, i.e., @@ -59,10 +59,13 @@ postprob(x=16, n=23, p=0.60, par=c(0.6, 0.4)) ## Pr(P_E > p | data) = 0.823 ## -postprob(x=16, n=23, p=0.60, - par= - rbind(c(0.6, 0.4), - c(1, 1)), - weights=c(0.6, 0.4)) - +postprob( + x = 16, n = 23, p = 0.60, + par = + rbind( + c(0.6, 0.4), + c(1, 1) + ), + weights = c(0.6, 0.4) +) } diff --git a/man/postprobDist.Rd b/man/postprobDist.Rd index 0af127ba..4658f604 100644 --- a/man/postprobDist.Rd +++ b/man/postprobDist.Rd @@ -73,16 +73,18 @@ treatment is e.g. important for the futility decision making (see the } \examples{ ## example similar to Lee and Liu: -postprobDist(x=16, n=23, parE=c(0.6, 0.4), parS=c(0.6, 0.4)) +postprobDist(x = 16, n = 23, parE = c(0.6, 0.4), parS = c(0.6, 0.4)) ## these two should give the same result: -postprobDist(x = 27, n = 34, - xS = 0, nS = 0, - delta = 0.15, - parE = c(1, 1), - parS = c(50007530, 49924090)) +postprobDist( + x = 27, n = 34, + xS = 0, nS = 0, + delta = 0.15, + parE = c(1, 1), + parS = c(50007530, 49924090) +) -postprob(x=27, n=34, p=0.65, parE=c(1, 1)) +postprob(x = 27, n = 34, p = 0.65, parE = c(1, 1)) ## ok, almost ## try out mixtures: @@ -91,12 +93,18 @@ postprob(x=27, n=34, p=0.65, parE=c(1, 1)) ## Note that very extreme beta parameters do no longer increase ## the return value, because then that mixture component is too ## unlikely a posteriori -postprobDist(x=16, n=23, - parE= - rbind(c(0.6, 0.4), - c(10, 20)), - parS= - rbind(c(0.6, 0.4), - c(10, 10)), - weightsS=c(1, 3)) +postprobDist( + x = 16, n = 23, + parE = + rbind( + c(0.6, 0.4), + c(10, 20) + ), + parS = + rbind( + c(0.6, 0.4), + c(10, 10) + ), + weightsS = c(1, 3) +) } diff --git a/man/postprobOld.Rd b/man/postprobOld.Rd index 9dd15b37..c2cbab63 100644 --- a/man/postprobOld.Rd +++ b/man/postprobOld.Rd @@ -39,5 +39,5 @@ P_E | data ~ beta(a + x, b + n - x). ## Pr(P_E > p | data) = 0.8358808 ## -postprobOld(x=16, n=23, p=0.60, a=0.6, b=0.4) +postprobOld(x = 16, n = 23, p = 0.60, a = 0.6, b = 0.4) } diff --git a/man/predprob.Rd b/man/predprob.Rd index 756a7840..3512b2a1 100644 --- a/man/predprob.Rd +++ b/man/predprob.Rd @@ -50,34 +50,42 @@ b: Pr(P_E > p | x, Y=i) using beta (mixture) posterior bgttheta: indicator I(b>thetaT) } \examples{ -## The original Lee and Liu (Table 1) example: +## The original Lee and Liu (Table 1) example: ## Nmax=40, x=16, n=23, beta(0.6,0.4) prior distribution, ## thetaT=0.9. The control response rate is 60\%: -predprob(x=16, n=23, Nmax=40, p=0.6, thetaT=0.9, - parE=c(0.6, 0.4)) +predprob( + x = 16, n = 23, Nmax = 40, p = 0.6, thetaT = 0.9, + parE = c(0.6, 0.4) +) ## So the predictive probability is 56.6\%. 12 responses ## in the remaining 17 patients are required for success. ## Lowering/Increasing the probability threshold thetaT of course increases ## /decreases the predictive probability of success, respectively: -predprob(x=16, n=23, Nmax=40, p=0.6, thetaT=0.8, - parE=c(0.6, 0.4)) +predprob( + x = 16, n = 23, Nmax = 40, p = 0.6, thetaT = 0.8, + parE = c(0.6, 0.4) +) ## 70.8\% -predprob(x=16, n=23, Nmax=40, p=0.6, thetaT=0.95, - parE=c(0.6, 0.4)) +predprob( + x = 16, n = 23, Nmax = 40, p = 0.6, thetaT = 0.95, + parE = c(0.6, 0.4) +) ## 40.7\% ## Instead of a fixed beta prior on the response rate, dynamic borrowing ## from a previous data set is possible by using a beta-mixture prior. ## For example, assume we have a previous trial where we saw 25 responses ## in 40 patients. We would like to use information worth 10 patients in our -## trial, but be robust against deviations from that response rate (maybe +## trial, but be robust against deviations from that response rate (maybe ## because it was conducted in slightly different disease or patients). ## Then we can use a beta mixture prior, with the informative component getting ## weight of 1/4: -predprob(x=20, n=23, Nmax=40, p=0.6, thetaT=0.9, - parE=rbind(c(1, 1), c(25, 15)), - weights=c(3, 1)) +predprob( + x = 20, n = 23, Nmax = 40, p = 0.6, thetaT = 0.9, + parE = rbind(c(1, 1), c(25, 15)), + weights = c(3, 1) +) ## Since the response rate in the historical dataset is lower (62.5\% < 69.6\%) ## than in the trial, but similar, we notice that the predictive probability ## of success is now lower. diff --git a/man/predprobDist.Rd b/man/predprobDist.Rd index 639f96e7..88932f6e 100644 --- a/man/predprobDist.Rd +++ b/man/predprobDist.Rd @@ -95,61 +95,70 @@ b: matrix with Pr(P_E > P_S + delta | x, xS, Y=i, Z=j) bgttheta: matrix of indicators I(b>thetaT) } \examples{ -## The original Lee and Liu (Table 1) example: +## The original Lee and Liu (Table 1) example: ## Nmax=40, x=16, n=23, beta(0.6,0.4) prior distribution, ## thetaT=0.9. The control response rate is 60\%: -predprob(x=16, n=23, Nmax=40, p=0.6, thetaT=0.9, - parE=c(0.6, 0.4)) +predprob( + x = 16, n = 23, Nmax = 40, p = 0.6, thetaT = 0.9, + parE = c(0.6, 0.4) +) ## So the predictive probability is 56.6\%. 12 responses ## in the remaining 17 patients are required for success. -## Now to the modified example, where the control response +## Now to the modified example, where the control response ## rate p has a beta(7, 11) distribution. ## For example if the 60\% threshold stems from a trial ## with 10 patients, of which 6 were observed with response. -predprobDist(x=16, n=23, Nmax=40, delta=0, thetaT=0.9, - parE=c(0.6, 0.4), parS=c(7, 11)) +predprobDist( + x = 16, n = 23, Nmax = 40, delta = 0, thetaT = 0.9, + parE = c(0.6, 0.4), parS = c(7, 11) +) ## Now only 11 responses are needed in the remaining 17 patients -## in order to have a successful trial. +## in order to have a successful trial. ## Also, the predictive probability for a Go decision is now ## 70.8\% instead of merely 56.6\%. ## If the response threshold of 60\% stems from an SOC estimate (e.g. 50\% = 5/10) ## and a margin of e.g. 10\%, then the margin can be specified with ## the delta argument: -predprobDist(x=16, n=23, Nmax=40, delta=0.1, thetaT=0.9, - parE=c(1, 1), parS=c(6, 11)) +predprobDist( + x = 16, n = 23, Nmax = 40, delta = 0.1, thetaT = 0.9, + parE = c(1, 1), parS = c(6, 11) +) ## This again changes the result: Only 10 future responses are required, ## the predictive probability of success is now 80\%. ## Next we will use a beta mixture prior, with a weight of 1/3 for an ## informative beta(50, 10) prior, on the experimental response rate: -predprobDist(x=16, n=23, Nmax=40, delta=0.1, thetaT=0.9, - parE=rbind(c(1, 1), c(50, 10)), - weights=c(2, 1), parS=c(6, 11)) +predprobDist( + x = 16, n = 23, Nmax = 40, delta = 0.1, thetaT = 0.9, + parE = rbind(c(1, 1), c(50, 10)), + weights = c(2, 1), parS = c(6, 11) +) ## Now still 10 future responses are required for success, but the predictive ## success probability is higher (87.2\%). ## We can also have additional controls in our trial. For example ## assume that in the interim analysis we had 10 control patients observed -## with 5 responses out of 20 in total at the end. +## with 5 responses out of 20 in total at the end. ## We also had historical control data (say 60 patients of -## which 20 responded), but in order to be robust against changes in the response +## which 20 responded), but in order to be robust against changes in the response # rate over time, we will again use a beta mixture, putting only 1/3 of weight ## on the historical controls: -predprobDist(x=16, n=23, xS=5, nS=10, - Nmax=40, NmaxControl=20, - delta=0.1, thetaT=0.9, - parE=rbind(c(1, 1), c(50, 10)), - weights=c(2, 1), - parS=rbind(c(1, 1), c(20, 40)), - weightsS=c(2, 1)) +predprobDist( + x = 16, n = 23, xS = 5, nS = 10, + Nmax = 40, NmaxControl = 20, + delta = 0.1, thetaT = 0.9, + parE = rbind(c(1, 1), c(50, 10)), + weights = c(2, 1), + parS = rbind(c(1, 1), c(20, 40)), + weightsS = c(2, 1) +) ## Now we only have 59.9\% predictive probability of success. The bgttheta matrix ## lists the cases where we would have success, for all possible combinations -## of future responses in the control and experimental arms. We see that the -## success threshold for experimental responses depends on the number of +## of future responses in the control and experimental arms. We see that the +## success threshold for experimental responses depends on the number of ## control responses. - } \references{ Lee, J. J., & Liu, D. D. (2008). A predictive probability diff --git a/man/sumBetadiff.Rd b/man/sumBetadiff.Rd index ee5c4cac..e99f7936 100644 --- a/man/sumBetadiff.Rd +++ b/man/sumBetadiff.Rd @@ -27,5 +27,5 @@ A function to summerize the characters of a betadiff distribution \code{\link{be \examples{ parX <- c(1, 52) parY <- c(5.5, 20.5) -sumBetadiff(parX,parY,0.9,cutB=0.8,cutW=0.2) +sumBetadiff(parX, parY, 0.9, cutB = 0.8, cutW = 0.2) } diff --git a/man/sumTable.Rd b/man/sumTable.Rd index f2481b26..e09f7722 100644 --- a/man/sumTable.Rd +++ b/man/sumTable.Rd @@ -38,9 +38,9 @@ outcome scenario. } \examples{ -sumTable(2,25,parX=c(1,52),cut_B=0.2,cut_W=0.05,YPri=c(1,1)) +sumTable(2, 25, parX = c(1, 52), cut_B = 0.2, cut_W = 0.05, YPri = c(1, 1)) -#for multiple response scenarios (e.g. 0 to 8 responses out of 25) -summaries<-do.call(cbind,lapply(c(0:8),sumTable,TotalSample=25,parX=c(1,52),cut_B=0.2,cut_W=0.05)) +# for multiple response scenarios (e.g. 0 to 8 responses out of 25) +summaries <- do.call(cbind, lapply(c(0:8), sumTable, TotalSample = 25, parX = c(1, 52), cut_B = 0.2, cut_W = 0.05)) summaries }