From 26d9870a7520efc11aa3118c9ed040df2fdb7292 Mon Sep 17 00:00:00 2001 From: Yilong Zhang Date: Sat, 24 Jun 2023 04:08:54 +0000 Subject: [PATCH 01/13] move functions to internal - h1 - hupdate - gridpts --- NAMESPACE | 3 - R/gridpts_h1_hupdate.R | 6 +- R/gs_spending_bound.R | 33 ---------- _pkgdown.yml | 3 - inst/old_function/gs_power_npe_.R | 5 +- man/gridpts.Rd | 58 ----------------- man/gs_spending_bound.Rd | 33 ---------- man/h1.Rd | 53 ---------------- man/hupdate.Rd | 62 ------------------- vignettes/articles/story-npe-integration.Rmd | 12 ++-- .../articles/usage-gs-spending-bound.Rmd | 4 +- 11 files changed, 13 insertions(+), 259 deletions(-) delete mode 100644 man/gridpts.Rd delete mode 100644 man/h1.Rd delete mode 100644 man/hupdate.Rd diff --git a/NAMESPACE b/NAMESPACE index 44bdd055..1d97215a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,7 +14,6 @@ export(expected_accrual) export(expected_event) export(expected_time) export(fixed_design) -export(gridpts) export(gs_b) export(gs_create_arm) export(gs_design_ahr) @@ -33,8 +32,6 @@ export(gs_power_rd) export(gs_power_wlr) export(gs_spending_bound) export(gs_spending_combo) -export(h1) -export(hupdate) export(ppwe) export(s2pwe) export(to_integer) diff --git a/R/gridpts_h1_hupdate.R b/R/gridpts_h1_hupdate.R index 8a5137e3..4d410ed2 100644 --- a/R/gridpts_h1_hupdate.R +++ b/R/gridpts_h1_hupdate.R @@ -51,7 +51,7 @@ #' } #' \if{html}{The contents of this section are shown in PDF user manual only.} #' -#' @export +#' @noRd #' #' @examples #' # Approximate variance of standard normal (i.e., 1) @@ -93,7 +93,7 @@ gridpts <- function(r = 18, mu = 0, a = -Inf, b = Inf) { #' } #' \if{html}{The contents of this section are shown in PDF user manual only.} #' -#' @export +#' @noRd #' #' @examples #' # Replicate variance of 1, mean of 35 @@ -137,7 +137,7 @@ h1 <- function(r = 18, theta = 0, info = 1, a = -Inf, b = Inf) { #' } #' \if{html}{The contents of this section are shown in PDF user manual only.} #' -#' @export +#' @noRd #' #' @examples #' # 2nd analysis with no interim bound and drift 0 should have mean 0, variance 1 diff --git a/R/gs_spending_bound.R b/R/gs_spending_bound.R index 1276b1da..a85d0c54 100644 --- a/R/gs_spending_bound.R +++ b/R/gs_spending_bound.R @@ -81,39 +81,6 @@ #' @importFrom stats qnorm #' #' @export -#' -#' @examples -#' info <- (1:3) * 10 -#' info_frac <- info / max(info) -#' k <- length(info_frac) -#' -#' # 1st analysis -#' a1 <- gs_spending_bound( -#' k = 1, efficacy = FALSE, theta = 0, -#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' hgm1 = NULL -#' ) -#' -#' b1 <- gs_spending_bound( -#' k = 1, efficacy = TRUE, theta = 0, -#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' hgm1 = NULL -#' ) -#' cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n") -#' -#' # 2nd analysis -#' a2 <- gs_spending_bound( -#' k = 2, efficacy = FALSE, theta = 0, -#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' hgm1 = h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -#' ) -#' -#' b2 <- gs_spending_bound( -#' k = 2, efficacy = TRUE, theta = 0, -#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' hgm1 = h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -#' ) -#' cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") gs_spending_bound <- function(k = 1, par = list( sf = gsDesign::sfLDOF, diff --git a/_pkgdown.yml b/_pkgdown.yml index 2991dd63..386d8d46 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -97,9 +97,6 @@ reference: - expected_accrual - ppwe - s2pwe - - gridpts - - h1 - - hupdate - gs_create_arm articles: diff --git a/inst/old_function/gs_power_npe_.R b/inst/old_function/gs_power_npe_.R index a8e6112a..e09f1931 100644 --- a/inst/old_function/gs_power_npe_.R +++ b/inst/old_function/gs_power_npe_.R @@ -255,15 +255,14 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf 0 } - # hgm1_0 <- h1(r = r, theta = 0, info = info0[1], a = if(binding){a[1]}else{-Inf}, b = b[1]) hgm1_0 <- h1(r = r, theta = 0, info = info0[1], a = if (binding) { a[1] } else { -Inf }, b = b[1]) - # hgm1_1 <- h1(r = r, theta = theta1[1], info = info1[1], a = a[1], b = b[1]) + hgm1_1 <- h1(r = r, theta = theta1[1], info = info1[1], a = a[1], b = b[1]) - # hgm1 <- h1(r = r, theta = theta[1], info = info[1], a = a[1], b = b[1]) + hgm1 <- h1(r = r, theta = theta[1], info = info[1], a = a[1], b = b[1]) } else { # Cross upper bound diff --git a/man/gridpts.Rd b/man/gridpts.Rd deleted file mode 100644 index 3d2ccdc6..00000000 --- a/man/gridpts.Rd +++ /dev/null @@ -1,58 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gridpts_h1_hupdate.R -\name{gridpts} -\alias{gridpts} -\title{Grid points for group sequential design numerical integration} -\usage{ -gridpts(r = 18, mu = 0, a = -Inf, b = Inf) -} -\arguments{ -\item{r}{Integer, at least 2; default of 18 recommended by Jennison and Turnbull.} - -\item{mu}{Mean of normal distribution (scalar) under consideration.} - -\item{a}{Lower limit of integration (scalar).} - -\item{b}{Upper limit of integration (scalar \verb{> a}).} -} -\value{ -A list with grid points in \code{z} and numerical integration weights in \code{w}. -} -\description{ -Points and weights for Simpson's rule numerical integration from -p 349--350 of Jennison and Turnbull book. -This is not used for arbitrary integration, but for the canonical form of Jennison and Turnbull. -mu is computed elsewhere as drift parameter times sqrt of information. -Since this is a lower-level routine, no checking of input is done; calling routines should -ensure that input is correct. -Lower limit of integration can be \code{-Inf} and upper limit of integration can be \code{Inf}. -} -\details{ -Jennison and Turnbull (p 350) claims accuracy of \code{10e-6} with \code{r=16}. -The numerical integration grid spreads out at the tail to enable accurate tail probability calculations. -} -\section{Specification}{ - -\if{latex}{ - \itemize{ - \item Define odd numbered grid points for real line. - \item Trim points outside of $[a, b]$ and include those points. - \item If extreme, include only 1 point where density will be essentially 0. - \item Define even numbered grid points between the odd ones. - \item Compute weights for odd numbered grid points. - \item Combine odd- and even-numbered grid points with their corresponding weights. - \item Return a tibble of with grid points in z and numerical integration weights in z. - } -} -\if{html}{The contents of this section are shown in PDF user manual only.} -} - -\examples{ -# Approximate variance of standard normal (i.e., 1) -g <- gridpts() -sum((g$z)^2 * g$w * dnorm(g$z)) - -# Approximate probability above .95 quantile (i.e., 0.05) -g <- gridpts(a = qnorm(0.95), b = Inf) -sum(g$w * dnorm(g$z)) -} diff --git a/man/gs_spending_bound.Rd b/man/gs_spending_bound.Rd index 2cf99be6..9d4159e1 100644 --- a/man/gs_spending_bound.Rd +++ b/man/gs_spending_bound.Rd @@ -85,39 +85,6 @@ that in Chapter 19 of Jennison and Turnbull (2000). \if{html}{The contents of this section are shown in PDF user manual only.} } -\examples{ -info <- (1:3) * 10 -info_frac <- info / max(info) -k <- length(info_frac) - -# 1st analysis -a1 <- gs_spending_bound( - k = 1, efficacy = FALSE, theta = 0, - par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = NULL -) - -b1 <- gs_spending_bound( - k = 1, efficacy = TRUE, theta = 0, - par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = NULL -) -cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n") - -# 2nd analysis -a2 <- gs_spending_bound( - k = 2, efficacy = FALSE, theta = 0, - par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -) - -b2 <- gs_spending_bound( - k = 2, efficacy = TRUE, theta = 0, - par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -) -cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") -} \references{ Jennison C and Turnbull BW (2000), \emph{Group Sequential Methods with Applications to Clinical Trials}. diff --git a/man/h1.Rd b/man/h1.Rd deleted file mode 100644 index 7fc437e9..00000000 --- a/man/h1.Rd +++ /dev/null @@ -1,53 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gridpts_h1_hupdate.R -\name{h1} -\alias{h1} -\title{Initialize numerical integration for group sequential design} -\usage{ -h1(r = 18, theta = 0, info = 1, a = -Inf, b = Inf) -} -\arguments{ -\item{r}{Integer, at least 2; default of 18 recommended by Jennison and Turnbull.} - -\item{theta}{Drift parameter for first analysis.} - -\item{info}{Information at first analysis.} - -\item{a}{Lower limit of integration (scalar).} - -\item{b}{Upper limit of integration (scalar \verb{> a}).} -} -\value{ -A list with grid points in \code{z}, numerical integration weights in \code{w}, -and a normal density with mean \verb{mu = theta * sqrt\{I\}} -and variance 1 times the weight in \code{h}. -} -\description{ -Compute grid points for first interim analysis in a group sequential design. -} -\details{ -Mean for standard normal distribution under consideration is \code{mu = theta * sqrt(I)}. -} -\section{Specification}{ - -\if{latex}{ - \itemize{ - \item Compute drift at analysis 1. - \item Compute deviation from drift. - \item Compute standard normal density, multiply by grid weight. - \item Return a tibble of z, w, and h. - } -} -\if{html}{The contents of this section are shown in PDF user manual only.} -} - -\examples{ -# Replicate variance of 1, mean of 35 -g <- h1(theta = 5, info = 49) -mu <- sum(g$z * g$h) -var <- sum((g$z - mu)^2 * g$h) - -# Replicate p-value of 0.0001 by numerical integration of tail -g <- h1(a = qnorm(0.9999)) -sum(g$h) -} diff --git a/man/hupdate.Rd b/man/hupdate.Rd deleted file mode 100644 index fa4203f2..00000000 --- a/man/hupdate.Rd +++ /dev/null @@ -1,62 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gridpts_h1_hupdate.R -\name{hupdate} -\alias{hupdate} -\title{Update numerical integration for group sequential design} -\usage{ -hupdate( - r = 18, - theta = 0, - info = 2, - a = -Inf, - b = Inf, - thetam1 = 0, - im1 = 1, - gm1 = h1() -) -} -\arguments{ -\item{r}{Integer, at least 2; default of 18 recommended by Jennison and Turnbull.} - -\item{theta}{Drift parameter for current analysis.} - -\item{info}{Information at current analysis.} - -\item{a}{Lower limit of integration (scalar).} - -\item{b}{Upper limit of integration (scalar \verb{> a}).} - -\item{thetam1}{Drift parameter for previous analysis.} - -\item{im1}{Information at previous analysis.} - -\item{gm1}{Numerical integration grid from \code{\link[=h1]{h1()}} or previous run of \code{\link[=hupdate]{hupdate()}}.} -} -\value{ -A list with grid points in \code{z}, -numerical integration weights in \code{w}, -a normal density with mean \verb{mu = theta * sqrt\{I\}} -and variance 1 times the weight in \code{h}. -} -\description{ -Update grid points for numerical integration from one analysis to the next. -} -\section{Specification}{ - -\if{latex}{ - \itemize{ - \item Compute the square root of the change in information. - \item Compute the grid points for group sequential design numerical integration. - \item Update the integration. - \item Return a tibble of z, w, and h. - } -} -\if{html}{The contents of this section are shown in PDF user manual only.} -} - -\examples{ -# 2nd analysis with no interim bound and drift 0 should have mean 0, variance 1 -g <- hupdate() -mu <- sum(g$z * g$h) -var <- sum((g$z - mu)^2 * g$h) -} diff --git a/vignettes/articles/story-npe-integration.Rmd b/vignettes/articles/story-npe-integration.Rmd index 970a5340..f9868695 100644 --- a/vignettes/articles/story-npe-integration.Rmd +++ b/vignettes/articles/story-npe-integration.Rmd @@ -195,7 +195,7 @@ The columns in the resulting table are ```{r} # Set up grid over continuation region # Null hypothesis -grid1_0 <- h1(theta = 0, info = info[1], a = a1, b = b1) +grid1_0 <- gsDesign2:::h1(theta = 0, info = info[1], a = a1, b = b1) grid1_0 %>% head() ``` The probability of not crossing a bound under the null hypothesis is computed as follows: @@ -212,7 +212,7 @@ cat( We now set up numerical integration grid under the alternate hypothesis and the compute continuation probability. ```{r} -grid1_1 <- h1(theta = theta[1], info = info[1], a = a1, b = b1) +grid1_1 <- gsDesign2:::h1(theta = theta[1], info = info[1], a = a1, b = b1) prob_h1_continue <- sum(grid1_1$h) h1mean <- sqrt(info[1]) * theta[1] cat( @@ -248,7 +248,7 @@ Under the null hypothesis, we need to update to the interval above `b2_0`. ```{r} # Upper rejection region grid under H0 -grid2_0 <- hupdate(theta = 0, info = info[2], a = b2_0, b = Inf, im1 = info[1], gm1 = grid1_0) +grid2_0 <- gsDesign2:::hupdate(theta = 0, info = info[2], a = b2_0, b = Inf, im1 = info[1], gm1 = grid1_0) pupper_0 <- sum(grid2_0$h) cat( "Upper spending at analysis 2\n Target:", spend0, "\n Using initial bound approximation:", @@ -272,7 +272,7 @@ cat( "Original bound approximation:", b2_0, "\nUpdated bound approximation:", b2_1 ) -grid2_0 <- hupdate(theta = 0, info = info[2], a = b2_1, b = Inf, im1 = info[1], gm1 = grid1_0) +grid2_0 <- gsDesign2:::hupdate(theta = 0, info = info[2], a = b2_1, b = Inf, im1 = info[1], gm1 = grid1_0) pupper_1 <- sum(grid2_0$h) cat( "\nOriginal boundary crossing probability:", pupper_0, @@ -286,7 +286,7 @@ We now update the lower bound in an analogous fashion. ```{r} # Lower rejection region grid under H1 -grid2_1 <- hupdate( +grid2_1 <- gsDesign2:::hupdate( theta = theta[2], info = info[2], a = -Inf, b = a2_0, thetam1 = theta[1], im1 = info[1], gm1 = grid1_1 ) @@ -305,7 +305,7 @@ cat( "\nUpdated bound approximation:", a2_1 ) -grid2_1 <- hupdate( +grid2_1 <- gsDesign2:::hupdate( theta = theta[2], info = info[2], a = -Inf, b = a2_1, thetam1 = theta[1], im1 = info[1], gm1 = grid1_1 ) diff --git a/vignettes/articles/usage-gs-spending-bound.Rmd b/vignettes/articles/usage-gs-spending-bound.Rmd index 22ae41c5..a18fce71 100644 --- a/vignettes/articles/usage-gs-spending-bound.Rmd +++ b/vignettes/articles/usage-gs-spending-bound.Rmd @@ -61,13 +61,13 @@ cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n" a2 <- gs_spending_bound( k = 2, efficacy = FALSE, theta = 0, par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) + hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) ) b2 <- gs_spending_bound( k = 2, efficacy = TRUE, theta = 0, par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) + hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) ) cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") ``` From 4f58c51b1750f505b3b6074c7e15205f1bc255e1 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Fri, 14 Jul 2023 19:44:24 +0000 Subject: [PATCH 02/13] add examples back in `gs_spending_bound` --- R/gs_spending_bound.R | 33 +++++++++++++++++++++++++++++++++ man/gs_spending_bound.Rd | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/R/gs_spending_bound.R b/R/gs_spending_bound.R index a85d0c54..ed9104ac 100644 --- a/R/gs_spending_bound.R +++ b/R/gs_spending_bound.R @@ -79,7 +79,40 @@ #' #' @importFrom gsDesign gsDesign sfLDOF #' @importFrom stats qnorm +#' +#' @examples +#' info <- (1:3) * 10 +#' info_frac <- info / max(info) +#' k <- length(info_frac) #' +#' # 1st analysis +#' a1 <- gs_spending_bound( +#' k = 1, efficacy = FALSE, theta = 0, +#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), +#' hgm1 = NULL +#' ) +#' +#' b1 <- gs_spending_bound( +#' k = 1, efficacy = TRUE, theta = 0, +#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), +#' hgm1 = NULL +#' ) +#' cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n") +#' +#' # 2nd analysis +#' # a2 <- gs_spending_bound( +#' # k = 2, efficacy = FALSE, theta = 0, +#' # par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), +#' # hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) +#' # ) +#' +#' # b2 <- gs_spending_bound( +#' # k = 2, efficacy = TRUE, theta = 0, +#' # par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), +#' # hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) +#' # ) +#' # cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") +#' #' @export gs_spending_bound <- function(k = 1, par = list( diff --git a/man/gs_spending_bound.Rd b/man/gs_spending_bound.Rd index 9d4159e1..84ae9411 100644 --- a/man/gs_spending_bound.Rd +++ b/man/gs_spending_bound.Rd @@ -85,6 +85,40 @@ that in Chapter 19 of Jennison and Turnbull (2000). \if{html}{The contents of this section are shown in PDF user manual only.} } +\examples{ +info <- (1:3) * 10 +info_frac <- info / max(info) +k <- length(info_frac) + +# 1st analysis +a1 <- gs_spending_bound( + k = 1, efficacy = FALSE, theta = 0, + par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), + hgm1 = NULL +) + +b1 <- gs_spending_bound( + k = 1, efficacy = TRUE, theta = 0, + par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), + hgm1 = NULL +) +cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n") + +# 2nd analysis +# a2 <- gs_spending_bound( +# k = 2, efficacy = FALSE, theta = 0, +# par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), +# hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) +# ) + +# b2 <- gs_spending_bound( +# k = 2, efficacy = TRUE, theta = 0, +# par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), +# hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) +# ) +# cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") + +} \references{ Jennison C and Turnbull BW (2000), \emph{Group Sequential Methods with Applications to Clinical Trials}. From 1198152c05042e32daeed0b869ffb88b901d24ad Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sat, 15 Jul 2023 02:55:36 +0000 Subject: [PATCH 03/13] address warning in test --- R/utility_tidy_tbl.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utility_tidy_tbl.R b/R/utility_tidy_tbl.R index 1d706338..7889f522 100644 --- a/R/utility_tidy_tbl.R +++ b/R/utility_tidy_tbl.R @@ -75,7 +75,7 @@ table_ab <- function(table_a, table_b, byvar, decimals = 1, aname = names(table_ # Get order of names to unite table_a columns together with names into a string col_order <- c(rbind(names(anames), names(table_a))) # Now unite columns of table_a into a string - astring <- xx %>% tidyr::unite("_alab", col_order, sep = " ") + astring <- xx %>% tidyr::unite("_alab", all_of(col_order), sep = " ") # Bind this together with the byvar column astring <- cbind(table_a %>% select(all_of(byvar)), astring) # Now merge with table_b From df9f441225b31c2d6a48bf56e88d131ba31ab684 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sat, 15 Jul 2023 03:17:37 +0000 Subject: [PATCH 04/13] apply ::: to internal functions --- .../test-developer-gs_spending_bound.R | 4 +-- tests/testthat/test-independent-gridpts.R | 4 +-- .../test-independent-gs_spending_bound.R | 16 ++++++------ tests/testthat/test-independent-h1.R | 18 ++++++------- tests/testthat/test-independent-hupdate.R | 26 +++++++++---------- tests/testthat/test-oldversion-gridpts.R | 6 ++--- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/testthat/test-developer-gs_spending_bound.R b/tests/testthat/test-developer-gs_spending_bound.R index 134cacf7..9ff70efd 100644 --- a/tests/testthat/test-developer-gs_spending_bound.R +++ b/tests/testthat/test-developer-gs_spending_bound.R @@ -1,8 +1,8 @@ test_that("gs_spending_bound() does not execute as expected", { expect_true(is.numeric(b <- gs_spending_bound())) expect_true(is.numeric(a <- gs_spending_bound(efficacy = FALSE))) - hgm1_0 <- h1(theta = 0, info = 1, a = a, b = b) - hgm1_1 <- h1(theta = .1, info = 1, a = a, b = b) + hgm1_0 <- gsDesign2:::h1(theta = 0, info = 1, a = a, b = b) + hgm1_1 <- gsDesign2:::h1(theta = .1, info = 1, a = a, b = b) expect_true(is.numeric(b2 <- gs_spending_bound(k = 2, theta = 0, hgm1 = hgm1_0))) expect_true(is.numeric(a2 <- gs_spending_bound(k = 2, theta = .1, hgm1 = hgm1_1, efficacy = FALSE))) }) diff --git a/tests/testthat/test-independent-gridpts.R b/tests/testthat/test-independent-gridpts.R index 42c448a3..d701965f 100644 --- a/tests/testthat/test-independent-gridpts.R +++ b/tests/testthat/test-independent-gridpts.R @@ -1,10 +1,10 @@ test_that("compare gridpts results with gsDesign::normalGrid results", { - x1 <- gridpts(r = 18, mu = 4, a = -Inf, b = Inf) + x1 <- gsDesign2:::gridpts(r = 18, mu = 4, a = -Inf, b = Inf) x2 <- gsDesign::normalGrid(r = 18, bounds = c(-40, 40), mu = 4, sigma = 1) expect_equal(x1$w, x2$gridwgts) expect_equal(x1$z, x2$z) - x1 <- gridpts(r = 18, mu = 2, a = -Inf, b = Inf) + x1 <- gsDesign2:::gridpts(r = 18, mu = 2, a = -Inf, b = Inf) x2 <- gsDesign::normalGrid(r = 18, bounds = c(-40, 40), mu = 2, sigma = 1) expect_equal(x1$w, x2$gridwgts) expect_equal(x1$z, x2$z) diff --git a/tests/testthat/test-independent-gs_spending_bound.R b/tests/testthat/test-independent-gs_spending_bound.R index 0f6cb055..3b98e8ae 100644 --- a/tests/testthat/test-independent-gs_spending_bound.R +++ b/tests/testthat/test-independent-gs_spending_bound.R @@ -25,7 +25,7 @@ test_that("compare gs_spending_bound with gsDesign results with equal IA timing a <- -Inf b <- Inf b <- gs_spending_bound() - hgm1_0 <- h1( + hgm1_0 <- gsDesign2:::h1( theta = 0, info = info[1], a = a, @@ -37,7 +37,7 @@ test_that("compare gs_spending_bound with gsDesign results with equal IA timing hgm1 = hgm1_0, info = info ) - hgm2_0 <- hupdate( + hgm2_0 <- gsDesign2:::hupdate( theta = 0, info = info[2], a = a, @@ -61,7 +61,7 @@ test_that("compare gs_spending_bound with gsDesign results with equal IA timing efficacy = FALSE, info = info ) - hgm1_1 <- h1(theta = x$theta[2], info = info[1], a = a, b = b) + hgm1_1 <- gsDesign2:::h1(theta = x$theta[2], info = info[1], a = a, b = b) a2 <- gs_spending_bound( k = 2, @@ -72,7 +72,7 @@ test_that("compare gs_spending_bound with gsDesign results with equal IA timing info = info ) - hgm2_1 <- hupdate( + hgm2_1 <- gsDesign2:::hupdate( theta = x$theta[2], info = info[2], a = a2, @@ -129,7 +129,7 @@ test_that("compare gs_spending_bound with gsDesign results with unequal IA timin hgm1 = NULL, info = info ) - hgm1_0 <- h1( + hgm1_0 <- gsDesign2:::h1( theta = 0, info = info[1], a = a, @@ -141,7 +141,7 @@ test_that("compare gs_spending_bound with gsDesign results with unequal IA timin hgm1 = hgm1_0, info = info ) - hgm2_0 <- hupdate( + hgm2_0 <- gsDesign2:::hupdate( theta = 0, info = info[2], a = a, @@ -166,7 +166,7 @@ test_that("compare gs_spending_bound with gsDesign results with unequal IA timin info = info ) - hgm1_1 <- h1(theta = y$theta[2], info = info[1], a = a, b = b) + hgm1_1 <- gsDesign2:::h1(theta = y$theta[2], info = info[1], a = a, b = b) a2 <- gs_spending_bound( k = 2, @@ -177,7 +177,7 @@ test_that("compare gs_spending_bound with gsDesign results with unequal IA timin info = info ) - hgm2_1 <- hupdate( + hgm2_1 <- gsDesign2:::hupdate( theta = y$theta[2], info = info[2], a = a2, diff --git a/tests/testthat/test-independent-h1.R b/tests/testthat/test-independent-h1.R index 5739415e..b4fa9e3a 100644 --- a/tests/testthat/test-independent-h1.R +++ b/tests/testthat/test-independent-h1.R @@ -1,30 +1,30 @@ -test_that("h1() returns results as expected ", { +test_that("gsDesign2:::h1() returns results as expected ", { # the design gstry <- gsDesign::gsDesign( k = 3, sfl = gsDesign::sfLDOF, delta = 0 ) - # probabilities calculated based on function h1() - upper.null <- sum(h1( + # probabilities calculated based on function gsDesign2:::h1() + upper.null <- sum(gsDesign2:::h1( theta = gstry$theta[1], info = gstry$n.I[1], a = gstry$upper$bound[1], b = Inf )$h) - upper.alt <- sum(h1( + upper.alt <- sum(gsDesign2:::h1( theta = gstry$theta[2], info = gstry$n.I[1], a = gstry$upper$bound[1], b = Inf )$h) - lower.null <- sum(h1( + lower.null <- sum(gsDesign2:::h1( theta = gstry$theta[1], info = gstry$n.I[1], a = -Inf, b = gstry$lower$bound[1] )$h) - lower.alt <- sum(h1( + lower.alt <- sum(gsDesign2:::h1( theta = gstry$theta[2], info = gstry$n.I[1], a = -Inf, @@ -41,8 +41,8 @@ test_that("h1() returns results as expected ", { expect_equal(object = as.numeric(c(lower.null, lower.alt)), expected = x$lower$prob[1, ], tolerance = 0.0001) }) -test_that("h1() returns probability almost zero for extreme case", { - exmtest1 <- sum(h1(theta = 9, info = 0.5, a = -Inf, b = 0)$h) - exmtest2 <- sum(h1(theta = 1, info = 0.5, a = 9, b = Inf)$h) +test_that("gsDesign2:::h1() returns probability almost zero for extreme case", { + exmtest1 <- sum(gsDesign2:::h1(theta = 9, info = 0.5, a = -Inf, b = 0)$h) + exmtest2 <- sum(gsDesign2:::h1(theta = 1, info = 0.5, a = 9, b = Inf)$h) expect_equal(object = as.numeric(c(exmtest1, exmtest2)), expected = c(0, 0), tolerance = 0.0001) }) diff --git a/tests/testthat/test-independent-hupdate.R b/tests/testthat/test-independent-hupdate.R index 0b5337ae..dd144a47 100644 --- a/tests/testthat/test-independent-hupdate.R +++ b/tests/testthat/test-independent-hupdate.R @@ -1,20 +1,20 @@ -test_that("hupdate() returns results as expected ", { +test_that("gsDesign2:::hupdate() returns results as expected ", { # the design gstry <- gsDesign::gsDesign( k = 3, sfl = gsDesign::sfLDOF, delta = 0 ) - # probabilities calculated based on function h1(), IA1 needs to full between low and upper bound + # probabilities calculated based on function gsDesign2:::h1(), IA1 needs to full between low and upper bound # in order to continue to IA2 - null.01 <- h1( + null.01 <- gsDesign2:::h1( theta = gstry$theta[1], info = gstry$n.I[1], a = gstry$lower$bound[1], b = gstry$upper$bound[1] ) # IA2 to reject H0, we integrate from upper bound to Inf - upper.null.02 <- sum(hupdate( + upper.null.02 <- sum(gsDesign2:::hupdate( theta = gstry$theta[1], thetam1 = gstry$theta[1], info = gstry$n.I[2], @@ -24,7 +24,7 @@ test_that("hupdate() returns results as expected ", { b = Inf )$h) # IA2 to accept H0, we integrate from -Inf to lower bound - lower.null.02 <- sum(hupdate( + lower.null.02 <- sum(gsDesign2:::hupdate( theta = gstry$theta[1], thetam1 = gstry$theta[1], info = gstry$n.I[2], @@ -34,14 +34,14 @@ test_that("hupdate() returns results as expected ", { b = gstry$lower$bound[2] )$h) - alt.01 <- h1( + alt.01 <- gsDesign2:::h1( theta = gstry$theta[2], info = gstry$n.I[1], a = gstry$lower$bound[1], b = gstry$upper$bound[1] ) # IA2 to reject H0, we integrate from upper bound to Inf - upper.alt.02 <- sum(hupdate( + upper.alt.02 <- sum(gsDesign2:::hupdate( theta = gstry$theta[2], thetam1 = gstry$theta[2], info = gstry$n.I[2], @@ -51,7 +51,7 @@ test_that("hupdate() returns results as expected ", { b = Inf )$h) # IA2 to accept H0, we integrate from -Inf to lower bound - lower.alt.02 <- sum(hupdate( + lower.alt.02 <- sum(gsDesign2:::hupdate( theta = gstry$theta[2], thetam1 = gstry$theta[2], info = gstry$n.I[2], @@ -72,19 +72,19 @@ test_that("hupdate() returns results as expected ", { expect_equal(object = as.numeric(c(lower.null.02, lower.alt.02)), expected = x$lower$prob[2, ], tolerance = 0.0001) expect_equal(object = as.numeric(c(upper.null.02, upper.alt.02)), expected = x$upper$prob[2, ], tolerance = 0.0001) # problem with below code on extreme case: - # hupdate(theta = gstry$theta[1], thetam1= gstry$theta[1], + # gsDesign2:::theta = gstry$theta[1], thetam1= gstry$theta[1], # info=gstry$n.I[1]+0.00000000000001,im1=gstry$n.I[1],gm1=null.01, # a = gstry$upper$bound[2],b=Inf) %>% summarise(p = sum(h)) }) -test_that("hupdate() returns probability almost zero for extreme case", { +test_that("gsDesign2:::) returns probability almost zero for extreme case", { # the design gstry <- gsDesign::gsDesign( k = 3, sfl = gsDesign::sfLDOF, delta = 0 ) - null.01 <- h1( + null.01 <- gsDesign2:::h1( theta = gstry$theta[1], info = gstry$n.I[1], a = gstry$lower$bound[1], @@ -92,7 +92,7 @@ test_that("hupdate() returns probability almost zero for extreme case", { ) # IA2 to reject H0, we integrate from upper bound to Inf #-8 is an arbitrary extreme case for theta - poor.02 <- sum(hupdate( + poor.02 <- sum(gsDesign2:::hupdate( theta = -8, thetam1 = gstry$theta[1], info = gstry$n.I[2], @@ -103,7 +103,7 @@ test_that("hupdate() returns probability almost zero for extreme case", { )$h) # IA2 to accept H0, we integrate from -Inf to lower bound #-8 is an arbitrary extreme case for the bound - high.02 <- sum(hupdate( + high.02 <- sum(gsDesign2:::hupdate( theta = gstry$theta[2], thetam1 = gstry$theta[2], info = gstry$n.I[2], diff --git a/tests/testthat/test-oldversion-gridpts.R b/tests/testthat/test-oldversion-gridpts.R index f70eecde..0c25a659 100644 --- a/tests/testthat/test-oldversion-gridpts.R +++ b/tests/testthat/test-oldversion-gridpts.R @@ -6,21 +6,21 @@ library(dplyr) test_that("Default (N(0,1)) - approximate variance of standard normal (i.e., 1)", { x1 <- gridpts_(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 old version - x2 <- gridpts(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 latest version + x2 <- gsDesign2:::gridpts(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 latest version expect_equal(x1$z, x2$z) expect_equal(x1$w, x2$w) }) test_that("Approximate probability of N(0,1) above .95 quantile (i.e., .05)", { x1 <- gridpts_(mu = 0, a = qnorm(0.95), b = Inf, r = 18) - x2 <- gridpts(mu = 0, a = qnorm(0.95), b = Inf, r = 18) + x2 <- gsDesign2:::gridpts(mu = 0, a = qnorm(0.95), b = Inf, r = 18) expect_equal(x1$z, x2$z) expect_equal(x1$w, x2$w) }) test_that("Approximate probability of N(0.5, 1) above .95 quantile (i.e., .05)", { x1 <- gridpts_(mu = 0.5, a = qnorm(0.95), b = Inf, r = 18) - x2 <- gridpts(mu = 0.5, a = qnorm(0.95), b = Inf, r = 18) + x2 <- gsDesign2:::gridpts(mu = 0.5, a = qnorm(0.95), b = Inf, r = 18) expect_equal(x1$z, x2$z) expect_equal(x1$w, x2$w) }) From c78be2422a78bd736e7e3a01c92f9da44a490af4 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sat, 15 Jul 2023 06:01:44 +0000 Subject: [PATCH 05/13] use old `h1_` function instead of `h1`. --- inst/old_function/gridpts_h1_hupdate_oldR.R | 2 +- inst/old_function/gs_power_npe_.R | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/old_function/gridpts_h1_hupdate_oldR.R b/inst/old_function/gridpts_h1_hupdate_oldR.R index 26607aa5..f65e741e 100644 --- a/inst/old_function/gridpts_h1_hupdate_oldR.R +++ b/inst/old_function/gridpts_h1_hupdate_oldR.R @@ -188,7 +188,7 @@ NULL #' gsDesign2:::hupdate_() %>% summarise(mu = sum(z * h), var = sum((z - mu)^2 * h)) #' #' @noRd -hupdate_ <- function(r = 18, theta = 0, I = 2, a = -Inf, b = Inf, thetam1 = 0, Im1 = 1, gm1 = h1()) { +hupdate_ <- function(r = 18, theta = 0, I = 2, a = -Inf, b = Inf, thetam1 = 0, Im1 = 1, gm1 = h1_()) { # sqrt of change in information rtdelta <- sqrt(I - Im1) rtI <- sqrt(I) diff --git a/inst/old_function/gs_power_npe_.R b/inst/old_function/gs_power_npe_.R index e09f1931..2dc8ae8e 100644 --- a/inst/old_function/gs_power_npe_.R +++ b/inst/old_function/gs_power_npe_.R @@ -255,15 +255,15 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf 0 } - hgm1_0 <- h1(r = r, theta = 0, info = info0[1], a = if (binding) { + hgm1_0 <- h1_(r = r, theta = 0, info = info0[1], a = if (binding) { a[1] } else { -Inf }, b = b[1]) - hgm1_1 <- h1(r = r, theta = theta1[1], info = info1[1], a = a[1], b = b[1]) + hgm1_1 <- h1_(r = r, theta = theta1[1], info = info1[1], a = a[1], b = b[1]) - hgm1 <- h1(r = r, theta = theta[1], info = info[1], a = a[1], b = b[1]) + hgm1 <- h1_(r = r, theta = theta[1], info = info[1], a = a[1], b = b[1]) } else { # Cross upper bound upperProb[k] <- if (b[k] < Inf) { From c282f328bccccb4d5d503916ff6d9a0a0941f024 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 16:40:49 +0000 Subject: [PATCH 06/13] using gsDesign2:::h1() --- inst/old_function/gridpts_h1_hupdate_oldR.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/old_function/gridpts_h1_hupdate_oldR.R b/inst/old_function/gridpts_h1_hupdate_oldR.R index f65e741e..b04b3519 100644 --- a/inst/old_function/gridpts_h1_hupdate_oldR.R +++ b/inst/old_function/gridpts_h1_hupdate_oldR.R @@ -188,7 +188,7 @@ NULL #' gsDesign2:::hupdate_() %>% summarise(mu = sum(z * h), var = sum((z - mu)^2 * h)) #' #' @noRd -hupdate_ <- function(r = 18, theta = 0, I = 2, a = -Inf, b = Inf, thetam1 = 0, Im1 = 1, gm1 = h1_()) { +hupdate_ <- function(r = 18, theta = 0, I = 2, a = -Inf, b = Inf, thetam1 = 0, Im1 = 1, gm1 = gsDesign2:::h1()) { # sqrt of change in information rtdelta <- sqrt(I - Im1) rtI <- sqrt(I) From d0798c6a25f964130fc4b3f1e2b1c466062d956e Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 17:17:02 +0000 Subject: [PATCH 07/13] using `gsDesign2:::` --- inst/old_function/gs_power_npe_.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/old_function/gs_power_npe_.R b/inst/old_function/gs_power_npe_.R index 2dc8ae8e..208031d9 100644 --- a/inst/old_function/gs_power_npe_.R +++ b/inst/old_function/gs_power_npe_.R @@ -255,15 +255,15 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf 0 } - hgm1_0 <- h1_(r = r, theta = 0, info = info0[1], a = if (binding) { + hgm1_0 <- gsDesign2:::h1(r = r, theta = 0, info = info0[1], a = if (binding) { a[1] } else { -Inf }, b = b[1]) - hgm1_1 <- h1_(r = r, theta = theta1[1], info = info1[1], a = a[1], b = b[1]) + hgm1_1 <- gsDesign2:::h1(r = r, theta = theta1[1], info = info1[1], a = a[1], b = b[1]) - hgm1 <- h1_(r = r, theta = theta[1], info = info[1], a = a[1], b = b[1]) + hgm1 <- gsDesign2:::h1(r = r, theta = theta[1], info = info[1], a = a[1], b = b[1]) } else { # Cross upper bound upperProb[k] <- if (b[k] < Inf) { From 2471a53da77f32bca748ecc7f28f6299fa9785d2 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 17:41:56 +0000 Subject: [PATCH 08/13] using gsDesign2:::hupdate --- inst/old_function/gs_power_npe_.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/old_function/gs_power_npe_.R b/inst/old_function/gs_power_npe_.R index 208031d9..d5caf8a1 100644 --- a/inst/old_function/gs_power_npe_.R +++ b/inst/old_function/gs_power_npe_.R @@ -292,7 +292,7 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf if (k < K) { # hgm1_0 <- hupdate(r = r, theta = 0, info = info0[k], a = if(binding){a[k]}else{-Inf}, b = b[k], # thetam1 = 0, im1 = info0[k-1], gm1 = hgm1_0) - hgm1_0 <- hupdate( + hgm1_0 <- gsDesign2:::hupdate( r = r, theta = 0, info = info0[k], a = if (binding) { a[k] } else { @@ -302,13 +302,13 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf ) # hgm1_1 <- hupdate(r = r, theta = theta1[k], info = info1[k], a = a[k], b = b[k], # thetam1 = theta1[k-1], im1 = info1[k-1], gm1 = hgm1_1) - hgm1_1 <- hupdate( + hgm1_1 <- gsDesign2:::( r = r, theta = theta1[k], info = info1[k], a = a[k], b = b[k], thetam1 = theta1[k - 1], im1 = info1[k - 1], gm1 = hgm1_1 ) # hgm1 <- hupdate(r = r, theta = theta[k], info = info[k], a = a[k], b = b[k], # thetam1 = theta[k-1], im1 = info[k-1], gm1 = hgm1) - hgm1 <- hupdate( + hgm1 <- gsDesign2:::( r = r, theta = theta[k], info = info[k], a = a[k], b = b[k], thetam1 = theta[k - 1], im1 = info[k - 1], gm1 = hgm1 ) From 4736a698d71d0f2ac0a6de2342cf2f4dab9432c9 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 17:42:42 +0000 Subject: [PATCH 09/13] using gsDesign2:::gridpts --- inst/old_function/gridpts_h1_hupdate_oldR.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/old_function/gridpts_h1_hupdate_oldR.R b/inst/old_function/gridpts_h1_hupdate_oldR.R index b04b3519..2aac01f1 100644 --- a/inst/old_function/gridpts_h1_hupdate_oldR.R +++ b/inst/old_function/gridpts_h1_hupdate_oldR.R @@ -144,7 +144,7 @@ h1_ <- function(r = 18, theta = 0, I = 1, a = -Inf, b = Inf) { z <- w <- h <- NULL # compute drift at analysis 1 mu <- theta * sqrt(I) - g <- gridpts(r, mu, a, b) + g <- gsDesign2:::gridpts(r, mu, a, b) # compute deviation from drift x <- g$z - mu # compute standard normal density, multiply by grid weight and return @@ -193,7 +193,7 @@ hupdate_ <- function(r = 18, theta = 0, I = 2, a = -Inf, b = Inf, thetam1 = 0, I rtdelta <- sqrt(I - Im1) rtI <- sqrt(I) rtIm1 <- sqrt(Im1) - g <- gridpts(r = r, mu = theta * rtI, a = a, b = b) + g <- gsDesign2:::gridpts(r = r, mu = theta * rtI, a = a, b = b) # update integration mu <- theta * I - thetam1 * Im1 h <- rep(0, length(g$z)) From 61938bbb986a6b6d03e4a1f8201bd49eb0fc0b01 Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 17:54:10 +0000 Subject: [PATCH 10/13] fix typo --- inst/old_function/gs_power_npe_.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/old_function/gs_power_npe_.R b/inst/old_function/gs_power_npe_.R index d5caf8a1..16f97f4a 100644 --- a/inst/old_function/gs_power_npe_.R +++ b/inst/old_function/gs_power_npe_.R @@ -302,13 +302,13 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf ) # hgm1_1 <- hupdate(r = r, theta = theta1[k], info = info1[k], a = a[k], b = b[k], # thetam1 = theta1[k-1], im1 = info1[k-1], gm1 = hgm1_1) - hgm1_1 <- gsDesign2:::( + hgm1_1 <- gsDesign2:::hupdate( r = r, theta = theta1[k], info = info1[k], a = a[k], b = b[k], thetam1 = theta1[k - 1], im1 = info1[k - 1], gm1 = hgm1_1 ) # hgm1 <- hupdate(r = r, theta = theta[k], info = info[k], a = a[k], b = b[k], # thetam1 = theta[k-1], im1 = info[k-1], gm1 = hgm1) - hgm1 <- gsDesign2:::( + hgm1 <- gsDesign2:::hupdate( r = r, theta = theta[k], info = info[k], a = a[k], b = b[k], thetam1 = theta[k - 1], im1 = info[k - 1], gm1 = hgm1 ) From 9903a133d8c45f8c582a1cd918ca2fcfefd04cdc Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 18:07:37 +0000 Subject: [PATCH 11/13] using gsDesign2:::hupdate --- inst/old_function/gs_power_npe_.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/old_function/gs_power_npe_.R b/inst/old_function/gs_power_npe_.R index 16f97f4a..6a0357b0 100644 --- a/inst/old_function/gs_power_npe_.R +++ b/inst/old_function/gs_power_npe_.R @@ -270,7 +270,7 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf # hupdate(r = r, theta = theta[k], info = info[k], a = b[k], b = Inf, # thetam1 = theta[k - 1], im1 = info[k - 1], gm1 = hgm1) %>% # summarise(sum(h)) %>% as.numeric() - sum(hupdate( + sum(gsDesign2:::hupdate( r = r, theta = theta[k], info = info[k], a = b[k], b = Inf, thetam1 = theta[k - 1], im1 = info[k - 1], gm1 = hgm1 )$h) @@ -282,7 +282,7 @@ gs_power_npe_ <- function(theta = .1, theta1 = NULL, info = 1, info1 = NULL, inf # hupdate(r = r, theta = theta[k], info = info[k], a = -Inf, b = a[k], # thetam1 = theta[k - 1], im1 = info[k - 1], gm1 = hgm1) %>% # summarise(sum(h)) %>% as.numeric() - sum(hupdate( + sum(gsDesign2:::hupdate( r = r, theta = theta[k], info = info[k], a = -Inf, b = a[k], thetam1 = theta[k - 1], im1 = info[k - 1], gm1 = hgm1 )$h) From af743f76e07005df791784737c7c6e0f70c7273d Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 16 Jul 2023 18:30:47 +0000 Subject: [PATCH 12/13] run styler --- R/gs_spending_bound.R | 4 ++-- tests/testthat/test-oldversion-ahr.R | 24 ++++++++++++------- .../testthat/test-oldversion-expected_event.R | 13 ++++++---- .../testthat/test-oldversion-expected_time.R | 18 +++++++++----- tests/testthat/test-oldversion-gridpts.R | 4 ++-- .../testthat/test-oldversion-gs_design_ahr.R | 12 ++++++---- .../testthat/test-oldversion-gs_design_npe.R | 16 ++++++++----- tests/testthat/test-oldversion-gs_power_npe.R | 15 ++++++++---- 8 files changed, 68 insertions(+), 38 deletions(-) diff --git a/R/gs_spending_bound.R b/R/gs_spending_bound.R index ed9104ac..025f4632 100644 --- a/R/gs_spending_bound.R +++ b/R/gs_spending_bound.R @@ -79,7 +79,7 @@ #' #' @importFrom gsDesign gsDesign sfLDOF #' @importFrom stats qnorm -#' +#' #' @examples #' info <- (1:3) * 10 #' info_frac <- info / max(info) @@ -112,7 +112,7 @@ #' # hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) #' # ) #' # cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") -#' +#' #' @export gs_spending_bound <- function(k = 1, par = list( diff --git a/tests/testthat/test-oldversion-ahr.R b/tests/testthat/test-oldversion-ahr.R index 89dc7bfd..e96e64ff 100644 --- a/tests/testthat/test-oldversion-ahr.R +++ b/tests/testthat/test-oldversion-ahr.R @@ -7,21 +7,25 @@ library(dplyr) test_that("unstratified population", { enroll_rate <- define_enroll_rate( duration = c(2, 10, 4, 4, 8), - rate = c(5, 10, 0, 3, 6)) + rate = c(5, 10, 0, 3, 6) + ) fail_rate <- define_fail_rate( stratum = "All", duration = 1, fail_rate = c(.1, .2, .3, .4), hr = c(.9, .75, .8, .6), - dropout_rate = .001) + dropout_rate = .001 + ) x1 <- ahr( # latest version enroll_rate = enroll_rate, fail_rate = fail_rate, - total_duration = c(15, 30)) + total_duration = c(15, 30) + ) x2 <- AHR_( # old version enrollRates = enroll_rate %>% rename(Stratum = stratum), failRates = fail_rate %>% rename(Stratum = stratum, failRate = fail_rate, dropoutRate = dropout_rate), - totalDuration = c(15, 30)) %>% + totalDuration = c(15, 30) + ) %>% rename(time = Time, ahr = AHR, event = Events) expect_equal(x1, x2) }) @@ -30,21 +34,25 @@ test_that("stratified population", { enroll_rate <- define_enroll_rate( stratum = c(rep("Low", 2), rep("High", 3)), duration = c(2, 10, 4, 4, 8), - rate = c(5, 10, 0, 3, 6)) + rate = c(5, 10, 0, 3, 6) + ) fail_rate <- define_fail_rate( stratum = c(rep("Low", 2), rep("High", 2)), duration = 1, fail_rate = c(.1, .2, .3, .4), hr = c(.9, .75, .8, .6), - dropout_rate = .001) + dropout_rate = .001 + ) x1 <- ahr( # latest version enroll_rate = enroll_rate, fail_rate = fail_rate, - total_duration = c(15, 30)) + total_duration = c(15, 30) + ) x2 <- AHR_( # old version enrollRates = enroll_rate %>% rename(Stratum = stratum), failRates = fail_rate %>% rename(Stratum = stratum, failRate = fail_rate, dropoutRate = dropout_rate), - totalDuration = c(15, 30)) %>% + totalDuration = c(15, 30) + ) %>% rename(time = Time, ahr = AHR, event = Events) expect_equal(x1, x2) }) diff --git a/tests/testthat/test-oldversion-expected_event.R b/tests/testthat/test-oldversion-expected_event.R index 5f07f74a..b4c698d7 100644 --- a/tests/testthat/test-oldversion-expected_event.R +++ b/tests/testthat/test-oldversion-expected_event.R @@ -8,7 +8,7 @@ test_that("expected event vs gsDesign", { enroll_rate <- define_enroll_rate(duration = c(2, 1, 2), rate = c(5, 10, 20)) fail_rate <- define_fail_rate(duration = c(1, 1, 1), fail_rate = c(.05, .02, .01), dropout_rate = .01) total_duration <- 20 - x1 <- gsDesign::eEvents( # gsDesign + x1 <- gsDesign::eEvents( # gsDesign lambda = fail_rate$fail_rate, S = fail_rate$duration[1:(nrow(fail_rate) - 1)], eta = fail_rate$dropout_rate, @@ -16,13 +16,16 @@ test_that("expected event vs gsDesign", { R = enroll_rate$duration, T = total_duration )$d - x2 <- eEvents_df_( # gsDesign2 old version + x2 <- eEvents_df_( # gsDesign2 old version enrollRates = enroll_rate %>% rename(Stratum = stratum), failRates = fail_rate %>% rename(Stratum = stratum, failRate = fail_rate, dropoutRate = dropout_rate), total_duration, - simple = TRUE) - x3 <- expected_event( # gsDesign2 latest version - enroll_rate, fail_rate, total_duration, simple = TRUE) + simple = TRUE + ) + x3 <- expected_event( # gsDesign2 latest version + enroll_rate, fail_rate, total_duration, + simple = TRUE + ) expect(x1, x2) expect(x2, x3) }) diff --git a/tests/testthat/test-oldversion-expected_time.R b/tests/testthat/test-oldversion-expected_time.R index 2075123c..34dafe66 100644 --- a/tests/testthat/test-oldversion-expected_time.R +++ b/tests/testthat/test-oldversion-expected_time.R @@ -8,18 +8,21 @@ test_that("time to targeted events", { enroll_rate <- define_enroll_rate(stratum = "All", duration = c(2, 2, 10), rate = c(3, 6, 9) * 5) fail_rate <- define_fail_rate( stratum = "All", duration = c(3, 100), fail_rate = log(2) / c(9, 18), - hr = c(.9, .6), dropout_rate = rep(.001, 2)) + hr = c(.9, .6), dropout_rate = rep(.001, 2) + ) ratio <- 1 x <- AHR_( enrollRates = enroll_rate %>% rename(Stratum = stratum), failRates = fail_rate %>% rename(Stratum = stratum, failRate = fail_rate, dropoutRate = dropout_rate), ratio = ratio, - totalDuration = 20) + totalDuration = 20 + ) y <- expected_time( enroll_rate = enroll_rate, fail_rate = fail_rate, ratio = ratio, - target_event = x$Events) + target_event = x$Events + ) expect_equal(20, y$time) }) @@ -34,18 +37,21 @@ test_that("time to targeted events by new/old version", { fail_rate <- define_fail_rate( stratum = "All", duration = c(3, 100), fail_rate = log(2) / c(9, 18), hr = c(.9, .6), - dropout_rate = rep(.001, 2)) + dropout_rate = rep(.001, 2) + ) ratio <- 1 x1 <- expected_time( enroll_rate = enroll_rate, fail_rate = fail_rate, ratio = ratio, - target_event = 200) + target_event = 200 + ) x2 <- tEvents_( enrollRates = enroll_rate %>% rename(Stratum = stratum), failRates = fail_rate %>% rename(Stratum = stratum, failRate = fail_rate, dropoutRate = dropout_rate), ratio = ratio, - targetEvents = 200) %>% + targetEvents = 200 + ) %>% rename(time = Time, ahr = AHR, event = Events) expect_equal(x1, x2) }) diff --git a/tests/testthat/test-oldversion-gridpts.R b/tests/testthat/test-oldversion-gridpts.R index 0c25a659..5063274a 100644 --- a/tests/testthat/test-oldversion-gridpts.R +++ b/tests/testthat/test-oldversion-gridpts.R @@ -5,8 +5,8 @@ sapply(paste0(my_path, source_files), source) library(dplyr) test_that("Default (N(0,1)) - approximate variance of standard normal (i.e., 1)", { - x1 <- gridpts_(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 old version - x2 <- gsDesign2:::gridpts(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 latest version + x1 <- gridpts_(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 old version + x2 <- gsDesign2:::gridpts(mu = 0, a = -20, b = 20, r = 18) # gsDesign2 latest version expect_equal(x1$z, x2$z) expect_equal(x1$w, x2$w) }) diff --git a/tests/testthat/test-oldversion-gs_design_ahr.R b/tests/testthat/test-oldversion-gs_design_ahr.R index 2857b245..08506913 100644 --- a/tests/testthat/test-oldversion-gs_design_ahr.R +++ b/tests/testthat/test-oldversion-gs_design_ahr.R @@ -97,14 +97,16 @@ test_that("2-sided symmetric design with O'Brien-Fleming spending", { upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), lower = gs_spending_bound, lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), - h1_spending = FALSE) + h1_spending = FALSE + ) x2 <- gs_design_ahr_( analysisTimes = c(12, 24, 36), binding = TRUE, upper = gs_spending_bound, upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), lower = gs_spending_bound, lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), - h1_spending = FALSE) + h1_spending = FALSE + ) expect_equal(x1$analysis$time, x2$bounds$Time[x2$bounds$Bound == "Upper"]) expect_equal(x1$analysis$event, x2$bounds$Events[x2$bounds$Bound == "Upper"]) expect_equal(x1$bound$z[x1$bound$bound == "upper"], x2$bounds$Z[x2$bounds$Bound == "Upper"]) @@ -124,14 +126,16 @@ test_that("Pocock lower spending under H1 (NPH)", { upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), lower = gs_spending_bound, lpar = list(sf = gsDesign::sfLDPocock, total_spend = 0.1, param = NULL, timing = NULL), - h1_spending = TRUE) + h1_spending = TRUE + ) x2 <- gs_design_ahr_( analysisTimes = c(12, 24, 36), binding = TRUE, upper = gs_spending_bound, upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), lower = gs_spending_bound, lpar = list(sf = gsDesign::sfLDPocock, total_spend = 0.1, param = NULL, timing = NULL), - h1_spending = TRUE) + h1_spending = TRUE + ) expect_equal(x1$analysis$time, x2$bounds$Time[x2$bounds$Bound == "Upper"]) expect_equal(x1$analysis$event, x2$bounds$Events[x2$bounds$Bound == "Upper"]) expect_equal(x1$bound$z[x1$bound$bound == "upper"], x2$bounds$Z[x2$bounds$Bound == "Upper"]) diff --git a/tests/testthat/test-oldversion-gs_design_npe.R b/tests/testthat/test-oldversion-gs_design_npe.R index eaa0ee8f..253f7476 100644 --- a/tests/testthat/test-oldversion-gs_design_npe.R +++ b/tests/testthat/test-oldversion-gs_design_npe.R @@ -28,7 +28,8 @@ test_that("verify by gs_power_npe", { upper = gs_spending_bound, upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), lower = gs_spending_bound, - lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), binding = TRUE) + lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), binding = TRUE + ) # The power is 0.9. If we re-use these bounds under alternate hypothesis, then we can get a power close to 0.9. y <- gs_power_npe_( theta = c(.1, .2, .3), info = (1:3) * 40, @@ -36,7 +37,7 @@ test_that("verify by gs_power_npe", { lower = gs_b, lpar = -(x %>% filter(Bound == "Upper"))$Z, binding = TRUE # Always use binding = TRUE for power calculations ) - expect_equal(y$Probability [y$Analysis == 3 & y$Bound == "Upper"], 1 - beta, tolerance = 1e-2) + expect_equal(y$Probability[y$Analysis == 3 & y$Bound == "Upper"], 1 - beta, tolerance = 1e-2) }) test_that("examples in spec - Lachin book p71", { @@ -89,7 +90,8 @@ test_that("fixed design with 3 equal info", { theta = c(.1, .2, .3), info = (1:3) * 80, upper = gs_b, upar = gsDesign::gsDesign(k = 3, sfu = gsDesign::sfLDOF)$upper$bound, - lower = gs_b, lpar = c(-1, 0, 0)) %>% + lower = gs_b, lpar = c(-1, 0, 0) + ) %>% rename(analysis = Analysis, bound = Bound, z = Z, probability = Probability) %>% mutate(bound = tolower(bound)) %>% select(-c(theta1, info1)) %>% @@ -126,7 +128,8 @@ test_that("fixed design with 3 unequal info", { theta = c(.1, .2, .3), info = (1:3) * 80, info0 = (1:3) * 90 + 10, info1 = (1:3) * 70 - 5, upper = gs_b, upar = gsDesign::gsDesign(k = 3, sfu = gsDesign::sfLDOF)$upper$bound, - lower = gs_b, lpar = c(-1, 0, 0)) %>% + lower = gs_b, lpar = c(-1, 0, 0) + ) %>% rename(analysis = Analysis, bound = Bound, z = Z, probability = Probability) %>% mutate(bound = tolower(bound)) %>% select(-c(theta1, info1)) %>% @@ -167,10 +170,11 @@ test_that("futility at IA1; efficacy only at IA2 +FA", { info = (1:3) * 40, info0 = (1:3) * 40, upper = gs_spending_bound, upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), lower = gs_b, lpar = c(-1, -Inf, -Inf), - test_upper = c(FALSE, TRUE, TRUE)) %>% + test_upper = c(FALSE, TRUE, TRUE) + ) %>% rename(analysis = Analysis, bound = Bound, z = Z, probability = Probability) %>% mutate(bound = tolower(bound)) %>% - select(- c(theta1, info1)) %>% + select(-c(theta1, info1)) %>% arrange(analysis, bound) expect_equal(x1_c, x2) }) diff --git a/tests/testthat/test-oldversion-gs_power_npe.R b/tests/testthat/test-oldversion-gs_power_npe.R index 15934f75..b2a8aec2 100644 --- a/tests/testthat/test-oldversion-gs_power_npe.R +++ b/tests/testthat/test-oldversion-gs_power_npe.R @@ -281,11 +281,13 @@ test_that("Independent Tests - Expect equal with mvtnorm for efficacy and futili expect_equal( object = test1$z, expected = c(qnorm(1 - alpha_ia), b$root), - tolerance = 0.001) + tolerance = 0.001 + ) expect_equal( object = test1$probability, expected = cumsum(c(b_ia$spend, pb)), - tolerance = 0.001) + tolerance = 0.001 + ) beta_t <- 0.02 a_ia <- gsDesign::sfLDOF(alpha = beta_t, t = r) beta_ia <- a_ia$spend @@ -302,11 +304,13 @@ test_that("Independent Tests - Expect equal with mvtnorm for efficacy and futili expect_equal( object = test2$z, expected = c(qnorm(beta_ia), a$root), - tolerance = 0.001) + tolerance = 0.001 + ) expect_equal( object = test2$probability, expected = cumsum(c(a_ia$spend, pa)), - tolerance = 0.001) + tolerance = 0.001 + ) }) test_that("Expect equal with gsDesign::gsProbability outcome for efficacy bounds", { @@ -333,7 +337,8 @@ test_that("Expect equal with gsDesign::gsProbability outcome for efficacy bounds k = 3, theta = .1, n.I = info, a = rep(-20, 3), - b = gsDesign(k = 3, test.type = 1, sfu = sfLDOF, n.I = info)$upper$bound) + b = gsDesign(k = 3, test.type = 1, sfu = sfLDOF, n.I = info)$upper$bound + ) expect_equal(x, y) expect_equal(x$z[x$bound == "upper"], z$upper$bound, tolerance = 1e-5) expect_equal(x$probability[x$bound == "upper"], cumsum(z$upper$prob), tolerance = 1e-5) From 4330455bc3e1f2d09086d016deb45184f79f3cee Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Tue, 18 Jul 2023 09:48:40 -0400 Subject: [PATCH 13/13] add example to gs_spending_bound per keaven's suggestion --- R/gs_spending_bound.R | 39 ++++++++------------------------------- man/gs_spending_bound.Rd | 39 ++++++++------------------------------- 2 files changed, 16 insertions(+), 62 deletions(-) diff --git a/R/gs_spending_bound.R b/R/gs_spending_bound.R index 025f4632..ed89ad01 100644 --- a/R/gs_spending_bound.R +++ b/R/gs_spending_bound.R @@ -81,38 +81,15 @@ #' @importFrom stats qnorm #' #' @examples -#' info <- (1:3) * 10 -#' info_frac <- info / max(info) -#' k <- length(info_frac) -#' -#' # 1st analysis -#' a1 <- gs_spending_bound( -#' k = 1, efficacy = FALSE, theta = 0, -#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' hgm1 = NULL -#' ) -#' -#' b1 <- gs_spending_bound( -#' k = 1, efficacy = TRUE, theta = 0, -#' par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' hgm1 = NULL +#' gs_power_ahr( +#' analysis_time = c(12, 24, 36), +#' event = c(30, 40, 50), +#' binding = TRUE, +#' upper = gs_spending_bound, +#' upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), +#' lower = gs_spending_bound, +#' lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL) #' ) -#' cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n") -#' -#' # 2nd analysis -#' # a2 <- gs_spending_bound( -#' # k = 2, efficacy = FALSE, theta = 0, -#' # par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' # hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -#' # ) -#' -#' # b2 <- gs_spending_bound( -#' # k = 2, efficacy = TRUE, theta = 0, -#' # par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -#' # hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -#' # ) -#' # cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") -#' #' @export gs_spending_bound <- function(k = 1, par = list( diff --git a/man/gs_spending_bound.Rd b/man/gs_spending_bound.Rd index 84ae9411..bc33323d 100644 --- a/man/gs_spending_bound.Rd +++ b/man/gs_spending_bound.Rd @@ -86,38 +86,15 @@ that in Chapter 19 of Jennison and Turnbull (2000). } \examples{ -info <- (1:3) * 10 -info_frac <- info / max(info) -k <- length(info_frac) - -# 1st analysis -a1 <- gs_spending_bound( - k = 1, efficacy = FALSE, theta = 0, - par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = NULL -) - -b1 <- gs_spending_bound( - k = 1, efficacy = TRUE, theta = 0, - par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), - hgm1 = NULL +gs_power_ahr( + analysis_time = c(12, 24, 36), + event = c(30, 40, 50), + binding = TRUE, + upper = gs_spending_bound, + upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL), + lower = gs_spending_bound, + lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL, timing = NULL) ) -cat("The (lower, upper) boundary at the 1st analysis is (", a1, ", ", b1, ").\n") - -# 2nd analysis -# a2 <- gs_spending_bound( -# k = 2, efficacy = FALSE, theta = 0, -# par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -# hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -# ) - -# b2 <- gs_spending_bound( -# k = 2, efficacy = TRUE, theta = 0, -# par = list(sf = gsDesign::sfLDOF, total_spend = 0.025, timing = info_frac, param = NULL), -# hgm1 = gsDesign2:::h1(r = 18, theta = 0, info = info[1], a = a1, b = b1) -# ) -# cat("The upper boundary at the 2nd analysis is (", a2, ", ", b2, ").\n") - } \references{ Jennison C and Turnbull BW (2000),