This R Markdown document provides examples for designing trials with continuous endpoints using rpact.
These examples are not intended to replace the official rpact documentation and help pages but rather to supplement them. They also only cover a selection of all rpact features.
General convention: In rpact, arguments containing the index “2” always refer to the control group, “1” refer to the intervention group, and treatment effects compare treatment versus control.
First, load the rpact package
library(rpact)
packageVersion("rpact") # version should be version 3.0 or later
## [1] '3.3.1'
The sample size for a trial with continuous
endpoints can be calculated using the function
getSampleSizeMeans()
. This function is fully documented in
the relevant help page (?getSampleSizeMeans
). Some examples
are provided below.
getSampleSizeMeans()
requires that the mean difference
between the two arms is larger under the alternative than under the null
hypothesis. For superiority trials, this implies that rpact
requires that the targeted mean difference is >0 under the
alternative hypothesis. If this is not the case, the function
produces an error message. To circumvent this and power for a negative
mean difference, one can simply switch the two arms
(leading to a positive mean difference) as the situation is perfectly
symmetric.
By default, getSampleSizeMeans()
tests hypotheses about
the mean difference. rpact also supports
testing hypotheses about mean ratios if the argument
meanRatio
is set to TRUE
but this will not be
discussed further in this document.
By default, rpact uses sample
size formulas for the \(t\)-test, i.e.,
it assumes that the standard deviation in the two groups is equal but
unknown and estimated from the data. If sample size calculations for the
\(z\)-test are desired, one can set the
argument normalApproximation
to TRUE
but this
is usually not recommended.
# Example of a standard trial:
# - targeted mean difference is 10 (alternative = 10)
# - standard deviation in both arms is assumed to be 24 (stDev = 24)
# - two-sided test (sided = 2), Type I error 0.05 (alpha = 0.05) and power 80%
# - (beta = 0.2)
<- getSampleSizeMeans(
sampleSizeResult alternative = 10, stDev = 24, sided = 2,
alpha = 0.05, beta = 0.2
)kable(sampleSizeResult)
Design plan parameters and output for means
Design parameters
User defined parameters
Default parameters
Sample size and output
Legend
The generic summary()
function produces the output
kable(summary(sampleSizeResult))
Sample size calculation for a continuous endpoint
Fixed sample analysis, significance level 5% (two-sided). The sample size was calculated for a two-sample t-test, H0: mu(1) - mu(2) = 0, H1: effect = 10, standard deviation = 24, power 80%.
Stage | Fixed |
---|---|
Efficacy boundary (z-value scale) | 1.960 |
Number of subjects | 182.8 |
Two-sided local significance level | 0.0500 |
Lower efficacy boundary (t) | -7.006 |
Upper efficacy boundary (t) | 7.006 |
Legend:
As per the output above, the required total sample size for the trial is 183 and the critical value corresponds to a minimal detectable mean difference of approximately 7.01.
Unequal randomization between the treatment groups can be defind with
allocationRatioPlanned
, for example,
# Extension of standard trial:
# - 2(intervention):1(control) randomization (allocationRatioPlanned = 2)
kable(summary(getSampleSizeMeans(
alternative = 10, stDev = 24,
allocationRatioPlanned = 2, sided = 2, alpha = 0.05, beta = 0.2
)))
Sample size calculation for a continuous endpoint
Fixed sample analysis, significance level 5% (two-sided). The sample size was calculated for a two-sample t-test, H0: mu(1) - mu(2) = 0, H1: effect = 10, standard deviation = 24, planned allocation ratio = 2, power 80%.
Stage | Fixed |
---|---|
Efficacy boundary (z-value scale) | 1.960 |
Number of subjects | 205.4 |
Two-sided local significance level | 0.0500 |
Lower efficacy boundary (t) | -7.004 |
Upper efficacy boundary (t) | 7.004 |
Legend:
Power for a given sample size can be calculated
using the function getPowerMeans()
which has the same
arguments as getSampleSizeMeans()
except that the maximum
total sample is given (maxNumberOfSubjects
) instead of the
Type II error (beta
).
# Calculate power for the 2:1 rendomized trial with total sample size 206
# (as above) assuming a larger difference of 12
<- getPowerMeans(
powerResult alternative = 12, stDev = 24, sided = 2,
allocationRatioPlanned = 2, maxNumberOfSubjects = 206, alpha = 0.05
)kable(powerResult)
Design plan parameters and output for means
Design parameters
User defined parameters
Default parameters
Sample size and output
Legend
The calculated power is provided in the output as
“Overall reject” and is 0.92 for the example
alternative = 12
.
The summary()
function produces
kable(summary(powerResult))
Power calculation for a continuous endpoint
Fixed sample analysis, significance level 5% (two-sided). The results were calculated for a two-sample t-test, H0: mu(1) - mu(2) = 0, H1: effect = 12, standard deviation = 24, number of subjects = 206, planned allocation ratio = 2.
Stage | Fixed |
---|---|
Efficacy boundary (z-value scale) | 1.960 |
Power | 0.9203 |
Number of subjects | 206.0 |
Two-sided local significance level | 0.0500 |
Lower efficacy boundary (t) | -6.994 |
Upper efficacy boundary (t) | 6.994 |
Legend:
getPowerMeans()
(as well as
getSampleSizeMeans()
) can also be called with a vector
argument for the mean difference under the alternative H1
(alternative
). This is illustrated below via a plot of
power depending on these values. For examples of all available plots,
see the R Markdown document How to
create admirable plots with rpact.
# Example: Calculate power for design with sample size 206 as above
# alternative values ranging from 5 to 15
<- getPowerMeans(
powerResult alternative = 5:15, stDev = 24, sided = 2,
allocationRatioPlanned = 2, maxNumberOfSubjects = 206, alpha = 0.05
)plot(powerResult, type = 7) # one of several possible plots