sim_fixed_n {simtrial} | R Documentation |
Simulation of fixed sample size design for time-to-event endpoint
Description
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 |
enroll_rate |
Piecewise constant enrollment rates by time period.
Note that these are overall population enrollment rates and the |
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 |
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
|
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).
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.
Examples
library(dplyr)
library(future)
# Example 1: logrank test ----
x <- sim_fixed_n(n_sim = 10, timing_type = 1, rho_gamma = data.frame(rho = 0, gamma = 0))
# Get power approximation
mean(x$z <= qnorm(.025))
# Example 2: WLR with FH(0,1) ----
sim_fixed_n(n_sim = 1, timing_type = 1, rho_gamma = data.frame(rho = 0, gamma = 1))
# Get power approximation
mean(x$z <= qnorm(.025))
# 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))
)
# Get power approximation
x |>
group_by(sim) |>
filter(row_number() == 1) |>
ungroup() |>
summarize(power = mean(p_value < .025))
# Example 4
# Use two cores
set.seed(2023)
plan("multisession", workers = 2)
sim_fixed_n(n_sim = 10)
plan("sequential")