simfix() provide simulations of a single endpoint two-arm trial
where the enrollment, hazard ratio, and failure and dropout rates change over time.
Usage
simfix(
nsim = 1000,
sampleSize = 500,
target_event = 350,
strata = tibble(Stratum = "All", p = 1),
enroll_rate = tibble(duration = c(2, 2, 10), rate = c(3, 6, 9)),
failRates = tibble(Stratum = "All", duration = c(3, 100), failRate = log(2)/c(9, 18),
hr = c(0.9, 0.6), dropoutRate = rep(0.001, 2)),
totalDuration = 30,
block = rep(c("Experimental", "Control"), 2),
timingType = 1:5,
rg = tibble(rho = 0, gamma = 0),
seed = NULL
)Arguments
- nsim
Number of simulations to perform.
- sampleSize
Total sample size per simulation.
- target_event
Targeted event count for analysis.
- strata
A tibble with strata specified in
Stratum, probability (incidence) of each stratum inp.- enroll_rate
Piecewise constant enrollment rates by time period. Note that these are overall population enrollment rates and the
strataargument controls the random distribution between strata.- failRates
Piecewise constant control group failure rates, hazard ratio for experimental vs control, and dropout rates by stratum and time period.
- totalDuration
Total follow-up from start of enrollment to data cutoff.
- block
As in
simtrial::sim_pw_surv(). Vector of treatments to be included in each block.- timingType
A numeric vector determining data cutoffs used; see details. Default is to include all available cutoff methods.
- rg
As in
simtrial::tenFHCorr(). Atibblewith variablesrhoandgamma, both greater than equal to zero, to specify one Fleming-Harrington weighted logrank test per row.- seed
Optional. Initial seed for simulations
Value
A tibble including columns Events (event count), lnhr (log-hazard ratio),
Z (normal test statistic; < 0 favors experimental) cut (text describing cutoff used),
Duration (duration of trial at cutoff for analysis) and sim (sequential simulation id).
One row per simulated dataset per cutoff specified in timingType, per test statistic specified.
If multiple Fleming-Harrington tests are specified in rg, then columns rho,gamma
are also included.
Details
timingType has up to 5 elements indicating different options for data cutoff.
1 uses the planned study duration, 2 the time the targeted event count is achieved,
3 the planned minimum follow-up after enrollment is complete,
4 the maximum of planned study duration and targeted event count cuts (1 and 2),
5 the maximum of targeted event count and minimum follow-up cuts (2 and 3).
Examples
library(tidyr)
library(dplyr)
library(doParallel)
#> Loading required package: foreach
#> Loading required package: iterators
#> Loading required package: parallel
library(tibble)
# example 1
# Show output structure
simfix(nsim = 3)
#> Events lnhr Z cut Duration Sim
#> 1 101 -0.35596354 -1.7807528 Planned duration 30.00000 1
#> 2 350 -0.58842899 -5.4347050 Targeted events 70.66627 1
#> 3 345 -0.59304284 -5.4369767 Minimum follow-up 69.99847 1
#> 4 350 -0.58842899 -5.4347050 Max(planned duration, event cut) 70.66627 1
#> 5 350 -0.58842899 -5.4347050 Max(min follow-up, event cut) 70.66627 1
#> 6 99 -0.57115488 -2.7933633 Planned duration 30.00000 2
#> 7 350 -0.54403037 -5.0405514 Targeted events 70.40724 2
#> 8 358 -0.56738099 -5.3181052 Minimum follow-up 73.09564 2
#> 9 350 -0.54403037 -5.0405514 Max(planned duration, event cut) 70.40724 2
#> 10 358 -0.56738099 -5.3181052 Max(min follow-up, event cut) 73.09564 2
#> 11 100 -0.05129625 -0.2550474 Planned duration 30.00000 3
#> 12 350 -0.22755298 -2.1235342 Targeted events 68.31636 3
#> 13 375 -0.26792061 -2.5879234 Minimum follow-up 75.28638 3
#> 14 350 -0.22755298 -2.1235342 Max(planned duration, event cut) 68.31636 3
#> 15 375 -0.26792061 -2.5879234 Max(min follow-up, event cut) 75.28638 3
# example 2
# Example with 2 tests: logrank and FH(0,1)
simfix(nsim = 1,rg = tibble(rho = 0, gamma = c(0, 1)))
#> Events lnhr rho gamma Z V1 V2
#> 1 79 -0.4531215 0 0 -1.998291 1.0000000 0.8273014
#> 2 79 -0.4531215 0 1 -2.319715 0.8273014 1.0000000
#> 3 350 -0.4268443 0 0 -3.965361 1.0000000 0.8504254
#> 4 350 -0.4268443 0 1 -3.694219 0.8504254 1.0000000
#> 5 357 -0.4368910 0 0 -4.104925 1.0000000 0.8522037
#> 6 357 -0.4368910 0 1 -3.921844 0.8522037 1.0000000
#> 7 350 -0.4268443 0 0 -3.965361 1.0000000 0.8504254
#> 8 350 -0.4268443 0 1 -3.694219 0.8504254 1.0000000
#> 9 357 -0.4368910 0 0 -4.104925 1.0000000 0.8522037
#> 10 357 -0.4368910 0 1 -3.921844 0.8522037 1.0000000
#> cut Duration Sim
#> 1 Planned duration 30.00000 1
#> 2 Planned duration 30.00000 1
#> 3 Targeted events 71.51114 1
#> 4 Targeted events 71.51114 1
#> 5 Minimum follow-up 73.51266 1
#> 6 Minimum follow-up 73.51266 1
#> 7 Max(planned duration, event cut) 71.51114 1
#> 8 Max(planned duration, event cut) 71.51114 1
#> 9 Max(min follow-up, event cut) 73.51266 1
#> 10 Max(min follow-up, event cut) 73.51266 1
# example 3
# Power by test
# Only use cuts for events, events + min follow-up
xx <- simfix(nsim = 100,
timingType = c(2, 5),
rg = tibble(rho = 0, gamma = c(0, 1)))
# Get power approximation for FH, data cutoff combination
xx %>%
group_by(cut, rho, gamma) %>%
summarise(mean(Z <= qnorm(.025)))
#> `summarise()` has grouped output by 'cut', 'rho'. You can override using the
#> `.groups` argument.
#> # A tibble: 4 × 4
#> # Groups: cut, rho [2]
#> cut rho gamma `mean(Z <= qnorm(0.025))`
#> <chr> <dbl> <dbl> <dbl>
#> 1 Max(min follow-up, event cut) 0 0 0.94
#> 2 Max(min follow-up, event cut) 0 1 0.98
#> 3 Targeted events 0 0 0.94
#> 4 Targeted events 0 1 0.97
# MaxCombo power estimate for cutoff at max of targeted events, minimum follow-up
p <- xx %>%
filter(cut != "Targeted events") %>%
group_by(Sim) %>%
group_map(pvalue_maxcombo) %>%
unlist()
mean(p < .025)
#> [1] 0.98
# MaxCombo estimate for targeted events cutoff
p <- xx %>%
filter(cut == "Targeted events") %>%
group_by(Sim) %>%
group_map(pvalue_maxcombo) %>%
unlist()
mean(p < .025)
#> [1] 0.95
# example 3
# Use two cores
registerDoParallel(2)
simfix(nsim = 10, seed = 2022)
#> Using 2 cores with backend doParallelMC
#> Events lnhr Z cut Duration Sim
#> 1 109 -0.39889743 -2.06986755 Planned duration 30.00000 1
#> 2 350 -0.49422311 -4.60390065 Targeted events 68.10765 1
#> 3 361 -0.46996411 -4.44698855 Minimum follow-up 70.94601 1
#> 4 350 -0.49422311 -4.60390065 Max(planned duration, event cut) 68.10765 1
#> 5 361 -0.46996411 -4.44698855 Max(min follow-up, event cut) 70.94601 1
#> 6 92 0.13030304 0.62455481 Planned duration 30.00000 2
#> 7 350 -0.06380056 -0.59576098 Targeted events 71.15880 2
#> 8 369 -0.12986489 -1.24394980 Minimum follow-up 74.20194 2
#> 9 350 -0.06380056 -0.59576098 Max(planned duration, event cut) 71.15880 2
#> 10 369 -0.12986489 -1.24394980 Max(min follow-up, event cut) 74.20194 2
#> 11 109 -0.35042569 -1.81806443 Planned duration 30.00000 3
#> 12 350 -0.30340153 -2.82469678 Targeted events 69.68286 3
#> 13 353 -0.30661159 -2.86687105 Minimum follow-up 71.40394 3
#> 14 350 -0.30340153 -2.82469678 Max(planned duration, event cut) 69.68286 3
#> 15 353 -0.30661159 -2.86687105 Max(min follow-up, event cut) 71.40394 3
#> 16 107 -0.32400212 -1.66943391 Planned duration 30.00000 4
#> 17 350 -0.38322625 -3.56929885 Targeted events 70.15615 4
#> 18 361 -0.40035000 -3.78355568 Minimum follow-up 73.04033 4
#> 19 350 -0.38322625 -3.56929885 Max(planned duration, event cut) 70.15615 4
#> 20 361 -0.40035000 -3.78355568 Max(min follow-up, event cut) 73.04033 4
#> 21 99 -0.13790150 -0.68382782 Planned duration 30.00000 5
#> 22 350 -0.43925467 -4.08974448 Targeted events 71.52825 5
#> 23 369 -0.44486563 -4.25463983 Minimum follow-up 76.21111 5
#> 24 350 -0.43925467 -4.08974448 Max(planned duration, event cut) 71.52825 5
#> 25 369 -0.44486563 -4.25463983 Max(min follow-up, event cut) 76.21111 5
#> 26 105 -0.18871020 -0.96580373 Planned duration 30.00000 6
#> 27 350 -0.32895353 -3.07323368 Targeted events 68.56574 6
#> 28 358 -0.33990896 -3.21127927 Minimum follow-up 69.61403 6
#> 29 350 -0.32895353 -3.07323368 Max(planned duration, event cut) 68.56574 6
#> 30 358 -0.33990896 -3.21127927 Max(min follow-up, event cut) 69.61403 6
#> 31 91 -0.32023796 -1.51269632 Planned duration 30.00000 7
#> 32 350 -0.30003853 -2.79088836 Targeted events 74.43009 7
#> 33 348 -0.30041840 -2.78367764 Minimum follow-up 73.88934 7
#> 34 350 -0.30003853 -2.79088836 Max(planned duration, event cut) 74.43009 7
#> 35 350 -0.30003853 -2.79088836 Max(min follow-up, event cut) 74.43009 7
#> 36 108 -0.06740129 -0.34998515 Planned duration 30.00000 8
#> 37 350 -0.34760754 -3.23571976 Targeted events 70.79181 8
#> 38 360 -0.36258193 -3.42179494 Minimum follow-up 73.10338 8
#> 39 350 -0.34760754 -3.23571976 Max(planned duration, event cut) 70.79181 8
#> 40 360 -0.36258193 -3.42179494 Max(min follow-up, event cut) 73.10338 8
#> 41 101 -0.51016154 -2.54286277 Planned duration 30.00000 9
#> 42 350 -0.37603601 -3.50384516 Targeted events 68.74117 9
#> 43 364 -0.37361232 -3.55001459 Minimum follow-up 74.54110 9
#> 44 350 -0.37603601 -3.50384516 Max(planned duration, event cut) 68.74117 9
#> 45 364 -0.37361232 -3.55001459 Max(min follow-up, event cut) 74.54110 9
#> 46 79 0.01209188 0.05336003 Planned duration 30.00000 10
#> 47 350 -0.18922477 -1.76159151 Targeted events 73.00188 10
#> 48 361 -0.19779690 -1.86989858 Minimum follow-up 76.39085 10
#> 49 350 -0.18922477 -1.76159151 Max(planned duration, event cut) 73.00188 10
#> 50 361 -0.19779690 -1.86989858 Max(min follow-up, event cut) 76.39085 10
stopImplicitCluster()
registerDoSEQ()