Find the critical value of two-stage log-rank test
find_m_logrank.RdThis function performs a grid search to find the critical values m1, m2) for the log-rank test in a two-stage design.
It makes use of probability Prob(W1 / sigma1 > m1 & W2 / sigma2 > m2 | H0) = alpha and
the normality of Z-statistics (Kwak and Jung(2017))
W / sigma are estimated by simulation. The z-statistics can be obtained using the log_rank_sim function
and accessed via its $z_stats output.
When power is not given, the function finds the critical values (m1, m2) that control the overall type I error
while maximizing the power. When power is given, it searches for valid critical values such that the empirical
power is greater than the specified power. If power is given, int_n and fin_n are required
for the expected sample size calculation.
Usage
find_m_logrank(
logrank_data,
corr_h0,
search_times,
int_n = NULL,
fin_n = NULL,
alpha,
sim_size,
power = NULL
)Arguments
- logrank_data
A matrix of log-rank test z statistics for each simulation.
- corr_h0
A numeric value representing the correlation of two stages, calculated as
sqrt(var(W1) / var(W)).- search_times
An integer specifying the number of grid search iterations.
- int_n
An optional integer specifying the interim sample size (required if
poweris given).- fin_n
An optional integer specifying the total sample size in both arms (required if
poweris given).- alpha
A numeric value specifying the significance level for hypothesis testing.
- sim_size
An integer specifying the number of simulations to perform, say 10000.
- power
An optional numeric value specifying the desired power for the test.
Value
A data frame with the following columns:
- m1
Critical value for the first stage test.
- m2
Critical value for the second stage test.
- PET0
Probability of early termination under H0.
- PET1
Probability of early termination under H1.
- alpha
Empirical overall type I error rate.
- power
Empirical power of the test.
- PET
Probability of early termination.
- EN0
Expected sample size under H0.
- EN1
Expected sample size under H1.
- EN
Overall expected sample size.
If no valid critical values are found, the function returns a data frame with:
m1 = 0, m2 = 0, PET0 = 0, PET1 = 0, alpha = 0, power = 0, PET = 0, EN0 = NA, EN1 = NA, EN = NA.
Examples
sim_size <- 5000
N <- 100
r <- 60
acc_time <- N / r
cen_time <- 1
lambda_H1 <- 0.9
HR <- 1.7
lambda_H0 <- 0.9 * 1.7
change_time <- 1
interim <- 0.6 * acc_time
n <- ceiling(N / 2)
alpha <- 0.05
tau_f <- 2.5
data_C <- expo_gen_2stages(N = n * sim_size, acc_time = acc_time,
lambda = lambda_H0, dist = 'exp',
cen_time = cen_time,arm = 0, interim = interim)
data_E_H0 <- expo_gen_2stages(N = n * sim_size, acc_time = acc_time,
lambda = lambda_H0, dist = 'exp',
cen_time = cen_time,arm = 1, interim = interim)
data_E_H1 <- expo_gen_2stages(N = n * sim_size, acc_time = acc_time,
lambda = lambda_H1, dist = 'exp',
cen_time = cen_time,arm = 1, interim = interim)
lr_h0_int <- log_rank_sim(data_C = data_C[ , c(2,3,1)], data_E = data_E_H0[ , c(2,3,1)],
sim_size = sim_size, n = n, alpha = alpha, sided = 'greater')
#> Error in makeCluster(n_cores): could not find function "makeCluster"
lr_h1_int <- log_rank_sim(data_C = data_C[ , c(2,3,1)], data_E = data_E_H1[ , c(2,3,1)],
sim_size = sim_size, n = n, alpha = alpha, sided = 'greater')
#> Error in makeCluster(n_cores): could not find function "makeCluster"
lr_h0_fin <- log_rank_sim(data_C = data_C[ , c(4,5,1)], data_E = data_E_H0[ , c(4,5,1)],
sim_size = sim_size, n = n, alpha = alpha, sided = 'greater')
#> Error in makeCluster(n_cores): could not find function "makeCluster"
lr_h1_fin <- log_rank_sim(data_C = data_C[ , c(4,5,1)], data_E = data_E_H1[ , c(4,5,1)],
sim_size = sim_size, n = n, alpha = alpha, sided = 'greater')
#> Error in makeCluster(n_cores): could not find function "makeCluster"
# Get W/sigma
z_stats_h1_int <- lr_h1_int$z_stats
#> Error: object 'lr_h1_int' not found
z_stats_h1_fin <- lr_h1_fin$z_stats
#> Error: object 'lr_h1_fin' not found
z_stats_h0_int <- lr_h0_int$z_stats
#> Error: object 'lr_h0_int' not found
z_stats_h0_fin <- lr_h0_fin$z_stats
#> Error: object 'lr_h0_fin' not found
logrank_data <- rbind(z_stats_h0_int, z_stats_h1_int, z_stats_h0_fin, z_stats_h1_fin)
#> Error: object 'z_stats_h0_int' not found
corr_h0 <- sqrt(mean(lr_h0_int$var_w) / mean(lr_h0_fin$var_w))
#> Error: object 'lr_h0_int' not found
best_lr <- find_m_logrank(logrank_data = logrank_data, search_times = 200, corr_h0 = corr_h0,
alpha = 0.05, sim_size = sim_size)
#> Error: object 'logrank_data' not found