From a6a8adfdb4b31abe34492e9ce5b3d4a98f96e0ba Mon Sep 17 00:00:00 2001 From: Friedrich Pahlke Date: Thu, 18 Jul 2024 11:22:09 +0200 Subject: [PATCH 1/3] Minor summary improvements; seq_len used in loops --- DESCRIPTION | 4 +- NEWS.md | 1 + R/class_analysis_dataset.R | 20 ++++---- R/class_core_parameter_set.R | 24 +++------ R/class_design_set.R | 6 +-- R/class_summary.R | 86 +++++++++++++++++--------------- R/class_time.R | 18 +++---- R/f_analysis_enrichment_rates.R | 9 ++-- R/f_analysis_utilities.R | 10 ++-- R/f_core_assertions.R | 20 ++++++-- R/f_core_output_formats.R | 6 +-- R/f_core_plot.R | 10 ++-- R/f_core_utilities.R | 8 +-- R/f_design_plan_means.R | 8 +-- R/f_design_plan_rates.R | 30 +++++------ R/f_design_plan_survival.R | 11 ++-- R/f_design_plan_utilities.R | 6 +-- R/f_object_r_code.R | 6 +-- R/f_simulation_base_count_data.R | 9 ++-- R/f_simulation_base_means.R | 8 +-- 20 files changed, 156 insertions(+), 144 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0aa0ea7e..acd45de7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rpact Title: Confirmatory Adaptive Clinical Trial Design and Analysis -Version: 4.0.1.9245 -Date: 2024-06-24 +Version: 4.0.1.9246 +Date: 2024-07-17 Authors@R: c( person( given = "Gernot", diff --git a/NEWS.md b/NEWS.md index 0cddeac5..8a5a0346 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * When analyzing with a two-sided test, an issue with the calculation of the conditional rejection probability was fixed * Issue [#41](https://github.com/rpact-com/rpact/issues/41) fixed * Usage of pipe-operators improved +* Minor summary improvements # rpact 4.0.0 diff --git a/R/class_analysis_dataset.R b/R/class_analysis_dataset.R index be011c8c..ec007b9b 100644 --- a/R/class_analysis_dataset.R +++ b/R/class_analysis_dataset.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -404,7 +404,7 @@ writeDatasets <- function(datasets, file, ..., append = FALSE, quote = TRUE, sep datasetType <- NA_character_ dataFrames <- NULL - for (i in 1:length(datasets)) { + for (i in seq_len(length(datasets))) { dataset <- datasets[[i]] .assertIsDataset(dataset) if (is.na(datasetType)) { @@ -675,7 +675,7 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) { } argNames <- names(args) - for (i in 1:length(args)) { + for (i in seq_len(length(args))) { arg <- args[[i]] if (!inherits(arg, "emmGrid")) { argName <- argNames[i] @@ -715,7 +715,7 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) { stop(C_EXCEPTION_TYPE_ILLEGAL_ARGUMENT, sQuote(emmeansResults), " must be not empty") } - for (stage in 1:length(emmeansResults)) { + for (stage in seq_len(length(emmeansResults))) { if (!inherits(emmeansResults[[stage]], "emmGrid")) { stop(sprintf( paste0( @@ -769,7 +769,7 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) { ) stDevCalcMode <- getOption("rpact.dataset.stdev.calc.mode", "auto") # auto, sigma, norm, t - for (stage in 1:length(emmeansResults)) { + for (stage in seq_len(length(emmeansResults))) { emmeansResult <- emmeansResults[[stage]] emmeansResultsSummary <- summary(emmeansResult) emmeansResultsList <- as.list(emmeansResult) @@ -797,7 +797,7 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) { rpactGroupNumbers <- c(2:numberOfGroups, rpactGroupNumbers) } } - for (group in 1:length(emmeansResultsSummary$emmean)) { + for (group in seq_len(length(emmeansResultsSummary$emmean))) { stages <- c(stages, stage) groups <- c(groups, group) rpactGroupNumber <- rpactGroupNumbers[group] @@ -884,7 +884,7 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) { subsetNumbers <- as.integer(subsetNumbers) gMax <- max(subsetNumbers) + 1 validSubsetNames <- .createSubsetsByGMax(gMax, stratifiedInput = stratifiedInput, all = FALSE) - for (i in 1:length(subsetNames)) { + for (i in seq_len(length(subsetNames))) { subsetName <- subsetNames[i] if (subsetName == "" && !inherits(args[[i]], "TrialDesign")) { stop(C_EXCEPTION_TYPE_ILLEGAL_ARGUMENT, "all subsets must be named") @@ -2438,7 +2438,7 @@ DatasetMeans <- R6::R6Class("DatasetMeans", } fixedCovariateSample <- sample(values, length(subjects), replace = TRUE) - for (i in 1:length(subjects)) { + for (i in seq_len(length(subjects))) { data[[fixedCovariateName]][data$subject == subjects[i]] <- fixedCovariateSample[i] } } else if (is.numeric(values)) { @@ -2448,7 +2448,7 @@ DatasetMeans <- R6::R6Class("DatasetMeans", covMean <- runif(1, minValue, maxValue) covSD <- covMean * 0.1 showMessage <- TRUE - for (i in 1:length(subjects)) { + for (i in seq_len(length(subjects))) { groupName <- as.character(data$group[data$subject == subjects[i]])[1] covEffect <- 1 if (groupName == controlName && !is.null(covariateEffects)) { diff --git a/R/class_core_parameter_set.R b/R/class_core_parameter_set.R index 69425522..8a8b1cec 100644 --- a/R/class_core_parameter_set.R +++ b/R/class_core_parameter_set.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -81,7 +81,7 @@ FieldSet <- R6::R6Class("FieldSet", if (tableColumns > 0) { values <- unlist(args, use.names = FALSE) values <- values[values != "\n"] - for (i in 1:length(values)) { + for (i in seq_len(length(values))) { values[i] <- gsub("\n", "", values[i]) } if (!is.null(na) && length(na) == 1 && !is.na(na)) { @@ -387,16 +387,6 @@ ParameterSet <- R6::R6Class("ParameterSet", ) } }, -# .catMarkdownText = function(...) { # TODO remove -# self$.show(consoleOutputEnabled = FALSE, ...) -# if (length(self$.catLines) == 0) { -# return(invisible()) -# } -# -# for (line in self$.catLines) { -# cat(line) -# } -# }, .showParametersOfOneGroup = function(parameters, title, orderByParameterName = TRUE, consoleOutputEnabled = TRUE) { output <- "" @@ -443,7 +433,7 @@ ParameterSet <- R6::R6Class("ParameterSet", } output <- "" - for (i in 1:length(params)) { + for (i in seq_len(length(params))) { param <- params[[i]] category <- NULL parts <- strsplit(param$paramName, "$", fixed = TRUE)[[1]] @@ -756,7 +746,8 @@ ParameterSet <- R6::R6Class("ParameterSet", parameterValues <- self[[parameterName]] if (is.vector(parameterValues) && length(parameterValues) > numberOfRows) { numberOfRows <- length(parameterValues) - } else if (is.matrix(parameterValues) && (nrow(parameterValues) == 1 || ncol(parameterValues) == 1) && + } else if (is.matrix(parameterValues) && + (nrow(parameterValues) == 1 || ncol(parameterValues) == 1) && length(parameterValues) > numberOfRows) { numberOfRows <- length(parameterValues) } @@ -1525,7 +1516,8 @@ as.matrix.FieldSet <- function(x, ..., enforceRowNames = TRUE, niceColumnNamesEn if (inherits(x, "AnalysisResults")) { dfDesign <- as.data.frame(x$.design, niceColumnNamesEnabled = niceColumnNamesEnabled) dfStageResults <- as.data.frame(x$.stageResults, niceColumnNamesEnabled = niceColumnNamesEnabled) - dfStageResults <- dfStageResults[!is.na(dfStageResults[, grep("(test statistic)|(testStatistics)", colnames(dfStageResults))]), ] + dfStageResults <- dfStageResults[!is.na(dfStageResults[, + grep("(test statistic)|(testStatistics)", colnames(dfStageResults))]), ] if (length(intersect(names(dfDesign), names(dfStageResults))) == 1) { dfTemp <- merge(dfDesign, dfStageResults) if (length(intersect(names(dfTemp), names(dataFrame))) >= 1) { diff --git a/R/class_design_set.R b/R/class_design_set.R index 954a46b8..a5a64232 100644 --- a/R/class_design_set.R +++ b/R/class_design_set.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -630,7 +630,7 @@ length.TrialDesignSet <- function(x) { } colNames <- character() - for (i in 1:length(colNames1)) { + for (i in seq_len(length(colNames1))) { colName1 <- colNames1[i] colName2 <- colNames2[i] if (!identical(colName1, colName2)) { diff --git a/R/class_summary.R b/R/class_summary.R index 88704d3b..7b4ff8d7 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: 8024 $ -## | Last changed: $Date: 2024-07-02 13:50:24 +0200 (Di, 02 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -310,7 +310,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", tableColumns <- 0 maxValueWidth <- 1 if (length(self$summaryItems) > 0) { - for (i in 1:length(self$summaryItems)) { + for (i in seq_len(length(self$summaryItems))) { validValues <- na.omit(self$summaryItems[[i]]$values) if (length(validValues) > 0) { w <- max(nchar(validValues)) @@ -319,7 +319,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", } } spaceString <- paste0(rep(" ", maxValueWidth + 1), collapse = "") - for (i in 1:length(self$summaryItems)) { + for (i in seq_len(length(self$summaryItems))) { itemTitle <- self$summaryItems[[i]]$title if (!is.null(itemTitle) && length(itemTitle) == 1 && !is.na(itemTitle)) { summaryItemName <- summaryItemNames[i] @@ -383,7 +383,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", .getFormattedParameterValue = function(valuesToShow, valuesToShow2) { naText <- getOption("rpact.summary.na", "") if (length(valuesToShow) == length(valuesToShow2) && !all(is.na(valuesToShow2))) { - for (variantIndex in 1:length(valuesToShow)) { + for (variantIndex in seq_len(length(valuesToShow))) { value1 <- as.character(valuesToShow[variantIndex]) value2 <- as.character(valuesToShow2[variantIndex]) if (grepl("^ *NA *$", value1)) { @@ -1547,7 +1547,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", value[!is.na(value)] <- round(value[!is.na(value)], 2) if ((is.matrix(value) && nrow(value) > 1) || length(value) > 1) { - treatmentNames <- 1:length(value) + treatmentNames <- seq_len(length(value)) if (.isEnrichmentAnalysisResults(analysisResults)) { populations <- paste0("S", treatmentNames) gMax <- analysisResults$.stageResults$getGMax() @@ -1648,6 +1648,25 @@ SummaryFactory <- R6::R6Class("SummaryFactory", return(header) } +.addAlphaAndBetaToHeader <- function(header, design, designPlan, ..., endOfRecord = FALSE) { + header <- .concatenateSummaryText(header, paste0( + ifelse(design$sided == 1, "one-sided", "two-sided"), + ifelse(design$kMax == 1, "", " overall") + )) + powerEnabled <- .isTrialDesignInverseNormalOrGroupSequential(design) && + (is.null(designPlan) || (!.isSimulationResults(designPlan) && !identical("power", designPlan[[".objectType"]]))) + header <- .concatenateSummaryText(header, + paste0("significance level ", round(100 * design$alpha, 2), "%", + ifelse(!powerEnabled && endOfRecord, ".", "")), + sep = " " + ) + if (powerEnabled) { + header <- .concatenateSummaryText(header, + paste0("power ", round(100 * (1 - design$beta), 1), "%", ifelse(endOfRecord, ".", ""))) + } + return(header) +} + .addEnrichmentEffectListToHeader <- function(header, designPlan) { if (!grepl("SimulationResultsEnrichment", .getClassName(designPlan)) || is.null(designPlan[["effectList"]])) { @@ -1763,17 +1782,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", paste0(ifelse(design$bindingFutility, "binding", "non-binding"), " futility") ) } - header <- .concatenateSummaryText(header, paste0( - ifelse(design$sided == 1, "one-sided", "two-sided"), - ifelse(design$kMax == 1, "", " overall") - )) - header <- .concatenateSummaryText(header, - paste0("significance level ", round(100 * design$alpha, 2), "%"), - sep = " " - ) - if (.isTrialDesignInverseNormalOrGroupSequential(design)) { - header <- .concatenateSummaryText(header, paste0("power ", round(100 * (1 - design$beta), 1), "%")) - } + header <- .addAlphaAndBetaToHeader(header, design, designPlan) header <- .concatenateSummaryText(header, "undefined endpoint") if (design$kMax > 1 && .isTrialDesignInverseNormalOrGroupSequential(design)) { @@ -1826,13 +1835,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", sep = " " ) } - header <- .concatenateSummaryText(header, ifelse(design$kMax == 1, "", "overall")) - header <- .concatenateSummaryText(header, - paste0("significance level ", round(100 * design$alpha, 2), "%"), - sep = " " - ) - header <- .concatenateSummaryText(header, ifelse(design$sided == 1, "(one-sided).", "(two-sided)."), sep = " ") - + header <- .addAlphaAndBetaToHeader(header, design, designPlan, endOfRecord = TRUE) header <- paste0(header, "\n") header <- paste0(header, "The results were ") @@ -2106,10 +2109,6 @@ SummaryFactory <- R6::R6Class("SummaryFactory", header <- .addEnrichmentEffectListToHeader(header, designPlan) header <- .addAdditionalArgumentsToHeader(header, designPlan, settings) } - if (!inherits(designPlan, "SimulationResults") && designPlan$.isSampleSizeObject()) { - header <- .concatenateSummaryText(header, paste0("power ", round(100 * (1 - design$beta), 1), "%")) - } - if (inherits(designPlan, "SimulationResults")) { header <- .concatenateSummaryText( @@ -2675,21 +2674,26 @@ SummaryFactory <- R6::R6Class("SummaryFactory", if (outputSize != "small" && dataInput$getNumberOfGroups() > 1) { treatmentRateParamName <- "overallPi1" controlRateParamName <- "overallPi2" + enforceFirstCase <- TRUE if (.isEnrichmentStageResults(stageResults)) { treatmentRateParamName <- "overallPisTreatment" controlRateParamName <- "overallPisControl" + enforceFirstCase <- FALSE } else if (.isMultiArmStageResults(stageResults)) { treatmentRateParamName <- "overallPiTreatments" controlRateParamName <- "overallPiControl" } summaryFactory$addParameter(stageResults, parameterName = treatmentRateParamName, - parameterCaption = "Cumulative treatment rate", roundDigits = digitsGeneral + parameterCaption = "Cumulative treatment rate", + roundDigits = digitsGeneral ) + summaryFactory$addParameter(stageResults, parameterName = controlRateParamName, parameterCaption = "Cumulative control rate", - roundDigits = digitsGeneral, enforceFirstCase = TRUE + roundDigits = digitsGeneral, + enforceFirstCase = enforceFirstCase ) } } @@ -3589,15 +3593,6 @@ SummaryFactory <- R6::R6Class("SummaryFactory", } if (survivalEnabled) { - if (design$kMax > 1 && !(inherits(designPlan, "TrialDesignPlanSurvival") && - designPlan$.isSampleSizeObject())) { - summaryFactory$addParameter(designPlan, - parameterName = "expectedNumberOfEvents", - parameterCaption = "Expected number of events", - roundDigits = digitsSampleSize, transpose = TRUE - ) - } - if (outputSize %in% c("medium", "large")) { summaryFactory$addParameter(designPlan, parameterName = parameterNameEvents, @@ -3606,6 +3601,14 @@ SummaryFactory <- R6::R6Class("SummaryFactory", ), roundDigits = digitsSampleSize, cumsumEnabled = FALSE ) + if (!enrichmentEnabled && design$kMax > 1) { + summaryFactory$addParameter(designPlan, + parameterName = ifelse(designPlan$.isSampleSizeObject(), + "expectedEventsH1", "expectedNumberOfEvents"), + parameterCaption = "Expected number of events under H1", + roundDigits = digitsSampleSize, cumsumEnabled = FALSE + ) + } } if (outputSize == "large") { @@ -3618,7 +3621,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", summaryFactory$addParameter(designPlan, parameterName = "studyDuration", - parameterCaption = "Expected study duration", + parameterCaption = "Expected study duration under H1", roundDigits = digitsTime, smoothedZeroFormat = TRUE, transpose = TRUE @@ -3667,7 +3670,8 @@ SummaryFactory <- R6::R6Class("SummaryFactory", if (!countDataEnabled) { legendEntry <- list("(t)" = "treatment effect scale") - if (ncol(designPlan$criticalValuesEffectScale) > 0 && !all(is.na(designPlan$criticalValuesEffectScale))) { + if (ncol(designPlan$criticalValuesEffectScale) > 0 && + !all(is.na(designPlan$criticalValuesEffectScale))) { summaryFactory$addParameter(designPlan, parameterName = "criticalValuesEffectScale", parameterCaption = ifelse(.isDelayedInformationEnabled(design = design), diff --git a/R/class_time.R b/R/class_time.R index 59dbfc1d..cfc48a3b 100644 --- a/R/class_time.R +++ b/R/class_time.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 7962 $ -## | Last changed: $Date: 2024-05-31 13:41:37 +0200 (Fr, 31 Mai 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -714,7 +714,7 @@ PiecewiseSurvivalTime <- R6::R6Class("PiecewiseSurvivalTime", } else { piecewiseSurvivalTimeStr <- format(self$piecewiseSurvivalTime) lambda2Str <- format(self$lambda2) - for (i in 1:length(self$piecewiseSurvivalTime)) { + for (i in seq_len(length(self$piecewiseSurvivalTime))) { if (i < length(self$piecewiseSurvivalTime)) { self$.cat(" ", piecewiseSurvivalTimeStr[i], " - <", piecewiseSurvivalTimeStr[i + 1], ": ", @@ -811,7 +811,7 @@ PiecewiseSurvivalTime <- R6::R6Class("PiecewiseSurvivalTime", pwSurvStartTimes <- c(0) pwSurvLambda2 <- c() pwSurvTimeNames <- names(pwSurvTimeList) - for (i in 1:length(pwSurvTimeNames)) { + for (i in seq_len(length(pwSurvTimeNames))) { timePeriod <- pwSurvTimeNames[i] lambdaValue <- pwSurvTimeList[[timePeriod]] .assertIsSingleNumber(lambdaValue, paste0("pwSurvLambda[", i, "]")) @@ -1497,7 +1497,7 @@ AccrualTime <- R6::R6Class("AccrualTime", !self$absoluteAccrualIntensityEnabled) { self$remainingTime <- NA_real_ self$.setParameterType("remainingTime", C_PARAM_NOT_APPLICABLE) - self$accrualTime <- self$accrualTime[1:length(self$accrualIntensity)] + self$accrualTime <- self$accrualTime[seq_len(length(self$accrualIntensity))] } self$.initAccrualIntensityAbsolute() @@ -1556,7 +1556,7 @@ AccrualTime <- R6::R6Class("AccrualTime", } else { accrualTimeStr <- format(self$accrualTime) accrualIntensityStr <- format(self$accrualIntensity) - for (i in 1:length(self$accrualTime)) { + for (i in seq_len(length(self$accrualTime))) { prefix <- ifelse(i == length(self$accrualTime) - 1, "<=", " <") suffix <- "" if (!self$maxNumberOfSubjectsIsUserDefined) { @@ -1602,7 +1602,7 @@ AccrualTime <- R6::R6Class("AccrualTime", }, .getFormula = function() { s <- "" - for (i in 1:length(self$accrualTime)) { + for (i in seq_len(length(self$accrualTime))) { if (i < length(self$accrualTime)) { s <- paste0( s, (round(self$accrualTime[i + 1], 4) - round(self$accrualTime[i], 4)), @@ -1625,7 +1625,7 @@ AccrualTime <- R6::R6Class("AccrualTime", } numberOfSubjects <- 0 - for (i in 1:length(self$accrualTime)) { + for (i in seq_len(length(self$accrualTime))) { if (i < length(self$accrualTime)) { numberOfSubjects <- numberOfSubjects + (self$accrualTime[i + 1] - self$accrualTime[i]) * self$accrualIntensity[i] @@ -1967,7 +1967,7 @@ AccrualTime <- R6::R6Class("AccrualTime", timeRegions <- names(accrualTimeList) endOfAccrualIsUndefined <- FALSE self$accrualTime <- c(self$accrualTime, 0) - for (i in 1:length(timeRegions)) { + for (i in seq_len(length(timeRegions))) { timePeriod <- timeRegions[i] accrualTimeValue <- accrualTimeList[[timePeriod]] .assertIsSingleNumber(accrualTimeValue, paste0("accrualTime[", i, "]")) diff --git a/R/f_analysis_enrichment_rates.R b/R/f_analysis_enrichment_rates.R index da8979b7..8738fcd4 100644 --- a/R/f_analysis_enrichment_rates.R +++ b/R/f_analysis_enrichment_rates.R @@ -13,8 +13,8 @@ ## | ## | 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) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -56,10 +56,11 @@ NULL } else { actMl <- rep(NA_real_, length(subset)) ctrMl <- rep(NA_real_, length(subset)) - for (population in (1:length(subset))) { + for (population in seq_len(length(subset))) { y <- .getFarringtonManningValues( rate1 = actEv[population] / actN[population], - rate2 = ctrEv[population] / ctrN[population], theta = thetaH0, allocation = actN[population] / ctrN[population], method = "diff" + rate2 = ctrEv[population] / ctrN[population], theta = thetaH0, + allocation = actN[population] / ctrN[population], method = "diff" ) actMl[population] <- y$ml1 ctrMl[population] <- y$ml2 diff --git a/R/f_analysis_utilities.R b/R/f_analysis_utilities.R index bed2a330..c4065667 100644 --- a/R/f_analysis_utilities.R +++ b/R/f_analysis_utilities.R @@ -13,8 +13,8 @@ ## | ## | 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) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -580,7 +580,7 @@ NULL } .removeDesignFromArgs <- function(args) { - for (i in 1:length(args)) { + for (i in seq_len(length(args))) { if (.isTrialDesign(args[[i]])) { return(args[-i]) } @@ -655,7 +655,7 @@ NULL } if (length(unknownArgs) > 0) { - for (i in 1:length(unknownArgs)) { + for (i in seq_len(length(unknownArgs))) { unknownArgs[i] <- argNames[argNamesLower == unknownArgs[i]][1] } if (length(unknownArgs) == 1) { @@ -683,7 +683,7 @@ NULL indices <- gregexpr("[A-Z]", x)[[1]] parts <- strsplit(x, "[A-Z]")[[1]] result <- "" - for (i in 1:length(indices)) { + for (i in seq_len(length(indices))) { index <- indices[i] y <- tolower(substring(x, index, index)) result <- paste0(result, parts[i], sep, y) diff --git a/R/f_core_assertions.R b/R/f_core_assertions.R index d8dafe2f..98a76d7f 100644 --- a/R/f_core_assertions.R +++ b/R/f_core_assertions.R @@ -13,8 +13,8 @@ ## | ## | 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) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -178,6 +178,16 @@ NULL } } +.assertIsTrialDesignInverseNormalOrGroupSequentialOrFisher <- function(design) { + if (!.isTrialDesignInverseNormalOrGroupSequential(design) && !.isTrialDesignFisher(design)) { + stop( + C_EXCEPTION_TYPE_ILLEGAL_ARGUMENT, + "'design' must be an instance of class 'TrialDesignInverseNormal', 'TrialDesignGroupSequential', or 'TrialDesignFisher' (is '", + .getClassName(design), "')" + ) + } +} + .assertIsTrialDesignInverseNormalOrFisher <- function(design) { if (!.isTrialDesignInverseNormalOrFisher(design)) { stop( @@ -1298,8 +1308,8 @@ NULL definedArguments <- c() undefinedArguments <- c() - for (i in 1:length(args)) { - arg <- args[i] + for (i in seq_len(length(args))) { + arg <- args[[i]] argName <- argNames[i] if (missing(arg) || (!is.null(arg) && sum(is.na(arg)) > 0)) { undefinedArguments <- c(undefinedArguments, argName) @@ -1403,7 +1413,7 @@ NULL } ignore <- c(ignore, "showWarnings") argNames <- names(args) - for (i in 1:length(args)) { + for (i in seq_len(length(args))) { arg <- args[[i]] argName <- ifelse(is.null(argNames[i]) || argNames[i] == "", ifelse(inherits(arg, "StageResults"), "stageResultsName", paste0("%param", i, "%")), diff --git a/R/f_core_output_formats.R b/R/f_core_output_formats.R index 8844b17a..de457234 100644 --- a/R/f_core_output_formats.R +++ b/R/f_core_output_formats.R @@ -13,8 +13,8 @@ ## | ## | 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) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -138,7 +138,7 @@ C_OUTPUT_FORMAT_DEFAULT_VALUES <- pairlist( } fv <- .getFormattedValue(value[value >= 1e-04], digits = 4, nsmall = 4) - fv <- fv[!((1:length(fv)) %in% grep("e", fv))] + fv <- fv[!((seq_len(length(fv))) %in% grep("e", fv))] numberOfCharacters <- ifelse(length(fv) > 0, nchar(fv[1]), 6) numberOfCharacters <- ifelse(numberOfCharacters < 6, 6, numberOfCharacters) decimalPlaces <- numberOfCharacters - 2 diff --git a/R/f_core_plot.R b/R/f_core_plot.R index 5e4b3173..6671d33f 100644 --- a/R/f_core_plot.R +++ b/R/f_core_plot.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 7750 $ -## | Last changed: $Date: 2024-03-26 15:44:44 +0100 (Di, 26 Mrz 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -633,7 +633,7 @@ getAvailablePlotTypes <- function(obj, output = c("numeric", "caption", "numcap" ) } - yAxisCmds <- c() + yAxisCmds <- character() if (length(yParameterNames) == 1) { yAxisCmds <- .createValidParameterName(objectName, yParameterNames) } else { @@ -645,7 +645,7 @@ getAvailablePlotTypes <- function(obj, output = c("numeric", "caption", "numcap" cat(" y-axis: ", yAxisCmds, "\n", sep = "") } else { cat(" y-axes:\n") - for (i in 1:length(yAxisCmds)) { + for (i in seq_len(length(yAxisCmds))) { cat(" y", i, ": ", yAxisCmds[i], "\n", sep = "") } } @@ -1482,7 +1482,7 @@ getAvailablePlotTypes <- function(obj, output = c("numeric", "caption", "numcap" return(lambda2[1]) } - for (i in 1:length(piecewiseSurvivalTime)) { + for (i in seq_len(length(piecewiseSurvivalTime))) { if (time <= piecewiseSurvivalTime[i]) { return(lambda2[i]) } diff --git a/R/f_core_utilities.R b/R/f_core_utilities.R index ac347112..1ebe4add 100644 --- a/R/f_core_utilities.R +++ b/R/f_core_utilities.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -68,7 +68,7 @@ NULL indices <- gregexpr("[A-Z]", x)[[1]] parts <- strsplit(x, "[A-Z]")[[1]] result <- "" - for (i in 1:length(indices)) { + for (i in seq_len(length(indices))) { index <- indices[i] y <- tolower(substring(x, index, index)) if (title) { @@ -249,7 +249,7 @@ NULL } space <- ifelse(grepl(" $", separator), "", " ") - part1 <- x[1:length(x) - 1] + part1 <- x[seq_len(length(x)) - 1] part2 <- x[length(x)] return(paste0(paste(part1, collapse = separator), separator, space, mode, " ", part2)) } diff --git a/R/f_design_plan_means.R b/R/f_design_plan_means.R index 6e2d931a..6b5e20f7 100644 --- a/R/f_design_plan_means.R +++ b/R/f_design_plan_means.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -149,7 +149,7 @@ NULL allocationRatioPlanned = C_ALLOCATION_RATIO_DEFAULT) { nFixed <- rep(NA_real_, length(alternative)) - for (i in 1:length(alternative)) { + for (i in seq_len(length(alternative))) { theta <- alternative[i] if (groups == 1) { @@ -409,7 +409,7 @@ NULL informationRates <- designCharacteristics$information / designCharacteristics$shift - for (i in 1:length(fixedSampleSize$alternative)) { + for (i in seq_len(length(fixedSampleSize$alternative))) { maxNumberOfSubjects[i] <- fixedSampleSize$nFixed[i] * designCharacteristics$inflationFactor numberOfSubjects[, i] <- maxNumberOfSubjects[i] * diff --git a/R/f_design_plan_rates.R b/R/f_design_plan_rates.R index e1ede337..23ef7c5f 100644 --- a/R/f_design_plan_rates.R +++ b/R/f_design_plan_rates.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8027 $ -## | Last changed: $Date: 2024-07-03 16:00:55 +0200 (Mi, 03 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -86,7 +86,7 @@ NULL maxNumberOfSubjects[j] / (1 + allocationRatioPlanned[j]) n2 <- n1 / allocationRatioPlanned[j] - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -111,7 +111,7 @@ NULL criticalValuesEffectScaleUpper[i, j] <- pi1Bound - pi2 } if (design$sided == 2) { - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -143,7 +143,7 @@ NULL n1 <- allocationRatioPlanned[j] * design$informationRates * maxNumberOfSubjects[j] / (1 + allocationRatioPlanned[j]) n2 <- n1 / allocationRatioPlanned[j] - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -177,7 +177,7 @@ NULL n1 <- allocationRatioPlanned[j] * design$informationRates * maxNumberOfSubjects[j] / (1 + allocationRatioPlanned[j]) n2 <- n1 / allocationRatioPlanned[j] - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -209,7 +209,7 @@ NULL n1 <- allocationRatioPlanned[j] * design$informationRates * maxNumberOfSubjects[j] / (1 + allocationRatioPlanned[j]) n2 <- n1 / allocationRatioPlanned[j] - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -234,7 +234,7 @@ NULL criticalValuesEffectScaleUpper[i, j] <- pi1Bound / pi2 } if (design$sided == 2) { - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -266,7 +266,7 @@ NULL n1 <- allocationRatioPlanned[j] * design$informationRates * maxNumberOfSubjects[j] / (1 + allocationRatioPlanned[j]) n2 <- n1 / allocationRatioPlanned[j] - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -299,7 +299,7 @@ NULL n1 <- allocationRatioPlanned[j] * design$informationRates * maxNumberOfSubjects[j] / (1 + allocationRatioPlanned[j]) n2 <- n1 / allocationRatioPlanned[j] - for (i in (1:length(boundaries))) { + for (i in seq_len(length(boundaries))) { tryCatch( { pi1Bound <- uniroot( @@ -341,7 +341,7 @@ NULL if (groups == 1) { nFixed <- rep(NA_real_, length(pi1)) - for (i in 1:length(pi1)) { + for (i in seq_len(length(pi1))) { if (normalApproximation) { nFixed[i] <- (.getOneMinusQNorm(alpha / sided) * sqrt(thetaH0 * (1 - thetaH0)) + .getOneMinusQNorm(beta) * sqrt(pi1[i] * (1 - pi1[i])))^2 / @@ -435,7 +435,7 @@ NULL allocationRatioPlannedVec <- rep(NA_real_, length(pi1)) } - for (i in 1:length(pi1)) { + for (i in seq_len(length(pi1))) { if (!riskRatio) { # allocationRatioPlanned = 0 provides optimum sample size if (allocationRatioPlanned == 0) { @@ -538,7 +538,7 @@ NULL informationRates <- designCharacteristics$information / designCharacteristics$shift - for (i in 1:length(fixedSampleSize$pi1)) { + for (i in seq_len(length(fixedSampleSize$pi1))) { maxNumberOfSubjects[i] <- fixedSampleSize$nFixed[i] * designCharacteristics$inflationFactor numberOfSubjects[, i] <- maxNumberOfSubjects[i] * c( @@ -868,7 +868,7 @@ getPowerRates <- function(design = NULL, ..., } else { if (!riskRatio) { designPlan$effect <- pi1 - pi2 - thetaH0 - for (i in (1:length(pi1))) { + for (i in seq_len(length(pi1))) { fm <- .getFarringtonManningValues( rate1 = pi1[i], rate2 = pi2, theta = thetaH0, allocation = allocationRatioPlanned, method = "diff" @@ -883,7 +883,7 @@ getPowerRates <- function(design = NULL, ..., } } else { designPlan$effect <- pi1 / pi2 - thetaH0 - for (i in (1:length(pi1))) { + for (i in seq_len(length(pi1))) { fm <- .getFarringtonManningValues( rate1 = pi1[i], rate2 = pi2, theta = thetaH0, allocation = allocationRatioPlanned, method = "ratio" diff --git a/R/f_design_plan_survival.R b/R/f_design_plan_survival.R index b9b575cc..ee46352f 100644 --- a/R/f_design_plan_survival.R +++ b/R/f_design_plan_survival.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8049 $ +## | Last changed: $Date: 2024-07-17 17:03:09 +0200 (Mi, 17 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -1479,7 +1479,7 @@ NULL } stoppingProbs[kMax] <- 1 - sum(stoppingProbs[1:(kMax - 1)]) - + studyDuration[i] <- analysisTime[, i] %*% stoppingProbs expectedNumberOfSubjectsH1[i] <- numberOfSubjects[, i] %*% stoppingProbs @@ -2592,6 +2592,7 @@ getPowerSurvival <- function(design = NULL, ..., lambda1 <- rep(NA_real_, numberOfResults) } + studyDuration <- rep(NA_real_, numberOfResults) for (i in 1:numberOfResults) { # Analysis times up <- 2 @@ -2653,10 +2654,10 @@ getPowerSurvival <- function(design = NULL, ..., powerAndAverageSampleNumber$futilityPerStage[is.na( powerAndAverageSampleNumber$futilityPerStage[, i] ), i] <- 0 - + stoppingProbs[, i] <- powerAndAverageSampleNumber$rejectPerStage[, i] + c(powerAndAverageSampleNumber$futilityPerStage[, i], 0) - + stoppingProbs[kMax, i] <- 1 - sum(stoppingProbs[1:(kMax - 1), i]) designPlan$studyDuration[i] <- designPlan$analysisTime[, i] %*% stoppingProbs[, i] designPlan$.setParameterType("studyDuration", C_PARAM_GENERATED) diff --git a/R/f_design_plan_utilities.R b/R/f_design_plan_utilities.R index e63df07a..2339f36e 100644 --- a/R/f_design_plan_utilities.R +++ b/R/f_design_plan_utilities.R @@ -13,8 +13,8 @@ ## | ## | 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) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -385,7 +385,7 @@ NULL accrualTime[1:(length(accrualTime) - 1)] } densityVector <- accrualIntensity / sum(densityIntervals * accrualIntensity) - for (l in 1:length(densityVector)) { + for (l in seq_len(length(densityVector))) { if (timeValue <= accrualTime[l]) { if (l == 1) { return(timeValue * densityVector[l] * maxNumberOfSubjects) diff --git a/R/f_object_r_code.R b/R/f_object_r_code.R index 3e3f84a3..0be5a7d7 100644 --- a/R/f_object_r_code.R +++ b/R/f_object_r_code.R @@ -13,8 +13,8 @@ ## | ## | 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) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -108,7 +108,7 @@ NULL x <- t(x) } - for (i in 1:length(x)) { + for (i in seq_len(length(x))) { if (nchar(expectedResult) > 0) { expectedResult <- paste0(expectedResult, ", ") } diff --git a/R/f_simulation_base_count_data.R b/R/f_simulation_base_count_data.R index ec8faf01..3eec4efa 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: 7920 $ -## | Last changed: $Date: 2024-05-23 13:56:24 +0200 (Do, 23 Mai 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -431,7 +431,7 @@ getSimulationCounts <- function(design = NULL, idx <- as.integer(names(tab)) counts[idx] <- as.vector(tab) } - counts1 <- counts[1:length(timeUnderObservation1)] + counts1 <- counts[seq_len(length(timeUnderObservation1))] counts2 <- counts[(length(recruit1) + 1):(length(recruit1) + length(timeUnderObservation2))] } else { counts1 <- dfStartStop$nEvents[1:n1] @@ -439,7 +439,8 @@ getSimulationCounts <- function(design = NULL, } nb <- .getNegativeBinomialEstimates( counts1 = counts1, counts2 = counts2, - t1 = timeUnderObservation1, t2 = timeUnderObservation2 + t1 = timeUnderObservation1, + t2 = timeUnderObservation2 ) info_Analysis <- .getInformationCountData( lambda1 = nb[1], diff --git a/R/f_simulation_base_means.R b/R/f_simulation_base_means.R index e2ee9fe2..676478c0 100644 --- a/R/f_simulation_base_means.R +++ b/R/f_simulation_base_means.R @@ -13,8 +13,8 @@ ## | ## | Contact us for information about our services: info@rpact.com ## | -## | File version: $Revision: 8023 $ -## | Last changed: $Date: 2024-07-01 08:50:30 +0200 (Mo, 01 Jul 2024) $ +## | File version: $Revision: 8052 $ +## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -186,7 +186,7 @@ getSimulationMeans <- function(design = NULL, ..., ), ... ) } else { - .assertIsTrialDesign(design) + .assertIsTrialDesignInverseNormalOrGroupSequentialOrFisher(design) .warnInCaseOfUnknownArguments(functionName = "getSimulationMeans", ignore = c("showStatistics"), ...) .warnInCaseOfTwoSidedPowerArgument(...) design <- .resetPipeOperatorQueue(design) @@ -433,6 +433,8 @@ getSimulationMeans <- function(design = NULL, ..., designNumber <- 2L } else if (.isTrialDesignFisher(design)) { designNumber <- 3L + } else { + stop(C_EXCEPTION_TYPE_RUNTIME_ISSUE, "design type ", sQuote(.getClassName(design)), " not supported") } if (.isTrialDesignFisher(design)) { From 39af87cd033641e91635069589f941da7a21f9e4 Mon Sep 17 00:00:00 2001 From: Friedrich Pahlke Date: Thu, 18 Jul 2024 11:26:10 +0200 Subject: [PATCH 2/3] Issue #44 fixed --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 8a5a0346..6352227c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,7 @@ * Minimum version of suggested package `ggplot2` changed from 2.2.0 to 3.2.0 * When analyzing with a two-sided test, an issue with the calculation of the conditional rejection probability was fixed -* Issue [#41](https://github.com/rpact-com/rpact/issues/41) fixed +* Issues [#41](https://github.com/rpact-com/rpact/issues/41) and [#44](https://github.com/rpact-com/rpact/issues/44) fixed * Usage of pipe-operators improved * Minor summary improvements From 14adc1eeb5e00867307a0aab8f2fcd4b7b860cbb Mon Sep 17 00:00:00 2001 From: Friedrich Pahlke Date: Thu, 18 Jul 2024 13:16:42 +0200 Subject: [PATCH 3/3] Summary of fixed sample analysis improved --- R/class_summary.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/class_summary.R b/R/class_summary.R index 7b4ff8d7..6c4b58b1 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: 8052 $ -## | Last changed: $Date: 2024-07-18 11:19:40 +0200 (Do, 18 Jul 2024) $ +## | File version: $Revision: 8054 $ +## | Last changed: $Date: 2024-07-18 13:16:10 +0200 (Do, 18 Jul 2024) $ ## | Last changed by: $Author: pahlke $ ## | @@ -1826,7 +1826,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory", header <- "" if (design$kMax == 1) { - header <- paste0(header, "Fixed sample analysis,") + header <- paste0(header, "Fixed sample analysis") } else { header <- paste0(header, "Sequential analysis with a maximum of ", design$kMax, " looks") prefix <- ifelse(design$.isDelayedResponseDesign(), "delayed response ", "")