Skip to contents

WARNING: This experimental function is a work-in-progress. The function arguments will change as we add additional features.

Usage

sim_gs_n(
  n_sim = 1000,
  sample_size = 500,
  stratum = data.frame(stratum = "All", p = 1),
  enroll_rate = data.frame(duration = c(2, 2, 10), rate = c(3, 6, 9)),
  fail_rate = data.frame(stratum = "All", duration = c(3, 100), fail_rate = log(2)/c(9,
    18), hr = c(0.9, 0.6), dropout_rate = rep(0.001, 2)),
  block = rep(c("experimental", "control"), 2),
  test = wlr,
  cut = NULL,
  seed = 2024,
  ...
)

Arguments

n_sim

Number of simulations to perform.

sample_size

Total sample size per simulation.

stratum

A data frame with stratum specified in stratum, probability (incidence) of each stratum in p.

enroll_rate

Piecewise constant enrollment rates by time period. Note that these are overall population enrollment rates and the stratum argument controls the random distribution between stratum.

fail_rate

Piecewise constant control group failure rates, hazard ratio for experimental vs. control, and dropout rates by stratum and time period.

block

As in sim_pw_surv(). Vector of treatments to be included in each block.

test

One or more test functions such as wlr(), rmst(), or milestone() (maxcombo() can only be applied by itself). If a single test function is provided, it will be applied at each cut. Alternatively a list of functions created by create_test(). The list form is experimental and currently limited. It only accepts one test per cutting (in the future multiple tests may be accepted), and all the tests must consistently return the same exact results (again this may be more flexible in the future). Importantly, note that the simulated data set is always passed as the first positional argument to each test function provided.

cut

A list of cutting functions created by create_cut(), see examples.

seed

Random seed.

...

Arguments passed to the test function(s) provided by the argument test.

Value

A data frame summarizing the simulation ID, analysis date, z statistics or p-values.

Examples

library(gsDesign2)

# Parameters for enrollment
enroll_rampup_duration <- 4 # Duration for enrollment ramp up
enroll_duration <- 16 # Total enrollment duration
enroll_rate <- define_enroll_rate(
  duration = c(
    enroll_rampup_duration,
    enroll_duration - enroll_rampup_duration
  ),
  rate = c(10, 30)
)

# Parameters for treatment effect
delay_effect_duration <- 3 # Delay treatment effect in months
median_ctrl <- 9 # Survival median of the control arm
median_exp <- c(9, 14) # Survival median of the experimental arm
dropout_rate <- 0.001
fail_rate <- define_fail_rate(
  duration = c(delay_effect_duration, 100),
  fail_rate = log(2) / median_ctrl,
  hr = median_ctrl / median_exp,
  dropout_rate = dropout_rate
)

# Other related parameters
alpha <- 0.025 # Type I error
beta <- 0.1 # Type II error
ratio <- 1 # Randomization ratio (experimental:control)

# Define cuttings of 2 IAs and 1 FA
# IA1
# The 1st interim analysis will occur at the later of the following 3 conditions:
# - At least 20 months have passed since the start of the study.
# - At least 100 events have occurred.
# - At least 20 months have elapsed after enrolling 200/400 subjects, with a
#   minimum of 20 months follow-up.
# However, if events accumulation is slow, we will wait for a maximum of 24 months.
ia1_cut <- create_cut(
  planned_calendar_time = 20,
  target_event_overall = 100,
  max_extension_for_target_event = 24,
  min_n_overall = 200,
  min_followup = 20
)

# IA2
# The 2nd interim analysis will occur at the later of the following 3 conditions:
# - At least 32 months have passed since the start of the study.
# - At least 250 events have occurred.
# - At least 10 months after IA1.
# However, if events accumulation is slow, we will wait for a maximum of 34 months.
ia2_cut <- create_cut(
  planned_calendar_time = 32,
  target_event_overall = 200,
  max_extension_for_target_event = 34,
  min_time_after_previous_analysis = 10
)

# FA
# The final analysis will occur at the later of the following 2 conditions:
# - At least 45 months have passed since the start of the study.
# - At least 300 events have occurred.
fa_cut <- create_cut(
  planned_calendar_time = 45,
  target_event_overall = 350
)

