From 62b8bda3b73c42dc705d8b1a6f21f74683aee399 Mon Sep 17 00:00:00 2001 From: Friedrich Pahlke Date: Tue, 20 Aug 2024 14:18:29 +0200 Subject: [PATCH 1/2] rhub workflow file rhub.yaml added --- .github/workflows/rhub.yaml | 95 +++++++++++++++++++++++++++++ DESCRIPTION | 4 +- NAMESPACE | 1 + R/class_summary.R | 13 ++-- R/f_design_general_utilities.R | 8 +-- R/f_design_group_sequential.R | 4 ++ R/f_simulation_base_count_data.R | 16 +++-- inst/doc/rpact_getting_started.html | 4 +- man/getSimulationCounts.Rd | 81 +++++++++++++++++++++++- 9 files changed, 204 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/rhub.yaml diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml new file mode 100644 index 00000000..74ec7b05 --- /dev/null +++ b/.github/workflows/rhub.yaml @@ -0,0 +1,95 @@ +# R-hub's generic GitHub Actions workflow file. It's canonical location is at +# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml +# You can update this file to a newer version using the rhub2 package: +# +# rhub::rhub_setup() +# +# It is unlikely that you need to modify this file manually. + +name: R-hub +run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" + +on: + workflow_dispatch: + inputs: + config: + description: 'A comma separated list of R-hub platforms to use.' + type: string + default: 'linux,windows,macos' + name: + description: 'Run name. You can leave this empty now.' + type: string + id: + description: 'Unique ID. You can leave this empty now.' + type: string + +jobs: + + setup: + runs-on: ubuntu-latest + outputs: + containers: ${{ steps.rhub-setup.outputs.containers }} + platforms: ${{ steps.rhub-setup.outputs.platforms }} + + steps: + # NO NEED TO CHECKOUT HERE + - uses: r-hub/actions/setup@v1 + with: + config: ${{ github.event.inputs.config }} + id: rhub-setup + + linux-containers: + needs: setup + if: ${{ needs.setup.outputs.containers != '[]' }} + runs-on: ubuntu-latest + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.containers) }} + container: + image: ${{ matrix.config.container }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/run-check@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + + other-platforms: + needs: setup + if: ${{ needs.setup.outputs.platforms != '[]' }} + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.platforms) }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/setup-r@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/run-check@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} diff --git a/DESCRIPTION b/DESCRIPTION index a91a90f8..f4efdceb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rpact Title: Confirmatory Adaptive Clinical Trial Design and Analysis -Version: 4.0.1.9247 -Date: 2024-08-15 +Version: 4.0.1.9248 +Date: 2024-08-19 Authors@R: c( person( given = "Gernot", diff --git a/NAMESPACE b/NAMESPACE index e1e1fbd3..af7ab577 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -104,6 +104,7 @@ export(getSampleSizeCounts) export(getSampleSizeMeans) export(getSampleSizeRates) export(getSampleSizeSurvival) +export(getSimulationCounts) export(getSimulationEnrichmentMeans) export(getSimulationEnrichmentRates) export(getSimulationEnrichmentSurvival) diff --git a/R/class_summary.R b/R/class_summary.R index ff3312e1..e582a34d 100644 --- a/R/class_summary.R +++ b/R/class_summary.R @@ -1641,20 +1641,19 @@ SummaryFactory <- R6::R6Class("SummaryFactory", return(header) } -.addAlphaAndBetaToHeader <- function(header, design, designPlan, ..., endOfRecord = FALSE, powerEnabled = NA) { - header <- .concatenateSummaryText(header, paste0( - ifelse(design$sided == 1, "one-sided", "two-sided"), - ifelse(design$kMax == 1, "", " overall") - )) +.addAlphaAndBetaToHeader <- function(header, design, designPlan, ..., endOfRecord = FALSE, powerEnabled = NA, sep = ", ") { if (is.na(powerEnabled)) { powerEnabled <- .isTrialDesignInverseNormalOrGroupSequential(design) && (is.null(designPlan) || (!.isSimulationResults(designPlan) && !identical("power", designPlan[[".objectType"]]))) } header <- .concatenateSummaryText(header, - paste0("significance level ", round(100 * design$alpha, 2), "%", + paste0( + ifelse(design$sided == 1, "one-sided", "two-sided"), + ifelse(design$kMax == 1, "", " overall"), + " significance level ", round(100 * design$alpha, 2), "%", ifelse(!powerEnabled && endOfRecord, ".", "")), - sep = " " + sep = sep ) if (powerEnabled) { header <- .concatenateSummaryText(header, diff --git a/R/f_design_general_utilities.R b/R/f_design_general_utilities.R index 3fe82198..2852d154 100644 --- a/R/f_design_general_utilities.R +++ b/R/f_design_general_utilities.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8087 $ -## | Last changed: $Date: 2024-08-15 16:34:30 +0200 (Do, 15 Aug 2024) $ +## | File version: $Revision: 8104 $ +## | Last changed: $Date: 2024-08-19 10:30:01 +0200 (Mo, 19 Aug 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -27,7 +27,7 @@ NULL } .getDefaultDesign <- function(..., - type = c("sampleSize", "power", "simulation", "analysis", "characteristics"), + type = c("sampleSize", "power", "simulation", "simulationCounts", "analysis", "characteristics"), ignore = c()) { type <- match.arg(type) @@ -54,7 +54,7 @@ NULL twoSidedPower <- .getOptionalArgument("twoSidedPower", ...) if (is.null(twoSidedPower)) { - if (type %in% c("power", "simulation") && sided == 2) { + if (type %in% c("power", "simulation", "simulationCounts") && sided == 2) { twoSidedPower <- TRUE } else { twoSidedPower <- C_TWO_SIDED_POWER_DEFAULT diff --git a/R/f_design_group_sequential.R b/R/f_design_group_sequential.R index c7ca127a..2eb6a814 100644 --- a/R/f_design_group_sequential.R +++ b/R/f_design_group_sequential.R @@ -423,6 +423,10 @@ getGroupSequentialProbabilities <- function(decisionMatrix, informationRates) { .getDesignGroupSequentialKMax1 <- function(design) { design$criticalValues <- .getOneMinusQNorm(design$alpha / design$sided) design$alphaSpent[1] <- design$alpha + design$.setParameterType("typeOfDesign", C_PARAM_NOT_APPLICABLE) + if (!identical(design$typeOfDesign, C_DEFAULT_TYPE_OF_DESIGN)) { + warning("'typeOfDesign' (", design$typeOfDesign, ") will be ignored because design is fixed", call. = FALSE) + } return(invisible(design)) } diff --git a/R/f_simulation_base_count_data.R b/R/f_simulation_base_count_data.R index 3eec4efa..ab27a1f4 100644 --- a/R/f_simulation_base_count_data.R +++ b/R/f_simulation_base_count_data.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8052 $ -## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ +## | File version: $Revision: 8104 $ +## | Last changed: $Date: 2024-08-19 10:30:01 +0200 (Mo, 19 Aug 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -156,8 +156,12 @@ #' #' @template return_object_simulation_results #' @template how_to_get_help_for_generics +#' +#' @template examples_get_simulation_means #' -#' @keywords internal +#' @export +#' +#' @export #' getSimulationCounts <- function(design = NULL, ..., @@ -183,7 +187,7 @@ getSimulationCounts <- function(design = NULL, directionUpper <- TRUE } if (is.null(design)) { - design <- .getDefaultDesign(..., type = "simulation") + design <- .getDefaultDesign(..., type = "simulationCounts") .warnInCaseOfUnknownArguments( functionName = "getSimulationCounts", ignore = .getDesignArgumentsToIgnoreAtUnknownArgumentCheck( @@ -192,7 +196,7 @@ getSimulationCounts <- function(design = NULL, ) ) } else { - .assertIsTrialDesign(design) + .assertIsTrialDesignGroupSequential(design) .warnInCaseOfUnknownArguments( functionName = "getSimulationCounts", ignore = c("showStatistics"), ... @@ -426,7 +430,7 @@ getSimulationCounts <- function(design = NULL, dfStartStop$output[, "recruitTime"] <= plannedCalendarTime[k] & dfStartStop$output[, "stopCalendar"] <= plannedCalendarTime[k], ] - if (length(kthStageWithEvents) > 0 && nrow(kthStageWithEvents) > 0) { + if (length(kthStageWithEvents) > 0 && is.matrix(kthStageWithEvents) && nrow(kthStageWithEvents) > 0) { tab <- table(kthStageWithEvents[, "id"]) idx <- as.integer(names(tab)) counts[idx] <- as.vector(tab) diff --git a/inst/doc/rpact_getting_started.html b/inst/doc/rpact_getting_started.html index 1f240820..90108016 100644 --- a/inst/doc/rpact_getting_started.html +++ b/inst/doc/rpact_getting_started.html @@ -12,7 +12,7 @@ - + Getting started with rpact @@ -239,7 +239,7 @@

