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))
# \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))
)
# 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")
# Example 5: Stratified design with two strata
sim_fixed_n(
n_sim = 100,
sample_size = 500,
target_event = 350,
stratum = data.frame(stratum = c("Biomarker-positive", "Biomarker-negative"),
p = c(0.5, 0.5)),
enroll_rate = data.frame(stratum = c("Biomarker positive", "Biomarker negative"),
duration = c(12, 12), rate = c(250 / 12, 250 / 12)),
fail_rate = data.frame(stratum = c(rep("Biomarker-positive", 2), rep("Biomarker-negative", 2)),
duration = c(3, Inf, 3, Inf),
fail_rate = log(2) / c(12, 12, 8, 8),
hr = c(1, 0.6, 1, 0.7),
dropout_rate = rep(0.001, 4)),
total_duration = 30,
block = rep(c("experimental", "control"), 2),
timing_type = 1:5,
rho_gamma = data.frame(rho = 0, gamma = 0)
)
# }
Run the code above in your browser using DataLab