# Example 1: regular logrank test at all 3 analyses
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = wlr,
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024,
  weight = fh(rho = 0, gamma = 0)
)
#>   sim_id method          parameter analysis cut_date   n event  estimate
#> 1      1    WLR FH(rho=0, gamma=0)        1 24.00000 400   229 -28.19483
#> 2      1    WLR FH(rho=0, gamma=0)        2 32.00000 400   295 -38.32581
#> 3      1    WLR FH(rho=0, gamma=0)        3 45.00000 400   355 -39.49230
#> 4      2    WLR FH(rho=0, gamma=0)        1 24.00000 400   241 -26.84871
#> 5      2    WLR FH(rho=0, gamma=0)        2 32.00000 400   290 -32.54824
#> 6      2    WLR FH(rho=0, gamma=0)        3 46.21933 400   350 -30.06631
#> 7      3    WLR FH(rho=0, gamma=0)        1 24.00000 400   226 -23.06302
#> 8      3    WLR FH(rho=0, gamma=0)        2 32.00000 400   282 -30.16330
#> 9      3    WLR FH(rho=0, gamma=0)        3 50.86585 400   350 -38.75506
#>         se         z
#> 1 7.521418 -3.748605
#> 2 8.459808 -4.530340
#> 3 9.149248 -4.316453
#> 4 7.721484 -3.477144
#> 5 8.425310 -3.863150
#> 6 9.172772 -3.277778
#> 7 7.498065 -3.075863
#> 8 8.333910 -3.619345
#> 9 9.178027 -4.222592

# Example 2: weighted logrank test by FH(0, 0.5) at all 3 analyses
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = wlr,
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024,
  weight = fh(rho = 0, gamma = 0.5)
)
#>   sim_id method            parameter analysis cut_date   n event  estimate
#> 1      1    WLR FH(rho=0, gamma=0.5)        1 24.00000 400   229 -16.93422
#> 2      1    WLR FH(rho=0, gamma=0.5)        2 32.00000 400   295 -24.44818
#> 3      1    WLR FH(rho=0, gamma=0.5)        3 45.00000 400   355 -25.51076
#> 4      2    WLR FH(rho=0, gamma=0.5)        1 24.00000 400   241 -15.50024
#> 5      2    WLR FH(rho=0, gamma=0.5)        2 32.00000 400   290 -19.96769
#> 6      2    WLR FH(rho=0, gamma=0.5)        3 46.21933 400   350 -17.53906
#> 7      3    WLR FH(rho=0, gamma=0.5)        1 24.00000 400   226 -12.66462
#> 8      3    WLR FH(rho=0, gamma=0.5)        2 32.00000 400   282 -18.05051
#> 9      3    WLR FH(rho=0, gamma=0.5)        3 50.86585 400   350 -25.59217
#>         se         z
#> 1 4.081359 -4.149161
#> 2 5.116707 -4.778108
#> 3 5.987416 -4.260730
#> 4 4.299539 -3.605093
#> 5 5.061414 -3.945081
#> 6 6.008214 -2.919180
#> 7 4.029178 -3.143228
#> 8 4.958307 -3.640459
#> 9 6.031211 -4.243289

