getSimulationMeans {rpact}  R Documentation 
Returns the simulated power, stopping probabilities, conditional power, and expected sample size for testing means in a one or two treatment groups testing situation.
getSimulationMeans(
design = NULL,
...,
groups = 2L,
normalApproximation = TRUE,
meanRatio = FALSE,
thetaH0 = ifelse(meanRatio, 1, 0),
alternative = seq(0, 1, 0.2),
stDev = 1,
plannedSubjects = NA_real_,
directionUpper = TRUE,
allocationRatioPlanned = NA_real_,
minNumberOfSubjectsPerStage = NA_real_,
maxNumberOfSubjectsPerStage = NA_real_,
conditionalPower = NA_real_,
thetaH1 = NA_real_,
stDevH1 = NA_real_,
maxNumberOfIterations = 1000L,
seed = NA_real_,
calcSubjectsFunction = NULL,
showStatistics = FALSE
)
design 
The trial design. If no trial design is specified, a fixed sample size design is used.
In this case, Type I error rate 
... 
Ensures that all arguments (starting from the "...") are to be named and that a warning will be displayed if unknown arguments are passed. 
groups 
The number of treatment groups (1 or 2), default is 
normalApproximation 
The type of computation of the pvalues. Default is 
meanRatio 
If 
thetaH0 
The null hypothesis value,
default is
For testing a rate in one sample, a value 
alternative 
The alternative hypothesis value for testing means under which the data is simulated.
This can be a vector of assumed alternatives, default is 
stDev 
The standard deviation under which the data is simulated,
default is 
plannedSubjects 

directionUpper 
Logical. Specifies the direction of the alternative,
only applicable for onesided testing; default is 
allocationRatioPlanned 
The planned allocation ratio 
minNumberOfSubjectsPerStage 
When performing a data driven sample size recalculation,
the numeric vector 
maxNumberOfSubjectsPerStage 
When performing a data driven sample size recalculation,
the numeric vector 
conditionalPower 
If 
thetaH1 
If specified, the value of the alternative under which the conditional power or sample size recalculation calculation is performed. Must be a numeric of length 1. 
stDevH1 
If specified, the value of the standard deviation under which
the conditional power or sample size recalculation calculation is performed,
default is the value of 
maxNumberOfIterations 
The number of simulation iterations, default is 
seed 
The seed to reproduce the simulation, default is a random seed. 
calcSubjectsFunction 
Optionally, a function can be entered that defines the way of performing the sample size
recalculation. By default, sample size recalculation is performed with conditional power and specified

showStatistics 
Logical. If 
At given design the function simulates the power, stopping probabilities, conditional power, and expected sample size at given number of subjects and parameter configuration. Additionally, an allocation ratio = n1/n2 can be specified where n1 and n2 are the number of subjects in the two treatment groups.
The definition of thetaH1
makes only sense if kMax
> 1
and if conditionalPower
, minNumberOfSubjectsPerStage
, and
maxNumberOfSubjectsPerStage
(or calcSubjectsFunction
) are defined.
calcSubjectsFunction
This function returns the number of subjects at given conditional power and conditional critical value for specified
testing situation. The function might depend on variables
stage
,
meanRatio
,
thetaH0
,
groups
,
plannedSubjects
,
sampleSizesPerStage
,
directionUpper
,
allocationRatioPlanned
,
minNumberOfSubjectsPerStage
,
maxNumberOfSubjectsPerStage
,
conditionalPower
,
conditionalCriticalValue
,
thetaH1
, and
stDevH1
.
The function has to contain the threedots argument '...' (see examples).
Returns a SimulationResults
object.
The following generics (R generic functions) are available for this object:
names()
to obtain the field names,
print()
to print the object,
summary()
to display a summary of the object,
plot()
to plot the object,
as.data.frame()
to coerce the object to a data.frame
,
as.matrix()
to coerce the object to a matrix
.
The summary statistics "Simulated data" contains the following parameters: median range; mean +/sd
$show(showStatistics = FALSE)
or $setShowStatistics(FALSE)
can be used to disable
the output of the aggregated simulated data.
Example 1:
simulationResults < getSimulationMeans(plannedSubjects = 40)
simulationResults$show(showStatistics = FALSE)
Example 2:
simulationResults < getSimulationMeans(plannedSubjects = 40)
simulationResults$setShowStatistics(FALSE)
simulationResults
getData()
can be used to get the aggregated simulated data from the
object as data.frame
. The data frame contains the following columns:
iterationNumber
: The number of the simulation iteration.
stageNumber
: The stage.
alternative
: The alternative hypothesis value.
numberOfSubjects
: The number of subjects under consideration when the
(interim) analysis takes place.
rejectPerStage
: 1 if null hypothesis can be rejected, 0 otherwise.
futilityPerStage
: 1 if study should be stopped for futility, 0 otherwise.
testStatistic
: The test statistic that is used for the test decision,
depends on which design was chosen (group sequential, inverse normal, or Fisher's combination test).
testStatisticsPerStage
: The test statistic for each stage if only data from
the considered stage is taken into account.
effectEstimate
: Overall simulated standardized effect estimate.
trialStop
: TRUE
if study should be stopped for efficacy or futility or final stage, FALSE
otherwise.
conditionalPowerAchieved
: The conditional power for the subsequent stage of the trial for
selected sample size and effect. The effect is either estimated from the data or can be
user defined with thetaH1
.
Click on the link of a generic in the list above to go directly to the help documentation of
the rpact
specific implementation of the generic.
Note that you can use the R function methods
to get all the methods of a generic and
to identify the object specific name of it, e.g.,
use methods("plot")
to get all the methods for the plot
generic.
There you can find, e.g., plot.AnalysisResults
and
obtain the specific help documentation linked above by typing ?plot.AnalysisResults
.
# 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)
## Not run:
# 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 threestage O'Brien&Fleming inverse
# normal group sequential design with nonbinding 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(1e12, 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
)
## End(Not run)