Designing Group Sequential Trials with a Binary Endpoint with rpact

Planning
Rates
This document provides examples for designing trials with binary endpoints using rpact.
Author
Published

February 16, 2024

Sample size calculation for a superiority trial with two groups without interim analyses

The sample size for a trial with binary endpoints can be calculated using the function getSampleSizeRates(). This function is fully documented in the help page (?getSampleSizeRates). Hence, we only provide some examples below.

First, load the rpact package.

library(rpact)
packageVersion("rpact") 
[1] '4.0.0'

To get the direction of the effects correctly, note that in rpact the index “2” in an argument name always refers to the control group, “1” to the intervention group, and treatment effects compare treatment versus control. Specifically, for binary endpoints, the probabilities of an event in the control group and intervention group, respectively, are given by arguments pi2 and pi1. The default treatment effect is the absolute risk difference pi1 - pi2 but the relative risk scale pi1/pi2 is also supported if the argument riskRatio is set to TRUE.

# Example of a standard trial:
# - probability 25% in control (pi2 = 0.25) vs. 40% (pi1 = 0.4) in intervention
# - one-sided test (sided = 1)
# - Type I error 0.025 (alpha = 0.025) and power 80% (beta = 0.2)
sampleSizeResult <- getSampleSizeRates(
    pi2 = 0.25, pi1 = 0.4,
    sided = 1, alpha = 0.025, beta = 0.2
)
kable(sampleSizeResult)
stages pi1 riskRatio thetaH0 normalApproximation pi2 groups allocationRatioPlanned directionUpper nFixed nFixed1 nFixed2 criticalValuesEffectScale
1 0.4 FALSE 0 TRUE 0.25 2 1 TRUE 303.7377 151.8689 151.8689 0.1032292

As per the output above, the required total sample size is 304 and the critical value corresponds to a minimal detectable difference (on the absolute risk difference scale, the default) of approximately 0.103. This calculation assumes that pi2 = 0.25 is the observed rate in treatment group 2.

A useful summary is provided with the generic summary() function:

kable(summary(sampleSizeResult))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA NA NA NA NA NA
1 0.4 FALSE 0 TRUE 0.25 2 1 TRUE 303.7377 151.8689 151.8689 0.1032292

You can change the randomization allocation between the treatment groups using allocationRatioPlanned:

# Example: Extension of standard trial
# - 2(intervention):1(control) randomization (allocationRatioPlanned = 2)
kable(summary(getSampleSizeRates(
    pi2 = 0.25, pi1 = 0.4,
    sided = 1, alpha = 0.025, beta = 0.2,
    allocationRatioPlanned = 2
)))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA NA NA NA NA NA
1 0.4 FALSE 0 TRUE 0.25 2 2 TRUE 346.3204 230.8803 115.4401 0.1041707

allocationRatioPlanned = 0 can be defined in order to obtain the optimum allocation ratio minimizing the overall sample size (the optimum ample size is only slightly smaller than sample size with equal allocation; practically, this has no effect):

# Example: Extension of standard trial
# optimum randomization ratio
kable(summary(getSampleSizeRates(
    pi2 = 0.25, pi1 = 0.4,
    sided = 1, alpha = 0.025, beta = 0.2,
    allocationRatioPlanned = 0
)))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA NA NA NA NA NA NA
1 0.4 FALSE 0 TRUE 0.25 2 0.9526172 TRUE TRUE 303.5628 148.0982 155.4645 0.1031639

Power at given sample size can be calculated using the function getPowerRates(). This function has the same arguments as getSampleSizeRates() except that the maximum total sample size needs to be defined (maxNumberOfSubjects) and the Type II error beta is no longer needed. For one-sided tests, the direction of the test is also required. The default directionUpper = TRUE indicates that for the alternative the probability in the intervention group pi1 is larger than the probability in the control group pi2 (directionUpper = FALSE is the other direction):

# Example: Calculate power for a simple trial with total sample size 304
# as in the example above in case of pi2 = 0.25 (control) and
# pi1 = 0.37 (intervention)
powerResult <- getPowerRates(
    pi2 = 0.25, pi1 = 0.37,
    maxNumberOfSubjects = 304, sided = 1, alpha = 0.025
)
kable(powerResult)
stages pi1 riskRatio thetaH0 normalApproximation pi2 groups allocationRatioPlanned directionUpper effect maxNumberOfSubjects overallReject nFixed nFixed1 nFixed2 criticalValuesEffectScale
1 0.37 FALSE 0 TRUE 0.25 2 1 TRUE 0.12 304 0.6196486 304 152 152 0.1031824

The calculated power is provided in the output as “Overall reject” and is 0.620 for the example.

The summary() command produces the output

kable(summary(powerResult))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
1 0.37 FALSE 0 TRUE 0.25 2 1 TRUE 0.12 304 0.6196486 304 152 152 0.1031824

The getPowerRates() (as well as getSampleSizeRates()) functions can also be called with a vector argument for the probability pi1 in the intervention group. This is illustrated below via a plot of power depending on this probability. For examples of all available plots, see the R Markdown document How to create admirable plots with rpact.

# Example: Calculate power for simple design (with sample size 304 as above)
# for probabilities in intervention ranging from 0.3 to 0.5
powerResult <- getPowerRates(
    pi2 = 0.25, pi1 = seq(0.3, 0.5, by = 0.01),
    maxNumberOfSubjects = 304, sided = 1, alpha = 0.025
)

# one of several possible plots, this one plotting true effect size vs power
plot(powerResult, type = 7)

Figure: example for an overall power plot