# Example 3: weighted logrank test by MB(3) at all 3 analyses
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = wlr,
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024,
  weight = mb(delay = 3)
)
#>   sim_id method                       parameter analysis cut_date   n event
#> 1      1    WLR MB(delay = 3, max_weight = Inf)        1 24.00000 400   229
#> 2      1    WLR MB(delay = 3, max_weight = Inf)        2 32.00000 400   295
#> 3      1    WLR MB(delay = 3, max_weight = Inf)        3 45.00000 400   355
#> 4      2    WLR MB(delay = 3, max_weight = Inf)        1 24.00000 400   241
#> 5      2    WLR MB(delay = 3, max_weight = Inf)        2 32.00000 400   290
#> 6      2    WLR MB(delay = 3, max_weight = Inf)        3 46.21933 400   350
#> 7      3    WLR MB(delay = 3, max_weight = Inf)        1 24.00000 400   226
#> 8      3    WLR MB(delay = 3, max_weight = Inf)        2 32.00000 400   282
#> 9      3    WLR MB(delay = 3, max_weight = Inf)        3 50.86585 400   350
#>    estimate        se         z
#> 1 -34.19243  9.004801 -3.797134
#> 2 -46.74548 10.203472 -4.581331
#> 3 -48.19085 11.079263 -4.349644
#> 4 -32.19277  9.194961 -3.501131
#> 5 -39.18612 10.082515 -3.886542
#> 6 -36.14078 11.020928 -3.279286
#> 7 -27.89564  8.957908 -3.114079
#> 8 -36.66946 10.022498 -3.658715
#> 9 -47.28631 11.091534 -4.263279

# Example 4: weighted logrank test by early zero (6) at all 3 analyses
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = wlr,
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024,
  weight = early_zero(6)
)
#>   sim_id method                                parameter analysis cut_date   n
#> 1      1    WLR Xu 2017 with first 6 months of 0 weights        1 24.00000 400
#> 2      1    WLR Xu 2017 with first 6 months of 0 weights        2 32.00000 400
#> 3      1    WLR Xu 2017 with first 6 months of 0 weights        3 45.00000 400
#> 4      2    WLR Xu 2017 with first 6 months of 0 weights        1 24.00000 400
#> 5      2    WLR Xu 2017 with first 6 months of 0 weights        2 32.00000 400
#> 6      2    WLR Xu 2017 with first 6 months of 0 weights        3 46.21933 400
#> 7      3    WLR Xu 2017 with first 6 months of 0 weights        1 24.00000 400
#> 8      3    WLR Xu 2017 with first 6 months of 0 weights        2 32.00000 400
#> 9      3    WLR Xu 2017 with first 6 months of 0 weights        3 50.86585 400
#>   event  estimate       se         z
#> 1   229 -21.99899 4.832164 -4.552617
#> 2   295 -32.12997 6.192449 -5.188573
#> 3   355 -33.29646 7.105407 -4.686074
#> 4   241 -17.19941 5.399223 -3.185533
#> 5   290 -22.89893 6.365230 -3.597503
#> 6   350 -20.41701 7.325985 -2.786930
#> 7   226 -11.77606 4.974376 -2.367344
#> 8   282 -18.87634 6.162588 -3.063054
#> 9   350 -27.46810 7.263581 -3.781619

# Example 5: RMST at all 3 analyses
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = rmst,
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024,
  tau = 20
)
#>   sim_id method parameter analysis cut_date   n event estimate        se
#> 1      1   RMST        20        1 24.00000 400   229 2.881152 0.7602020
#> 2      1   RMST        20        2 32.00000 400   295 2.853131 0.7147367
#> 3      1   RMST        20        3 45.00000 400   355 2.834508 0.7121699
#> 4      2   RMST        20        1 24.00000 400   241 2.567390 0.7388451
#> 5      2   RMST        20        2 32.00000 400   290 2.399692 0.7282783
#> 6      2   RMST        20        3 46.21933 400   350 2.368335 0.7277970
#> 7      3   RMST        20        1 24.00000 400   226 2.287498 0.7674791
#> 8      3   RMST        20        2 32.00000 400   282 2.448117 0.7416398
#> 9      3   RMST        20        3 50.86585 400   350 2.478942 0.7398877
#>          z
#> 1 3.789982
#> 2 3.991863
#> 3 3.980101
#> 4 3.474869
#> 5 3.295021
#> 6 3.254115
#> 7 2.980534
#> 8 3.300952
#> 9 3.350430

