Skip to contents

sim_fixed_n() provides simulations of a single endpoint two-arm trial where the enrollment, hazard ratio, and failure and dropout rates change over time.

Usage

sim_fixed_n(
  n_sim = 1000,
  sample_size = 500,
  target_event = 350,
  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)),
  total_duration = 30,
  block = rep(c("experimental", "control"), 2),
  timing_type = 1:5,
  rho_gamma = data.frame(rho = 0, gamma = 0)
)

Arguments

n_sim

Number of simulations to perform.

sample_size

Total sample size per simulation.

target_event

Targeted event count for analysis.

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.

total_duration

Total follow-up from start of enrollment to data cutoff.

block

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

timing_type

A numeric vector determining data cutoffs used; see details. Default is to include all available cutoff methods.

rho_gamma

A data frame with variables rho and gamma, both greater than equal to zero, to specify one Fleming-Harrington weighted logrank test per row.

Value

A data frame including columns:

  • event: Event count.

  • ln_hr: Log-hazard ratio.

  • z: Normal test statistic; < 0 favors experimental.

  • cut: Text describing cutoff used.

  • duration: Duration of trial at cutoff for analysis.

  • sim: Sequential simulation ID.

One row per simulated dataset per cutoff specified in timing_type, per test statistic specified. If multiple Fleming-Harrington tests are specified in rho_gamma, then columns rho and gamma are also included.

Details

timing_type 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(dplyr)
library(future)
#> 
#> Attaching package: ‘future’
#> The following object is masked from ‘package:survival’:
#> 
#>     cluster

# Example 1: logrank test ----
x <- sim_fixed_n(n_sim = 10, timing_type = 1, rho_gamma = data.frame(rho = 0, gamma = 0))
#> Backend uses sequential processing.
#> Loading required package: foreach
# Get power approximation
mean(x$z <= qnorm(.025))
#> [1] 0.2

# Example 2: WLR with FH(0,1) ----
sim_fixed_n(n_sim = 1, timing_type = 1, rho_gamma = data.frame(rho = 0, gamma = 1))
#> Backend uses sequential processing.
#>   method          parameter  estimate      se         z event      ln_hr
#> 1    WLR FH(rho=0, gamma=1) -1.608741 1.14817 -1.401136    90 -0.2204257
#>                cut duration sim
#> 1 Planned duration       30   1
# Get power approximation
mean(x$z <= qnorm(.025))
#> [1] 0.2

# \donttest{
# Example 3: MaxCombo, i.e., WLR-FH(0,0)+ WLR-FH(0,1)
# Power by test
# Only use cuts for events, events + min follow-up
x <- sim_fixed_n(
  n_sim = 10,
  timing_type = 2,
  rho_gamma = data.frame(rho = 0, gamma = c(0, 1))
)
#> Backend uses sequential processing.

# Get power approximation
x |>
  group_by(sim) |>
  filter(row_number() == 1) |>
  ungroup() |>
  summarize(power = mean(p_value < .025))
#> # A tibble: 1 × 1
#>   power
#>   <dbl>
#> 1     1

# Example 4
# Use two cores
set.seed(2023)
plan("multisession", workers = 2)
sim_fixed_n(n_sim = 10)
#> Using 2 cores with backend multisession
#>           message                      call      
#> result.1  "object 'results' not found" expression
#> result.2  "object 'results' not found" expression
#> result.3  "object 'results' not found" expression
#> result.4  "object 'results' not found" expression
#> result.5  "object 'results' not found" expression
#> result.6  "object 'results' not found" expression
#> result.7  "object 'results' not found" expression
#> result.8  "object 'results' not found" expression
#> result.9  "object 'results' not found" expression
#> result.10 "object 'results' not found" expression
plan("sequential")
# }