Sample size calculation for a non-inferiority trial with two groups without interim analyses

Sample size calculation proceeds in the same fashion as for superiority trials except that the role of the null and the alternative hypothesis are reversed. I.e., in this case, the non-inferiority margin \(\Delta\) corresponds to the treatment effect under the null hypothesis (thetaH0) which one aims to reject. Testing in non-inferiority trials is always one-sided.

# Example: Sample size for a non-inferiority trial
# Assume pi(control) = pi(intervention) = 0.2
# Test H0: pi1 - pi2 = 0.1 (risk increase in intervention >= Delta = 0.1)
# vs. H1: pi1 - pi2 < 0.1
sampleSizeNoninf <- getSampleSizeRates(
    pi2 = 0.2, pi1 = 0.2,
    thetaH0 = 0.1, sided = 1, alpha = 0.025, beta = 0.2
)
kable(sampleSizeNoninf)
stages pi1 riskRatio thetaH0 normalApproximation pi2 groups allocationRatioPlanned directionUpper nFixed nFixed1 nFixed2 criticalValuesEffectScale
1 0.2 FALSE 0.1 TRUE 0.2 2 1 FALSE 508.4354 254.2177 254.2177 0.0284932
kable(summary(sampleSizeNoninf))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA NA NA NA NA NA
1 0.2 FALSE 0.1 TRUE 0.2 2 1 FALSE 508.4354 254.2177 254.2177 0.0284932

Sample size calculation for a single arm trial without interim analyses

The function getSampleSizeRates() allows to set the number of groups (which is 2 by default) to 1 for the design of single arm trials. The probability under the null hypothesis can be specified with the argument thetaH0and the specific alternative hypothesis which is used for the sample size calculation with the argument pi1. The sample size calculation can be based either on a normal approximation (normalApproximation = TRUE, the default) or on exact binomial probabilities (normalApproximation = FALSE).

# Example: Sample size for a single arm trial which tests
# H0: pi = 0.1 vs. H1: pi = 0.25
# (use conservative exact binomial calculation)
samplesSizeResults <- getSampleSizeRates(
    groups = 1, thetaH0 = 0.1, pi1 = 0.25,
    normalApproximation = FALSE, sided = 1, alpha = 0.025, beta = 0.2
)

kable(summary(samplesSizeResults))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA
1 0.25 0.1 FALSE 1 TRUE 53 0.1807665

Sample size calculation for group sequential designs

Sample size calculation for a group sequential trial is performed in two steps:

  1. Define the (abstract) group sequential design using the function getDesignGroupSequential(). For details regarding this step, see the vignette Defining group sequential boundaries with rpact.
  2. Calculate sample size for the binary endpoint by feeding the abstract design into the function getSampleSizeRates(). Note that the power 1 - beta needs to be defined in the design function, and not in getSampleSizeRates().

In general, rpact supports both one-sided and two-sided group sequential designs. However, if futility boundaries are specified, only one-sided tests are permitted.

R code for a simple example is provided below:

# Example: Group-sequential design with  O'Brien & Fleming type alpha-spending and
# one interim at 60% information
design <- getDesignGroupSequential(
    sided = 1, alpha = 0.025, beta = 0.2,
    informationRates = c(0.6, 1), typeOfDesign = "asOF"
)

# Sample size calculation assuming event probabilities are 25% in control
# (pi2 = 0.25) vs 40% (pi1 = 0.4) in intervention
sampleSizeResultGS <- getSampleSizeRates(design, pi2 = 0.25, pi1 = 0.4)
# Standard rpact output (sample size object only, not design object)
kable(sampleSizeResultGS)
stages pi1 riskRatio thetaH0 normalApproximation pi2 groups allocationRatioPlanned directionUpper maxNumberOfSubjects maxNumberOfSubjects1 maxNumberOfSubjects2 numberOfSubjects rejectPerStage earlyStop expectedNumberOfSubjectsH0 expectedNumberOfSubjectsH01 expectedNumberOfSubjectsH1 criticalValuesEffectScale
1 0.4 FALSE 0 TRUE 0.25 2 1 TRUE 306.3311 153.1656 153.1656 183.7987 0.3123193 0.3123193 305.8645 299.3256 268.0619 0.1869477
2 0.4 FALSE 0 TRUE 0.25 2 1 TRUE 306.3311 153.1656 153.1656 306.3311 0.4876807 0.3123193 305.8645 299.3256 268.0619 0.1039268

The summary() command produces the output

kable(summary(sampleSizeResultGS))
Warning in is.na(parameterValues): is.na() auf Nicht-(Liste oder Vektor) des
Typs 'environment' angewendet
object NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
1 0.4 FALSE 0 TRUE 0.25 2 1 TRUE 306.3311 153.1656 153.1656 183.7987 0.3123193 0.3123193 305.8645 299.3256 268.0619 0.1869477
2 0.4 FALSE 0 TRUE 0.25 2 1 TRUE 306.3311 153.1656 153.1656 306.3311 0.4876807 0.3123193 305.8645 299.3256 268.0619 0.1039268

System: rpact 4.0.0, R version 4.3.3 (2024-02-29 ucrt), platform: x86_64-w64-mingw32

To cite R in publications use:

R Core Team (2024). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/. To cite package ‘rpact’ in publications use:

Wassmer G, Pahlke F (2024). rpact: Confirmatory Adaptive Clinical Trial Design and Analysis. R package version 4.0.0, https://www.rpact.com, https://github.com/rpact-com/rpact, https://rpact-com.github.io/rpact/, https://www.rpact.org.