From d0668df7272d12a579faeeb66665f805860a22ab Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 22 Sep 2023 18:38:31 +0200 Subject: [PATCH 1/3] Speed up examples for CRAN submission --- R/evaluate_estimator.R | 2 +- inst/REFERENCES.bib | 2 -- man/EstimatorScore-class.Rd | 2 +- man/evaluate_estimator-methods.Rd | 2 +- man/evaluate_estimator.Rd | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/R/evaluate_estimator.R b/R/evaluate_estimator.R index cfaed78..410eb97 100644 --- a/R/evaluate_estimator.R +++ b/R/evaluate_estimator.R @@ -154,7 +154,7 @@ setMethod("c", signature("EstimatorScoreResultList"), definition = #' estimator = StagewiseCombinationFunctionOrderingCI(), #' data_distribution = Normal(FALSE), #' design = get_example_design(), -#' mu = c(0, 0.3, 0.6), +#' mu = c(0, 0.3), #' sigma = 1, #' exact = FALSE #' ) diff --git a/inst/REFERENCES.bib b/inst/REFERENCES.bib index d1f9f23..db33375 100644 --- a/inst/REFERENCES.bib +++ b/inst/REFERENCES.bib @@ -28,8 +28,6 @@ @article{brannath2006estimation pages = {3366-3381}, keywords = {adaptive design, flexible confidence interval, invariance principle, maximum likelihood estimate, mean unbiased estimate, median unbiased estimate}, doi = {10.1002/sim.2258}, -url = {https://onlinelibrary.wiley.com/doi/abs/10.1002/sim.2258}, -eprint = {https://onlinelibrary.wiley.com/doi/pdf/10.1002/sim.2258}, year = {2006} } @book{wassmer2016group, diff --git a/man/EstimatorScore-class.Rd b/man/EstimatorScore-class.Rd index 1b92746..a861dea 100644 --- a/man/EstimatorScore-class.Rd +++ b/man/EstimatorScore-class.Rd @@ -100,7 +100,7 @@ evaluate_estimator( estimator = StagewiseCombinationFunctionOrderingCI(), data_distribution = Normal(FALSE), design = get_example_design(), - mu = c(0, 0.3, 0.6), + mu = c(0, 0.3), sigma = 1, exact = FALSE ) diff --git a/man/evaluate_estimator-methods.Rd b/man/evaluate_estimator-methods.Rd index 6001562..db368b7 100644 --- a/man/evaluate_estimator-methods.Rd +++ b/man/evaluate_estimator-methods.Rd @@ -387,7 +387,7 @@ evaluate_estimator( estimator = StagewiseCombinationFunctionOrderingCI(), data_distribution = Normal(FALSE), design = get_example_design(), - mu = c(0, 0.3, 0.6), + mu = c(0, 0.3), sigma = 1, exact = FALSE ) diff --git a/man/evaluate_estimator.Rd b/man/evaluate_estimator.Rd index f95b348..08ca873 100644 --- a/man/evaluate_estimator.Rd +++ b/man/evaluate_estimator.Rd @@ -122,7 +122,7 @@ evaluate_estimator( estimator = StagewiseCombinationFunctionOrderingCI(), data_distribution = Normal(FALSE), design = get_example_design(), - mu = c(0, 0.3, 0.6), + mu = c(0, 0.3), sigma = 1, exact = FALSE ) From 254191d6d4a1086a42fbb8b8e6abe2275f29c8e5 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 22 Sep 2023 18:52:36 +0200 Subject: [PATCH 2/3] Remove this package from start of description --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index cc3b37e..e87a124 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Title: Adaptive Design Estimation in R Version: 0.5.0 Authors@R: c(person("Jan", "Meis", role = c("aut", "cre"), email="meis@imbi.uni-heidelberg.de", comment = c(ORCID = "0000-0001-5407-7220"))) Description: - This package implements methods to evaluate the performance characteristics of + Methods to evaluate the performance characteristics of various point and interval estimators for optimal adaptive two-stage designs. Specifically, this package is written to work with trial designs created by the adoptr package (Kunzmann et al. (2021) ; Pilz et al. (2021) )). From ec9442072f5849ebec7835967ffd64fe1d428bff Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 22 Sep 2023 20:02:48 +0200 Subject: [PATCH 3/3] Fix some adoptr dependencies --- DESCRIPTION | 1 + NAMESPACE | 1 + R/twostagedesign_with_cache.R | 41 ++++++++++++----------------------- man/TwoStageDesign-class.Rd | 2 +- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e87a124..2454af9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,6 +29,7 @@ Imports: latex2exp, forcats, future.apply, + pracma, progressr, Rdpack Suggests: diff --git a/NAMESPACE b/NAMESPACE index aef3a63..45a5145 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -85,6 +85,7 @@ importFrom(ggpubr,theme_pubr) importFrom(grDevices,xy.coords) importFrom(graphics,plot.default) importFrom(latex2exp,TeX) +importFrom(pracma,gaussLegendre) importFrom(progressr,progressor) importFrom(scales,percent) importFrom(stats,dchisq) diff --git a/R/twostagedesign_with_cache.R b/R/twostagedesign_with_cache.R index c41ab54..0b25aad 100644 --- a/R/twostagedesign_with_cache.R +++ b/R/twostagedesign_with_cache.R @@ -1,6 +1,6 @@ ### Remove some of this once adoptr is back on CRAN ### -#' Two-stage designs +#' Re-export of two-stage design class #' #' This is a re-export of the \code{TwoStageDesign} class from the #' \code{adoptr} \insertCite{kunzmann2021adoptr}{adestr} package. @@ -24,6 +24,7 @@ #' Maximilian Pilz is available at \url{https://github.com/kkmann/adoptr}. #' #' @exportClass TwoStageDesign +#' @importFrom pracma gaussLegendre setClass("TwoStageDesign", representation( n1 = "numeric", c1f = "numeric", @@ -34,34 +35,20 @@ setClass("TwoStageDesign", representation( weights = "numeric", tunable = "logical" )) -TwoStageDesign <- function(n1, c1f, c1e, n2_pivots, c2_pivots, order = NULL) { - # The original version of this is available from - # https://github.com/kkmann/adoptr/blob/master/R/TwoStageDesign.R - if (is.null(order)) { - order <- length(c2_pivots) - } else if (length(n2_pivots) != order) { - n2_pivots <- rep(n2_pivots[1], order) - c2_pivots <- rep(c2_pivots[1], order) +TwoStageDesign <- function(n1, c1f, c1e, n2_pivots, c2_pivots, order = length(c2_pivots)) { + if (order != length(c2_pivots)) { + stop("order needs to be same length as c2_pivots") } - order <- as.integer(order) - if (order < 2) stop("At least two nodes are necessary for integration!") - j <- 1:(order - 1) - mu0 <- 2 - b <- j / (4 * j^2 - 1)^0.5 - A <- rep(0, order * order) - A[(order + 1) * (j - 1) + 2] <- b - A[(order + 1) * j] <- b - dim(A) <- c(order, order) - sd <- eigen(A, symmetric = TRUE) - w <- rev(as.vector(sd$vectors[1, ])) - w <- mu0 * w^2 - x <- rev(sd$values) - rule <- data.frame(nodes = x, weights = w) - tunable <- logical(8) # initialize to all false - tunable[1:5] <- TRUE - names(tunable) <- c("n1", "c1f", "c1e", "n2_pivots", "c2_pivots", "x1_norm_pivots", "weights", "tunable") + if (length(n2_pivots) != length(c2_pivots) && length(n2_pivots)!=1) { + stop("n2_pivots needs to be the same length as c2_pivots or of length 1.") + } + if (length(n2_pivots)==1L) + n2_pivots <- rep(n2_pivots, order) + glr <- gaussLegendre(order, -1, 1) + tunable <- c("n1" = TRUE, "c1f" = TRUE, "c1e" = TRUE, "n2_pivots" = TRUE, "c2_pivots" = TRUE, + "x1_norm_pivots" = FALSE, "weights" = FALSE, "tunable" = FALSE) new("TwoStageDesign", n1 = n1, c1f = c1f, c1e = c1e, n2_pivots = n2_pivots, - c2_pivots = c2_pivots, x1_norm_pivots = rule$nodes, weights = rule$weights, + c2_pivots = c2_pivots, x1_norm_pivots = glr$x, weights = glr$w, tunable = tunable) } setClass("DataDistribution", representation( diff --git a/man/TwoStageDesign-class.Rd b/man/TwoStageDesign-class.Rd index d5bf430..cd69dbf 100644 --- a/man/TwoStageDesign-class.Rd +++ b/man/TwoStageDesign-class.Rd @@ -3,7 +3,7 @@ \docType{class} \name{TwoStageDesign-class} \alias{TwoStageDesign-class} -\title{Two-stage designs} +\title{Re-export of two-stage design class} \description{ This is a re-export of the \code{TwoStageDesign} class from the \code{adoptr} \insertCite{kunzmann2021adoptr}{adestr} package.