Conversion of enrollment and failure rates from sim_fixed_n() to sim_pw_surv() format
Source:R/simfix2simPWSurv.R
simfix2simPWSurv.Rd
simfix2simPWSurv()
converts failure rates and dropout rates entered in the simpler
format for sim_fixed_n()
to that used for simtrial::sim_pw_surv()
.
The fail_rate
argument for sim_fixed_n()
requires enrollment rates, failure rates
hazard ratios and dropout rates by stratum for a 2-arm trial, simtrial::sim_pw_surv()
is in a more flexible but less obvious but more flexible format.
Since sim_fixed_n()
automatically analyzes data and simtrial::sim_pw_surv()
just produces
a simulation dataset, the latter provides additional options to analyze or otherwise evaluate
individual simulations in ways that sim_fixed_n()
does not.
Arguments
- fail_rate
Piecewise constant control group failure rates, hazard ratio for experimental vs control, and dropout rates by stratum and time period.
Value
A list
of two tibble
components formatted for simtrial::sim_pw_surv()
:
fail_rate
and dropout_rate
.
Examples
library(tidyr)
library(dplyr)
library(tibble)
# example 1
# Convert standard input
simfix2simPWSurv()
#> $fail_rate
#> # A tibble: 4 × 5
#> stratum period treatment duration rate
#> <chr> <int> <chr> <dbl> <dbl>
#> 1 All 1 control 3 0.0770
#> 2 All 2 control 100 0.0385
#> 3 All 1 experimental 3 0.0693
#> 4 All 2 experimental 100 0.0231
#>
#> $dropout_rate
#> # A tibble: 4 × 5
#> stratum period treatment duration rate
#> <chr> <int> <chr> <dbl> <dbl>
#> 1 All 1 control 3 0.001
#> 2 All 2 control 100 0.001
#> 3 All 1 experimental 3 0.001
#> 4 All 2 experimental 100 0.001
#>
# Stratified example
fail_rate <- tibble(stratum = c(rep("Low", 3),rep("High", 3)),
duration = rep(c(4, 10, 100), 2),
fail_rate = c(.04, .1, .06,
.08,.16,.12),
hr = c(1.5, .5, 2/3,
2, 10/16, 10/12),
dropout_rate =.01)
x <- simfix2simPWSurv(fail_rate)
# Do a single simulation with the above rates
# Enroll 300 patients in ~12 months at constant rate
sim <- sim_pw_surv(n = 300,
stratum = tibble(stratum = c("Low","High"), p = c(.6, .4)),
enroll_rate = tibble(duration = 12, rate = 300 / 12),
fail_rate = x$fail_rate,
dropout_rate = x$dropout_rate)
# Cut after 200 events and do a stratified logrank test
dat <- sim %>%
cut_data_by_event(200) %>% # cut data
counting_process(arm = "experimental") %>% # convert format for tenFH
wlr(rho_gamma = tibble(rho=0,gamma=0)) # stratified logrank