# Example 6: Milestone at all 3 analyses
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = milestone,
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024,
  ms_time = 10
)
#>   sim_id    method parameter analysis cut_date   n event   estimate         se
#> 1      1 milestone        10        1 24.00000 400   229 -0.4635636 -0.2151203
#> 2      1 milestone        10        2 32.00000 400   295 -0.5093608 -0.2066913
#> 3      1 milestone        10        3 45.00000 400   355 -0.5093608 -0.2066913
#> 4      2 milestone        10        1 24.00000 400   241 -0.3605499 -0.2158065
#> 5      2 milestone        10        2 32.00000 400   290 -0.3487338 -0.2107879
#> 6      2 milestone        10        3 46.21933 400   350 -0.3487338 -0.2107879
#> 7      3 milestone        10        1 24.00000 400   226 -0.4643428 -0.2176120
#> 8      3 milestone        10        2 32.00000 400   282 -0.4593313 -0.2152211
#> 9      3 milestone        10        3 50.86585 400   350 -0.4593313 -0.2152211
#>          z
#> 1 2.154904
#> 2 2.464355
#> 3 2.464355
#> 4 1.670709
#> 5 1.654430
#> 6 1.654430
#> 7 2.133810
#> 8 2.134230
#> 9 2.134230

# Example 7: WLR with fh(0, 0.5) test at IA1,
# WLR with mb(6, Inf) at IA2, and milestone test at FA
ia1_test <- create_test(wlr, weight = fh(rho = 0, gamma = 0.5))
ia2_test <- create_test(wlr, weight = mb(delay = 6, w_max = Inf))
fa_test <- create_test(milestone, ms_time = 10)
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = list(ia1 = ia1_test, ia2 = ia2_test, fa = fa_test),
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024
)
#>   sim_id    method                       parameter analysis cut_date   n event
#> 1      1       WLR            FH(rho=0, gamma=0.5)        1 24.00000 400   229
#> 2      1       WLR MB(delay = 6, max_weight = Inf)        2 32.00000 400   295
#> 3      1 milestone                              10        3 45.00000 400   355
#> 4      2       WLR            FH(rho=0, gamma=0.5)        1 24.00000 400   241
#> 5      2       WLR MB(delay = 6, max_weight = Inf)        2 32.00000 400   290
#> 6      2 milestone                              10        3 46.21933 400   350
#> 7      3       WLR            FH(rho=0, gamma=0.5)        1 24.00000 400   226
#> 8      3       WLR MB(delay = 6, max_weight = Inf)        2 32.00000 400   282
#> 9      3 milestone                              10        3 50.86585 400   350
#>      estimate         se         z
#> 1 -16.9342172  4.0813592 -4.149161
#> 2 -55.1339503 11.6364487 -4.738039
#> 3  -0.5093608 -0.2066913  2.464355
#> 4 -15.5002394  4.2995395 -3.605093
#> 5 -44.4370518 11.2729305 -3.941925
#> 6  -0.3487338 -0.2107879  1.654430
#> 7 -12.6646240  4.0291779 -3.143228
#> 8 -41.6624938 11.2572150 -3.700959
#> 9  -0.4593313 -0.2152211  2.134230

# WARNING: Multiple tests per cut will be enabled in a future version.
#          Currently does not work.
# Example 8: At IA1, we conduct 3 tests, LR, WLR with fh(0, 0.5), and RMST test.
# At IA2, we conduct 2 tests, LR and WLR with early zero (6).
# At FA, we conduct 2 tests, LR and milestone test.
ia1_test <- list(
  test1 = create_test(wlr, weight = fh(rho = 0, gamma = 0)),
  test2 = create_test(wlr, weight = fh(rho = 0, gamma = 0.5)),
  test3 = create_test(rmst, tau = 20)
)
ia2_test <- list(
  test1 = create_test(wlr, weight = fh(rho = 0, gamma = 0)),
  test2 = create_test(wlr, weight = early_zero(6))
)
fa_test <- list(
  test1 = create_test(wlr, weight = fh(rho = 0, gamma = 0)),
  test3 = create_test(milestone, ms_time = 20)
)
if (FALSE) {
sim_gs_n(
  n_sim = 3,
  sample_size = 400,
  enroll_rate = enroll_rate,
  fail_rate = fail_rate,
  test = list(ia1 = ia1_test, ia2 = ia2_test, fa = fa_test),
  cut = list(ia1 = ia1_cut, ia2 = ia2_cut, fa = fa_cut),
  seed = 2024
)
}