11 Scenario X: Chi-Squared Distribution
11.1 Details
In this scenario, we consider the case where the test statistic is Chi-squared distributed. It is useful when we conduct a test with more than two treatment arms or when we test two-sided with a normally distributed test statistic. In the first case, we assume binary endpoints, so we have a \(2 \times k\) contingency table. In the second case, we conduct a two-sided Z-test. As the normal distribution is symmetric around \(0\), this test is equivalent to a one-sided test with test statistic \(Z^2\).
11.2 Variant X-1: Contingeny table with binary endpoints
11.2.1 Setup
Under the alternative, we assume a response rate of \(0.4\) in the first group, \(0.5\) in the second and \(0.6\) in the third group.
<- c(0.4, 0.5, 0.6)
rate_vec <- get_tau_Pearson2xK(rate_vec)
theta <- Pearson2xK(3)
datadist <- PointMassPrior(.0, 1)
H_0 <- PointMassPrior(theta, 1)
prior
<- 0.025
alpha <- 0.9
min_power <- Power(datadist, H_0) <= alpha
toer_cnstr <- Power(datadist,prior) >= min_power pow_cnstr
11.2.2 Objective
The expected sample size under the alternative shall be minimized.
<- ExpectedSampleSize(datadist, prior) ess
11.2.3 Initial design
The initial designs for the minimization process is chosen using the in-built function.
<- tibble(
tbl_designs type = c("one-stage", "group-sequential", "two-stage"),
initial = list(
get_initial_design(theta, alpha, 1- min_power,
dist = datadist, type_design = "one-stage"),
get_initial_design(theta, alpha, 1- min_power,
dist = datadist, type_design = "group-sequential"),
get_initial_design(theta, alpha, 1- min_power,
dist = datadist, type_design = "two-stage")))
11.2.4 Optimization
<- tbl_designs %>%
tbl_designs mutate(
optimal = purrr::map(initial, ~minimize(
ess,subject_to(
toer_cnstr,
pow_cnstr
),
initial_design = .,
opts = opts)) )
11.2.5 Test Cases
We first verify that the number of iterations was not exceeded in any of the three cases.
%>%
tbl_designs transmute(
type, iterations = purrr::map_int(tbl_designs$optimal,
~.$nloptr_return$iterations) ) %>%
print(.); .} %>%
{::expect_true(all(.$iterations < opts$maxeval))} {testthat
## # A tibble: 3 × 2
## type iterations
## <chr> <int>
## 1 one-stage 24
## 2 group-sequential 6727
## 3 two-stage 5422
We then check via simulation that the type I error and power constraints are fulfilled.
%>%
tbl_designs transmute(
type, toer = purrr::map(tbl_designs$optimal,
~sim_pr_reject(.[[1]], .0, datadist)$prob),
power = purrr::map(tbl_designs$optimal,
~sim_pr_reject(.[[1]], theta , datadist)$prob) ) %>%
unnest(., cols = c(toer, power)) %>%
print(.); .} %>% {
{::expect_true(all(.$toer <= alpha * (1 + tol)))
testthat::expect_true(all(.$power >= min_power * (1 - tol))) } testthat
## # A tibble: 3 × 3
## type toer power
## <chr> <dbl> <dbl>
## 1 one-stage 0.0251 0.900
## 2 group-sequential 0.0249 0.900
## 3 two-stage 0.0249 0.899
We expect the sample size function \(n_2\) to be monotonously decreasing.
::expect_true(
testthatall(diff(
# get optimal two-stage design n2 pivots
%>% filter(type == "two-stage") %>%
tbl_designs "optimal"]][[1]]$design@n2_pivots}
{.[[< 0) ) )
Since the degrees of freedom of the three design classes are ordered as
‘two-stage’ > ‘group-sequential’ > ‘one-stage’,
the expected sample sizes (under the alternative) should be ordered
in reverse (‘two-stage’ smallest).
Additionally, expected sample sizes under both null and alternative
are computed both via evaluate()
and simulation-based.
<- ExpectedSampleSize(datadist, H_0)
ess0
%>%
tbl_designs mutate(
ess = map_dbl(optimal,
~evaluate(ess, .$design) ),
ess_sim = map_dbl(optimal,
~sim_n(.$design, theta, datadist)$n ),
ess0 = map_dbl(optimal,
~evaluate(ess0, .$design) ),
ess0_sim = map_dbl(optimal,
~sim_n(.$design, .0, datadist)$n ) ) %>%
print(.); .} %>% {
{# sim/evaluate same under alternative?
::expect_equal(.$ess, .$ess_sim,
testthattolerance = tol_n,
scale = 1)
# sim/evaluate same under null?
::expect_equal(.$ess0, .$ess0_sim,
testthattolerance = tol_n,
scale = 1)
# monotonicity with respect to degrees of freedom
::expect_true(all(diff(.$ess) < 0)) } testthat
## # A tibble: 3 × 7
## type initial optimal ess ess_sim ess0 ess0_sim
## <chr> <list> <list> <dbl> <dbl> <dbl> <dbl>
## 1 one-stage <OnStgDsg> <adptrOpR [3]> 184 184 184 184
## 2 group-sequential <GrpSqntD> <adptrOpR [3]> 157. 157. 154. 154.
## 3 two-stage <TwStgDsg> <adptrOpR [3]> 155. 155. 162. 162.
The expected sample size under the alternative of the optimized designs should be lower than the sample size of the initial designs.
::expect_lte(
testthatevaluate(ess,
%>%
tbl_designs pull(optimal) %>%
1]] %>%
.[[$design ),
.evaluate(ess,
%>%
tbl_designs pull(initial) %>%
1]] ) ) .[[
11.3 Variant X-2: Two-sided Z-test
In the second variant, we want to conduct a two-sided test with normally distributed outcome. Unfortunately, a two-sided test in the setting of two-stage trials is more difficult to implement, as the decision whether to stop early or to continue cannot be expressed in the same way as usual (\(Z < c_f\) for futility, \(Z > c_e\) for efficacy, \(Z \in [c_f, c_e]\) for continuation). In the two-sided test scenario, we would need to consider \(|Z|\), so \(|Z| < c_f\) for futility, \(|Z| > c_e\) for efficacy, \(|Z| \in [c_f, c_e]\) for continuation. Unfortunately, this would lead to \(4\) necessary boundaries, which would not fit the adoptr-framework. If \(Z \sim \mathcal{N}(0,1)\) under the null, we can use the fact \(Z^2 \sim \chi^2\) and transform our two-sided test problem to a one-sided test. Hence, we stop early for futility if \(Z^2 < c_f\), for efficacy if \(Z^2 > c_e\) and we continue if \(Z^2 \in [c_f, c_e]\), where \(c_f\) and \(c_e\) are calculated by adoptr using a \(\chi^2\)-distribution.
11.3.1 Setup
Under the alternative, we assume an effect size of \(0.4\). We want to get a Type I error \(\alpha \leq 0.05\) and our power should be higher than \(0.8\)
<- get_tau_ZSquared(0.4)
theta <- ZSquared(two_armed = TRUE)
datadist <- PointMassPrior(.0, 1)
H_0 <- PointMassPrior(theta, 1)
prior
<- 0.05
alpha <- 0.8
min_power <- Power(datadist, H_0) <= alpha
toer_cnstr <- Power(datadist,prior) >= min_power pow_cnstr
11.3.2 Objective
We minimize the expected sample size under the alternative.
<- ExpectedSampleSize(datadist, prior) ess
11.3.3 Initial designs
The initial designs for the minimization process is chosen using the in-built function.
<- tibble(
tbl_designs type = c("one-stage", "group-sequential", "two-stage"),
initial = list(
get_initial_design(theta, alpha, 1- min_power,
dist = datadist, type_design = "one-stage"),
get_initial_design(theta, alpha, 1- min_power,
dist = datadist, type_design = "group-sequential"),
get_initial_design(theta, alpha, 1- min_power,
dist = datadist, type_design = "two-stage")))
11.3.4 Optimization
<- tbl_designs %>%
tbl_designs mutate(
optimal = purrr::map(initial, ~minimize(
ess,subject_to(
toer_cnstr,
pow_cnstr
),
initial_design = .,
opts = opts)) )
11.3.5 Test
We check that in none of the three cases the number of iterations was exceeded.
%>%
tbl_designs transmute(
type, iterations = purrr::map_int(tbl_designs$optimal,
~.$nloptr_return$iterations) ) %>%
print(.); .} %>%
{::expect_true(all(.$iterations < opts$maxeval))} {testthat
## # A tibble: 3 × 2
## type iterations
## <chr> <int>
## 1 one-stage 24
## 2 group-sequential 2563
## 3 two-stage 2383
We now verify the type I error and power constraints. To get better insights, we do not simulate the test statistic, but normally distributed outcomes and then square the test statistic.
<- 10^6
N <- function(design, theta, dist){
simulation <- 0
count for(i in 1:N){
<- n1(design)
n1 <- rnorm(n1, mean = theta)
treatment <- rnorm(n1)
control
<- (sqrt(n1 / 2) * (mean(treatment) - mean(control)))^2
Z_square
if(Z_square > design@c1e){
<- count + 1
count
}
if(Z_square >= design@c1f & Z_square <= design@c1e){
<- n2(design, Z_square)
n2 <- rnorm(n2, mean = theta)
treatment2 <- rnorm(n2)
control2
<- (sqrt(n2 / 2) * (mean(treatment2) - mean(control2)))^2
Z_final if(Z_final > c2(design, Z_square)){
<- count + 1
count
}
}
}return(list(
prob = count / N))
}
%>%
tbl_designs transmute(
type, toer = purrr::map(tbl_designs$optimal,
~simulation(.[[1]], .0, datadist)$prob),
power = purrr::map(tbl_designs$optimal,
~simulation(.[[1]], .4, datadist)$prob) ) %>%
unnest(., cols = c(toer, power)) %>%
print(.); .} %>% {
{::expect_true(all(.$toer <= alpha * (1 + tol)))
testthat::expect_true(all(.$power >= min_power * (1 - tol))) } testthat
## # A tibble: 3 × 3
## type toer power
## <chr> <dbl> <dbl>
## 1 one-stage 0.0499 0.799
## 2 group-sequential 0.0501 0.798
## 3 two-stage 0.0499 0.798
The \(n_2\) function should be monotonously decreasing.
::expect_true(
testthatall(diff(
# get optimal two-stage design n2 pivots
%>% filter(type == "two-stage") %>%
tbl_designs "optimal"]][[1]]$design@n2_pivots}
{.[[< 0) ) )
Since the degrees of freedom of the three design classes are ordered as
‘two-stage’ > ‘group-sequential’ > ‘one-stage’,
the expected sample sizes (under the alternative) should be ordered
in reverse (‘two-stage’ smallest).
Additionally, expected sample sizes under both null and alternative
are computed both via evaluate()
and simulation-based.
<- ExpectedSampleSize(datadist, H_0)
ess0
%>%
tbl_designs mutate(
ess = map_dbl(optimal,
~evaluate(ess, .$design) ),
ess_sim = map_dbl(optimal,
~sim_n(.$design, theta, datadist)$n ),
ess0 = map_dbl(optimal,
~evaluate(ess0, .$design) ),
ess0_sim = map_dbl(optimal,
~sim_n(.$design, .0, datadist)$n ) ) %>%
print(.); .} %>% {
{# sim/evaluate same under alternative?
::expect_equal(.$ess, .$ess_sim,
testthattolerance = tol_n,
scale = 1)
# sim/evaluate same under null?
::expect_equal(.$ess0, .$ess0_sim,
testthattolerance = tol_n,
scale = 1)
# monotonicity with respect to degrees of freedom
::expect_true(all(diff(.$ess) < 0)) } testthat
## # A tibble: 3 × 7
## type initial optimal ess ess_sim ess0 ess0_sim
## <chr> <list> <list> <dbl> <dbl> <dbl> <dbl>
## 1 one-stage <OnStgDsg> <adptrOpR [3]> 98 98 98 98
## 2 group-sequential <GrpSqntD> <adptrOpR [3]> 87.2 87.2 82.0 82.0
## 3 two-stage <TwStgDsg> <adptrOpR [3]> 87.1 87.1 83.2 83.2
The optimized design should have a lower expected sample size than the initial designs.
::expect_lte(
testthatevaluate(ess,
%>%
tbl_designs pull(optimal) %>%
1]] %>%
.[[$design ),
.evaluate(ess,
%>%
tbl_designs pull(initial) %>%
1]] ) ) .[[