Skip to content

Commit

Permalink
Several improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fpahlke committed Sep 26, 2024
1 parent cb540fe commit 5e72e82
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 97 deletions.
4 changes: 2 additions & 2 deletions R/class_core_parameter_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8270 $
## | Last changed: $Date: 2024-09-25 16:37:39 +0200 (Mi, 25 Sep 2024) $
## | File version: $Revision: 8274 $
## | Last changed: $Date: 2024-09-26 11:33:59 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down
30 changes: 16 additions & 14 deletions R/class_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8273 $
## | Last changed: $Date: 2024-09-25 17:19:43 +0200 (Mi, 25 Sep 2024) $
## | File version: $Revision: 8276 $
## | Last changed: $Date: 2024-09-26 13:37:54 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -406,15 +406,15 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
naText <- getOption("rpact.summary.na", "")
if (length(valuesToShow) == length(valuesToShow2) && !all(is.na(valuesToShow2))) {
for (variantIndex in seq_len(length(valuesToShow))) {
value1 <- as.character(valuesToShow[variantIndex])
value2 <- as.character(valuesToShow2[variantIndex])
value1 <- trimws(as.character(valuesToShow[variantIndex]))
value2 <- trimws(as.character(valuesToShow2[variantIndex]))
if (grepl("^ *NA *$", value1)) {
value1 <- naText
}
if (grepl("^ *NA *$", value2)) {
value2 <- naText
}
if (trimws(value1) == "" && trimws(value2) == "") {
if (value1 == "" && value2 == "") {
valuesToShow[variantIndex] <- naText
} else {
valuesToShow[variantIndex] <- sprintf(self$intervalFormat, value1, value2)
Expand Down Expand Up @@ -1296,7 +1296,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
comparisonH0 <- " = "
comparisonH1 <- NA_character_
if (inherits(object, "AnalysisResults") && !is.null(directionUpper)) {
comparisonH1 <- ifelse(sided == 2, " != ", ifelse(directionUpper, " > ", " < "))
comparisonH1 <- ifelse(sided == 2, " != ", ifelse(!isFALSE(directionUpper), " > ", " < "))
}

if (!is.null(object[["thetaH0"]])) {
Expand Down Expand Up @@ -2093,36 +2093,36 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
inherits(designPlan, "SimulationResults"))) {
if (settings$groups == 1) {
if (!is.null(designPlan[["pi1"]]) && length(designPlan$pi1) == 1) {
treatmentRateText <- paste0("H1: treatment rate pi = ", round(designPlan$pi1, 3))
treatmentRateText <- paste0("H1: pi = ", round(designPlan$pi1, 3))
} else {
treatmentRateText <- "H1: treatment rate pi as specified"
treatmentRateText <- "H1: pi as specified"
}

header <- paste0(header, ",\n", .createSummaryHypothesisText(designPlan, summaryFactory))
header <- .concatenateSummaryText(header, treatmentRateText)
header <- .addAdditionalArgumentsToHeader(header, designPlan, settings)
} else {
if (!is.null(designPlan[["pi1"]]) && length(designPlan$pi1) == 1) {
treatmentRateText <- paste0("H1: treatment rate pi(1) = ", round(designPlan$pi1, 3))
treatmentRateText <- paste0("H1: pi(1) = ", round(designPlan$pi1, 3))
} else if (!is.null(designPlan[["piMaxVector"]]) && length(designPlan$piMaxVector) == 1) {
treatmentRateText <- paste0(
"H1: treatment rate pi_max = ",
"H1: pi_max = ",
.arrayToString(round(designPlan$piMaxVector, 3), vectorLookAndFeelEnabled = TRUE)
)
} else if (settings$enrichmentEnabled && !is.null(designPlan[["effectList"]]) &&
!is.null(designPlan$effectList[["piTreatments"]])) {
piTreatments <- designPlan$effectList[["piTreatments"]]
if (is.matrix(piTreatments) && nrow(piTreatments) == 1) {
treatmentRateText <- paste0(
"H1: assumed treatment rate pi(treatment) = ",
"H1: assumed pi(treatment) = ",
.arrayToString(round(designPlan$effectList$piTreatments, 3), vectorLookAndFeelEnabled = TRUE)
)
} else {
treatmentRateText <- paste0("H1: assumed treatment rate pi(treatment) as specified")
treatmentRateText <- paste0("H1: assumed pi(treatment) as specified")
}
} else {
treatmentRateText <- paste0(
"H1: treatment rate pi",
"H1: pi",
ifelse(settings$multiArmEnabled, "_max", "(1)"), " as specified"
)
}
Expand Down Expand Up @@ -2742,7 +2742,9 @@ SummaryFactory <- R6::R6Class("SummaryFactory",

summaryFactory <- SummaryFactory$new(
object = object,
intervalFormat = intervalFormat, output = output, markdown = markdown
intervalFormat = intervalFormat,
output = output,
markdown = markdown
)

.addDesignInformationToSummary(design, object, summaryFactory,
Expand Down
66 changes: 46 additions & 20 deletions R/f_analysis_base_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8225 $
## | Last changed: $Date: 2024-09-18 09:38:40 +0200 (Mi, 18 Sep 2024) $
## | File version: $Revision: 8276 $
## | Last changed: $Date: 2024-09-26 13:37:54 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -337,10 +337,14 @@ NULL
# final confidence interval & median unbiased estimate
startTime <- Sys.time()
finalConfidenceIntervals <- .getFinalConfidenceIntervalMeans(
design = design, dataInput = dataInput,
thetaH0 = thetaH0, stage = stage, directionUpper = directionUpper,
design = design,
dataInput = dataInput,
thetaH0 = thetaH0,
stage = stage,
directionUpper = directionUpper,
normalApproximation = normalApproximation,
equalVariances = equalVariances, tolerance = tolerance
equalVariances = equalVariances,
tolerance = tolerance
)

if (!is.null(finalConfidenceIntervals)) {
Expand Down Expand Up @@ -536,7 +540,7 @@ NULL

direction <- "undefined"
if (design$sided == 1) {
direction <- ifelse(directionUpper, C_DIRECTION_UPPER, C_DIRECTION_LOWER)
direction <- ifelse(!isFALSE(directionUpper), C_DIRECTION_UPPER, C_DIRECTION_LOWER)
}

if (dataInput$getNumberOfGroups() == 1) {
Expand Down Expand Up @@ -1604,21 +1608,27 @@ NULL

finalConfidenceIntervalGeneral[1] <- .getDecisionMatrixRoot(
design = design,
stage = finalStage, stageResults = stageResults, tolerance = tolerance,
stage = finalStage,
stageResults = stageResults,
tolerance = tolerance,
firstParameterName = firstParameterName,
case = "finalConfidenceIntervalGeneralLower"
)

finalConfidenceIntervalGeneral[2] <- .getDecisionMatrixRoot(
design = design,
stage = finalStage, stageResults = stageResults, tolerance = tolerance,
stage = finalStage,
stageResults = stageResults,
tolerance = tolerance,
firstParameterName = firstParameterName,
case = "finalConfidenceIntervalGeneralUpper"
)

medianUnbiasedGeneral <- .getDecisionMatrixRoot(
design = design,
stage = finalStage, stageResults = stageResults, tolerance = tolerance,
stage = finalStage,
stageResults = stageResults,
tolerance = tolerance,
firstParameterName = firstParameterName,
case = "medianUnbiasedGeneral"
)
Expand Down Expand Up @@ -1649,7 +1659,7 @@ NULL
finalConfidenceInterval[1] <- medianUnbiased - value
finalConfidenceInterval[2] <- medianUnbiased + value
} else {
directionUpperSign <- ifelse(directionUpper, 1, -1)
directionUpperSign <- ifelse(!isFALSE(directionUpper), 1, -1)
finalConfidenceInterval <- finalConfidenceIntervalGeneral *
stageResults$overallStDevs[finalStage] + directionUpperSign * thetaH0
medianUnbiased <- medianUnbiasedGeneral *
Expand Down Expand Up @@ -1933,7 +1943,8 @@ NULL
.assertIsValidThetaH0DataInput(thetaH0, dataInput)
.warnInCaseOfUnknownArguments(
functionName = "getFinalConfidenceIntervalMeans",
ignore = c(.getDesignArgumentsToIgnoreAtUnknownArgumentCheck(design, powerCalculationEnabled = TRUE), "stage"), ...
ignore = c(.getDesignArgumentsToIgnoreAtUnknownArgumentCheck(
design, powerCalculationEnabled = TRUE), "stage"), ...
)

if (design$kMax == 1) {
Expand All @@ -1952,25 +1963,40 @@ NULL

if (.isTrialDesignGroupSequential(design)) {
return(.getFinalConfidenceIntervalMeansGroupSequential(
design = design, dataInput = dataInput, stage = stage, thetaH0 = thetaH0,
directionUpper = directionUpper, normalApproximation = normalApproximation,
equalVariances = equalVariances, tolerance = tolerance
design = design,
dataInput = dataInput,
stage = stage,
thetaH0 = thetaH0,
directionUpper = directionUpper,
normalApproximation = normalApproximation,
equalVariances = equalVariances,
tolerance = tolerance
))
}

if (.isTrialDesignInverseNormal(design)) {
return(.getFinalConfidenceIntervalMeansInverseNormal(
design = design, dataInput = dataInput, stage = stage, thetaH0 = thetaH0,
directionUpper = directionUpper, normalApproximation = normalApproximation,
equalVariances = equalVariances, tolerance = tolerance
design = design,
dataInput = dataInput,
stage = stage,
thetaH0 = thetaH0,
directionUpper = directionUpper,
normalApproximation = normalApproximation,
equalVariances = equalVariances,
tolerance = tolerance
))
}

if (.isTrialDesignFisher(design)) {
return(.getFinalConfidenceIntervalMeansFisher(
design = design, dataInput = dataInput, stage = stage, thetaH0 = thetaH0,
directionUpper = directionUpper, normalApproximation = normalApproximation,
equalVariances = equalVariances, tolerance = tolerance
design = design,
dataInput = dataInput,
stage = stage,
thetaH0 = thetaH0,
directionUpper = directionUpper,
normalApproximation = normalApproximation,
equalVariances = equalVariances,
tolerance = tolerance
))
}

Expand Down
14 changes: 6 additions & 8 deletions R/f_analysis_base_rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8225 $
## | Last changed: $Date: 2024-09-18 09:38:40 +0200 (Mi, 18 Sep 2024) $
## | File version: $Revision: 8276 $
## | Last changed: $Date: 2024-09-26 13:37:54 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -600,7 +600,7 @@ NULL
combFisher[k] <- prod(pValues[1:k]^weightsFisher[1:k])
}

direction <- ifelse(directionUpper, C_DIRECTION_UPPER, C_DIRECTION_LOWER)
direction <- ifelse(!isFALSE(directionUpper), C_DIRECTION_UPPER, C_DIRECTION_LOWER)

stageResults <- StageResultsRates$new( # R6$new
design = design,
Expand All @@ -618,7 +618,7 @@ NULL
weightsInverseNormal = weightsInverseNormal,
weightsFisher = weightsFisher,
thetaH0 = thetaH0,
direction = ifelse(directionUpper, C_DIRECTION_UPPER, C_DIRECTION_LOWER),
direction = ifelse(!isFALSE(directionUpper), C_DIRECTION_UPPER, C_DIRECTION_LOWER),
normalApproximation = normalApproximation
)

Expand Down Expand Up @@ -1501,8 +1501,7 @@ NULL
stageResults$overallSampleSizes2[finalStage])
}

directionUpperSign <- ifelse(directionUpper, 1, -1)

directionUpperSign <- ifelse(!isFALSE(directionUpper), 1, -1)
if (stageGroupSeq == 1) {
finalConfidenceInterval[1] <- .getRootThetaRates(
design = design,
Expand Down Expand Up @@ -1701,8 +1700,7 @@ NULL
stageResults$overallSampleSizes2[finalStage])
}

directionUpperSign <- ifelse(directionUpper, 1, -1)

directionUpperSign <- ifelse(!isFALSE(directionUpper), 1, -1)
if (stageInverseNormal == 1) {
finalConfidenceInterval[1] <- .getRootThetaRates(
design = design,
Expand Down
11 changes: 5 additions & 6 deletions R/f_analysis_base_survival.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8225 $
## | Last changed: $Date: 2024-09-18 09:38:40 +0200 (Mi, 18 Sep 2024) $
## | File version: $Revision: 8276 $
## | Last changed: $Date: 2024-09-26 13:37:54 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -409,7 +409,7 @@ NULL
weightsFisher = weightsFisher,
weightsInverseNormal = weightsInverseNormal,
thetaH0 = thetaH0,
direction = ifelse(directionUpper, C_DIRECTION_UPPER, C_DIRECTION_LOWER)
direction = ifelse(!isFALSE(directionUpper), C_DIRECTION_UPPER, C_DIRECTION_LOWER)
)

if (.isTrialDesignFisher(design)) {
Expand Down Expand Up @@ -1241,8 +1241,7 @@ NULL
stderr <- (1 + y$overallAllocationRatios[finalStage]) / sqrt(y$overallAllocationRatios[finalStage]) /
sqrt(stageResults$overallEvents[finalStage])

directionUpperSign <- ifelse(directionUpper, 1, -1)

directionUpperSign <- ifelse(!isFALSE(directionUpper), 1, -1)
if (stageGroupSeq == 1) {
finalConfidenceInterval <- exp(stderr * finalConfidenceIntervalGeneral + log(thetaH0))
medianUnbiased <- exp(stderr * medianUnbiasedGeneral + log(thetaH0))
Expand Down Expand Up @@ -1371,7 +1370,7 @@ NULL
stderr <- (1 + y$overallAllocationRatios[finalStage]) / sqrt(y$overallAllocationRatios[finalStage]) /
sqrt(stageResults$overallEvents[finalStage])

directionUpperSign <- ifelse(directionUpper, 1, -1)
directionUpperSign <- ifelse(!isFALSE(directionUpper), 1, -1)
if (stageInvNormal == 1) {
finalConfidenceInterval <- exp(stderr * finalConfidenceIntervalGeneral + log(thetaH0))
medianUnbiased <- exp(stderr * medianUnbiasedGeneral + log(thetaH0))
Expand Down
9 changes: 5 additions & 4 deletions R/f_analysis_enrichment_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8225 $
## | Last changed: $Date: 2024-09-18 09:38:40 +0200 (Mi, 18 Sep 2024) $
## | File version: $Revision: 8276 $
## | Last changed: $Date: 2024-09-26 13:37:54 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -266,7 +266,7 @@ NULL
design = design,
dataInput = dataInput,
thetaH0 = thetaH0,
direction = ifelse(directionUpper, C_DIRECTION_UPPER, C_DIRECTION_LOWER),
direction = ifelse(!isFALSE(directionUpper), C_DIRECTION_UPPER, C_DIRECTION_LOWER),
normalApproximation = normalApproximation,
directionUpper = directionUpper,
stratifiedAnalysis = stratifiedAnalysis,
Expand Down Expand Up @@ -377,7 +377,8 @@ NULL

singleStepAdjustedPValues[population, k] <- 1 - .getMultivariateDistribution(
type = ifelse(normalApproximation, "normal", "t"),
upper = ifelse(directionUpper, testStatistics[population, k],
upper = ifelse(!isFALSE(directionUpper),
testStatistics[population, k],
-testStatistics[population, k]
),
sigma = sigma, df = df
Expand Down
10 changes: 6 additions & 4 deletions R/f_analysis_enrichment_rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: [email protected]
## |
## | File version: $Revision: 8225 $
## | Last changed: $Date: 2024-09-18 09:38:40 +0200 (Mi, 18 Sep 2024) $
## | File version: $Revision: 8276 $
## | Last changed: $Date: 2024-09-26 13:37:54 +0200 (Do, 26 Sep 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -239,7 +239,7 @@ NULL
design = design,
dataInput = dataInput,
thetaH0 = thetaH0,
direction = ifelse(directionUpper, C_DIRECTION_UPPER, C_DIRECTION_LOWER),
direction = ifelse(!isFALSE(directionUpper), C_DIRECTION_UPPER, C_DIRECTION_LOWER),
normalApproximation = normalApproximation,
directionUpper = directionUpper,
stratifiedAnalysis = stratifiedAnalysis,
Expand Down Expand Up @@ -332,7 +332,9 @@ NULL
}
singleStepAdjustedPValues[population, k] <- 1 - .getMultivariateDistribution(
type = "normal",
upper = ifelse(directionUpper, testStatistics[population, k], -testStatistics[population, k]),
upper = ifelse(!isFALSE(directionUpper),
testStatistics[population, k],
-testStatistics[population, k]),
sigma = sigma, df = NA
)
}
Expand Down
Loading

0 comments on commit 5e72e82

Please sign in to comment.