Getting started with rpact

Friedrich Pahlke and Gernot Wassmer

-

2024-08-15

+

2024-08-19

diff --git a/man/getSimulationCounts.Rd b/man/getSimulationCounts.Rd index fedc6bb9..ad8ef199 100644 --- a/man/getSimulationCounts.Rd +++ b/man/getSimulationCounts.Rd @@ -169,4 +169,83 @@ There you can find, e.g., \code{plot.AnalysisResults} and obtain the specific help documentation linked above by typing \code{?plot.AnalysisResults}. } -\keyword{internal} +\examples{ +# Fixed sample size design with two groups, total sample size 40, +# alternative = c(0, 0.2, 0.4, 0.8, 1), and standard deviation = 1 (the default) +getSimulationMeans(plannedSubjects = 40, maxNumberOfIterations = 10) +\dontrun{ +# Increase number of simulation iterations and compare results +# with power calculator using normal approximation +getSimulationMeans( + alternative = 0:4, stDev = 5, + plannedSubjects = 40, maxNumberOfIterations = 1000 +) +getPowerMeans( + alternative = 0:4, stDev = 5, + maxNumberOfSubjects = 40, normalApproximation = TRUE +) + +# Do the same for a three-stage O'Brien&Fleming inverse +# normal group sequential design with non-binding futility stops +designIN <- getDesignInverseNormal(typeOfDesign = "OF", futilityBounds = c(0, 0)) +x <- getSimulationMeans(designIN, + alternative = c(0:4), stDev = 5, + plannedSubjects = c(20, 40, 60), maxNumberOfIterations = 1000 +) +getPowerMeans(designIN, + alternative = 0:4, stDev = 5, + maxNumberOfSubjects = 60, normalApproximation = TRUE +) + +# Assess power and average sample size if a sample size increase is foreseen +# at conditional power 80\% for each subsequent stage based on observed overall +# effect and specified minNumberOfSubjectsPerStage and +# maxNumberOfSubjectsPerStage +getSimulationMeans(designIN, + alternative = 0:4, stDev = 5, + plannedSubjects = c(20, 40, 60), + minNumberOfSubjectsPerStage = c(NA, 20, 20), + maxNumberOfSubjectsPerStage = c(NA, 80, 80), + conditionalPower = 0.8, + maxNumberOfIterations = 50 +) + +# Do the same under the assumption that a sample size increase only takes +# place at the first interim. The sample size for the third stage is set equal +# to the second stage sample size. +mySampleSizeCalculationFunction <- function(..., stage, + minNumberOfSubjectsPerStage, + maxNumberOfSubjectsPerStage, + sampleSizesPerStage, + conditionalPower, + conditionalCriticalValue, + allocationRatioPlanned, + thetaH1, + stDevH1) { + if (stage <= 2) { + # Note that allocationRatioPlanned is as a vector of length kMax + stageSubjects <- (1 + allocationRatioPlanned[stage])^2 / + allocationRatioPlanned[stage] * + (max(0, conditionalCriticalValue + stats::qnorm(conditionalPower)))^2 / + (max(1e-12, thetaH1 / stDevH1))^2 + stageSubjects <- min(max( + minNumberOfSubjectsPerStage[stage], + stageSubjects + ), maxNumberOfSubjectsPerStage[stage]) + } else { + stageSubjects <- sampleSizesPerStage[stage - 1] + } + return(stageSubjects) +} +getSimulationMeans(designIN, + alternative = 0:4, stDev = 5, + plannedSubjects = c(20, 40, 60), + minNumberOfSubjectsPerStage = c(NA, 20, 20), + maxNumberOfSubjectsPerStage = c(NA, 80, 80), + conditionalPower = 0.8, + calcSubjectsFunction = mySampleSizeCalculationFunction, + maxNumberOfIterations = 50 +) +} + +} From 9795e41f8fd00be4c03ac8dca48a4c6e33b6d26b Mon Sep 17 00:00:00 2001 From: Friedrich Pahlke Date: Wed, 21 Aug 2024 08:34:47 +0200 Subject: [PATCH 2/2] Man pages improved --- .Rbuildignore | 1 + DESCRIPTION | 2 +- R/class_summary.R | 4 +- R/f_design_group_sequential.R | 12 ++-- R/f_simulation_base_count_data.R | 18 ++--- R/parameter_descriptions.R | 12 ++-- man/getGroupSequentialProbabilities.Rd | 6 +- man/getSimulationCounts.Rd | 97 ++++++-------------------- 8 files changed, 49 insertions(+), 103 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 90147d2b..0fd963fc 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -49,3 +49,4 @@ testthat-problems\.rds ^README\.html$ ^codecov\.yml$ Rplots\.pdf +^\.lintr$ diff --git a/DESCRIPTION b/DESCRIPTION index f4efdceb..d7560f9b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rpact Title: Confirmatory Adaptive Clinical Trial Design and Analysis Version: 4.0.1.9248 -Date: 2024-08-19 +Date: 2024-08-21 Authors@R: c( person( given = "Gernot", diff --git a/R/class_summary.R b/R/class_summary.R index e582a34d..0759a7a5 100644 --- a/R/class_summary.R +++ b/R/class_summary.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8087 $ -## | Last changed: $Date: 2024-08-15 16:34:30 +0200 (Do, 15 Aug 2024) $ +## | File version: $Revision: 8111 $ +## | Last changed: $Date: 2024-08-20 14:20:14 +0200 (Di, 20 Aug 2024) $ ## | Last changed by: $Author: pahlke $ ## | diff --git a/R/f_design_group_sequential.R b/R/f_design_group_sequential.R index 2eb6a814..0e59247c 100644 --- a/R/f_design_group_sequential.R +++ b/R/f_design_group_sequential.R @@ -13,9 +13,9 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 7742 $ -## | Last changed: $Date: 2024-03-22 13:46:29 +0100 (Fr, 22 Mrz 2024) $ -## | Last changed by: $Author: pahlke $ +## | File version: $Revision: 8112 $ +## | Last changed: $Date: 2024-08-20 15:44:53 +0200 (Di, 20 Aug 2024) $ +## | Last changed by: $Author: wassmer $ ## | #' @include f_core_constants.R @@ -38,9 +38,9 @@ NULL #' Given a sequence of information rates (fixing the correlation structure), and #' decisionMatrix with either 2 or 4 rows and kMax = length(informationRates) columns, #' this function calculates a probability matrix containing, for two rows, the probabilities:\cr -#' P(Z_1 <- l_1), P(l_1 <- Z_1 < u_1, Z_2 < l_1),..., P(l_kMax-1 <- Z_kMax-1 < u_kMax-1, Z_kMax < l_l_kMax)\cr -#' P(Z_1 <- u_1), P(l_1 <- Z_1 < u_1, Z_2 < u_1),..., P(l_kMax-1 <- Z_kMax-1 < u_kMax-1, Z_kMax < u_l_kMax)\cr -#' P(Z_1 <- Inf), P(l_1 <- Z_1 < u_1, Z_2 < Inf),..., P(l_kMax-1 <- Z_kMax-1 < u_kMax-1, Z_kMax < Inf)\cr +#' P(Z_1 < l_1), P(l_1 < Z_1 < u_1, Z_2 < l_2),..., P(l_kMax-1 < Z_kMax-1 < u_kMax-1, Z_kMax < l_l_kMax)\cr +#' P(Z_1 < u_1), P(l_1 < Z_1 < u_1, Z_2 < u_2),..., P(l_kMax-1 < Z_kMax-1 < u_kMax-1, Z_kMax < u_l_kMax)\cr +#' P(Z_1 < Inf), P(l_1 < Z_1 < u_1, Z_2 < Inf),..., P(l_kMax-1 < Z_kMax-1 < u_kMax-1, Z_kMax < Inf)\cr #' with continuation matrix\cr #' l_1,...,l_kMax\cr #' u_1,...,u_kMax\cr diff --git a/R/f_simulation_base_count_data.R b/R/f_simulation_base_count_data.R index ab27a1f4..b0e9b33b 100644 --- a/R/f_simulation_base_count_data.R +++ b/R/f_simulation_base_count_data.R @@ -13,9 +13,9 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8104 $ -## | Last changed: $Date: 2024-08-19 10:30:01 +0200 (Mo, 19 Aug 2024) $ -## | Last changed by: $Author: pahlke $ +## | File version: $Revision: 8112 $ +## | Last changed: $Date: 2024-08-20 15:44:53 +0200 (Di, 20 Aug 2024) $ +## | Last changed by: $Author: wassmer $ ## | .getInformationCountData <- function(lambda1, @@ -101,18 +101,14 @@ #' @inheritParams param_accrualTime_counts #' @inheritParams param_accrualIntensity_counts #' @inheritParams param_followUpTime_counts -#' @inheritParams param_maxNumberOfSubjects #' @inheritParams param_overdispersion_counts #' @inheritParams param_directionUpper #' @inheritParams param_allocationRatioPlanned -#' @inheritParams param_plannedSubjects -#' @inheritParams param_minNumberOfSubjectsPerStage -#' @inheritParams param_maxNumberOfSubjectsPerStage -#' @inheritParams param_conditionalPowerSimulation +#' @inheritParams param_maxNumberOfSubjects_counts #' @inheritParams param_maxNumberOfIterations -#' @inheritParams param_calcSubjectsFunction #' @inheritParams param_seed #' @inheritParams param_three_dots +#' @inheritParams param_calcSubjectsFunction #' @inheritParams param_showStatistics #' #' @details @@ -157,11 +153,9 @@ #' @template return_object_simulation_results #' @template how_to_get_help_for_generics #' -#' @template examples_get_simulation_means +#' @template examples_get_simulation_counts #' #' @export -#' -#' @export #' getSimulationCounts <- function(design = NULL, ..., diff --git a/R/parameter_descriptions.R b/R/parameter_descriptions.R index 61672665..54cb04a7 100644 --- a/R/parameter_descriptions.R +++ b/R/parameter_descriptions.R @@ -13,9 +13,9 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 7941 $ -## | Last changed: $Date: 2024-05-28 08:44:36 +0200 (Di, 28 Mai 2024) $ -## | Last changed by: $Author: pahlke $ +## | File version: $Revision: 8112 $ +## | Last changed: $Date: 2024-08-20 15:44:53 +0200 (Di, 20 Aug 2024) $ +## | Last changed by: $Author: wassmer $ ## | #' Parameter Description: "..." @@ -344,7 +344,11 @@ NULL #' @keywords internal NULL - +#' Parameter Description: plannedMaxSubjects for Counts +#' @param plannedMaxSubjects \code{plannedMaxSubjects > 0} needs to be specified. +#' @name param_maxNumberOfSubjects_counts +#' @keywords internal +NULL ## ## Analysis diff --git a/man/getGroupSequentialProbabilities.Rd b/man/getGroupSequentialProbabilities.Rd index c26d10a9..d2fe9f19 100644 --- a/man/getGroupSequentialProbabilities.Rd +++ b/man/getGroupSequentialProbabilities.Rd @@ -24,9 +24,9 @@ Calculates probabilities in the group sequential setting. Given a sequence of information rates (fixing the correlation structure), and decisionMatrix with either 2 or 4 rows and kMax = length(informationRates) columns, this function calculates a probability matrix containing, for two rows, the probabilities:\cr -P(Z_1 <- l_1), P(l_1 <- Z_1 < u_1, Z_2 < l_1),..., P(l_kMax-1 <- Z_kMax-1 < u_kMax-1, Z_kMax < l_l_kMax)\cr -P(Z_1 <- u_1), P(l_1 <- Z_1 < u_1, Z_2 < u_1),..., P(l_kMax-1 <- Z_kMax-1 < u_kMax-1, Z_kMax < u_l_kMax)\cr -P(Z_1 <- Inf), P(l_1 <- Z_1 < u_1, Z_2 < Inf),..., P(l_kMax-1 <- Z_kMax-1 < u_kMax-1, Z_kMax < Inf)\cr +P(Z_1 < l_1), P(l_1 < Z_1 < u_1, Z_2 < l_2),..., P(l_kMax-1 < Z_kMax-1 < u_kMax-1, Z_kMax < l_l_kMax)\cr +P(Z_1 < u_1), P(l_1 < Z_1 < u_1, Z_2 < u_2),..., P(l_kMax-1 < Z_kMax-1 < u_kMax-1, Z_kMax < u_l_kMax)\cr +P(Z_1 < Inf), P(l_1 < Z_1 < u_1, Z_2 < Inf),..., P(l_kMax-1 < Z_kMax-1 < u_kMax-1, Z_kMax < Inf)\cr with continuation matrix\cr l_1,...,l_kMax\cr u_1,...,u_kMax\cr diff --git a/man/getSimulationCounts.Rd b/man/getSimulationCounts.Rd index ad8ef199..13b5f937 100644 --- a/man/getSimulationCounts.Rd +++ b/man/getSimulationCounts.Rd @@ -38,6 +38,8 @@ that a warning will be displayed if unknown arguments are passed.} \item{plannedCalendarTime}{For simulating count data, the time points where an analysis is planned to be performed. Should be a vector of length \code{kMax}} +\item{plannedMaxSubjects}{\code{plannedMaxSubjects > 0} needs to be specified.} + \item{lambda1}{A numeric value or vector that represents the assumed rate of a homogeneous Poisson process in the active treatment group, there is no default.} @@ -170,82 +172,27 @@ obtain the specific help documentation linked above by typing \code{?plot.Analys } \examples{ -# Fixed sample size design with two groups, total sample size 40, -# alternative = c(0, 0.2, 0.4, 0.8, 1), and standard deviation = 1 (the default) -getSimulationMeans(plannedSubjects = 40, maxNumberOfIterations = 10) +# Fixed sample size design with two groups +getSimulationCounts( + plannedMaxSubjects = 200, + plannedCalendarTime = 8, + theta = 1.8, + lambda2 = 0.2, + maxNumberOfIterations = 1000, + fixedExposureTime = 6, + accrualTime = 3, + overdispersion = 2) \dontrun{ -# Increase number of simulation iterations and compare results -# with power calculator using normal approximation -getSimulationMeans( - alternative = 0:4, stDev = 5, - plannedSubjects = 40, maxNumberOfIterations = 1000 -) -getPowerMeans( - alternative = 0:4, stDev = 5, - maxNumberOfSubjects = 40, normalApproximation = TRUE -) - -# Do the same for a three-stage O'Brien&Fleming inverse -# normal group sequential design with non-binding futility stops -designIN <- getDesignInverseNormal(typeOfDesign = "OF", futilityBounds = c(0, 0)) -x <- getSimulationMeans(designIN, - alternative = c(0:4), stDev = 5, - plannedSubjects = c(20, 40, 60), maxNumberOfIterations = 1000 -) -getPowerMeans(designIN, - alternative = 0:4, stDev = 5, - maxNumberOfSubjects = 60, normalApproximation = TRUE -) - -# Assess power and average sample size if a sample size increase is foreseen -# at conditional power 80\% for each subsequent stage based on observed overall -# effect and specified minNumberOfSubjectsPerStage and -# maxNumberOfSubjectsPerStage -getSimulationMeans(designIN, - alternative = 0:4, stDev = 5, - plannedSubjects = c(20, 40, 60), - minNumberOfSubjectsPerStage = c(NA, 20, 20), - maxNumberOfSubjectsPerStage = c(NA, 80, 80), - conditionalPower = 0.8, - maxNumberOfIterations = 50 -) - -# Do the same under the assumption that a sample size increase only takes -# place at the first interim. The sample size for the third stage is set equal -# to the second stage sample size. -mySampleSizeCalculationFunction <- function(..., stage, - minNumberOfSubjectsPerStage, - maxNumberOfSubjectsPerStage, - sampleSizesPerStage, - conditionalPower, - conditionalCriticalValue, - allocationRatioPlanned, - thetaH1, - stDevH1) { - if (stage <= 2) { - # Note that allocationRatioPlanned is as a vector of length kMax - stageSubjects <- (1 + allocationRatioPlanned[stage])^2 / - allocationRatioPlanned[stage] * - (max(0, conditionalCriticalValue + stats::qnorm(conditionalPower)))^2 / - (max(1e-12, thetaH1 / stDevH1))^2 - stageSubjects <- min(max( - minNumberOfSubjectsPerStage[stage], - stageSubjects - ), maxNumberOfSubjectsPerStage[stage]) - } else { - stageSubjects <- sampleSizesPerStage[stage - 1] - } - return(stageSubjects) -} -getSimulationMeans(designIN, - alternative = 0:4, stDev = 5, - plannedSubjects = c(20, 40, 60), - minNumberOfSubjectsPerStage = c(NA, 20, 20), - maxNumberOfSubjectsPerStage = c(NA, 80, 80), - conditionalPower = 0.8, - calcSubjectsFunction = mySampleSizeCalculationFunction, - maxNumberOfIterations = 50 -) +# Group sequential design alpha spending function design with O'Brien and +# Fleming type boundaries: Power and test characteristics for N = 1976, +# under variable exposure time with uniform recruitment over 1.25 months, +# study time (accrual + followup) = 4 (lambda1, lambda2, and overdispersion +# as specified, no futility stopping): +getPowerCounts(design = getDesignGroupSequential( + kMax = 3, alpha = 0.025, beta = 0.2, typeOfDesign = "asOF"), + lambda1 = seq(0.08, 0.09, 0.0025), lambda2 = 0.125, + overdispersion = 5, directionUpper = FALSE, maxNumberOfSubjects = 1976, + followUpTime = 2.75, accrualTime = 1.25) } }