test_that("survival_adapt-bayes", { out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "less", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "bayes") expect_s3_class(out, "data.frame") }) test_that("survival_adapt-logrank", { out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") expect_s3_class(out, "data.frame") }) test_that("survival_adapt-cox", { out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "cox") expect_s3_class(out, "data.frame") }) test_that("survival_adapt-complex", { skip_on_cran() hc <- prop_to_haz(c(0.20, 0.25, 0.30), c(0, 3, 6), 24) ht <- prop_to_haz(c(0.075, 0.125, 0.175), c(0, 3, 6), 24) set.seed(12345) out <- survival_adapt( hazard_treatment = ht, hazard_control = hc, cutpoints = c(0, 3, 6), N_total = 500, lambda = c(6, 8), lambda_time = c(0, 6), interim_look = c(200, 350), end_of_study = 24, prior = c(0.1, 0.1), block = 3, rand_ratio = c(2, 1), prop_loss = 0, alternative = "less", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.95, N_impute = 20, N_mcmc = 20, method = "bayes", imputed_final = TRUE) expect_s3_class(out, "data.frame") }) test_that("error-interim-looks", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = c(200, 300, 400, 500), end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) }) test_that("error-alternative", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two-sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) }) test_that("error-cutpoint", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 37, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) }) test_that("error-alternative-bayes", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "bayes") ) }) test_that("error-alternative-logrank", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "less", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) }) test_that("error-logrank-single_arm", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = NULL, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = 200, end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = 0.9, prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) }) test_that("error-prob-thresholds-length_v1", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = c(100, 200), end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = 0.05, Sn = c(0.99, 0.9), prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) }) test_that("error-prob-thresholds-length_v2", { expect_error( out <- survival_adapt( hazard_treatment = -log(0.85) / 36, hazard_control = -log(0.7) / 36, cutpoints = 0, N_total = 400, lambda = 20, lambda_time = 0, interim_look = c(100, 200), end_of_study = 36, prior = c(0.1, 0.1), block = 2, rand_ratio = c(1, 1), prop_loss = 0.30, alternative = "two.sided", h0 = 0, Fn = c(0.05, 0.05, 0.05), Sn = c(0.99, 0.99, 0.99), prob_ha = 0.975, N_impute = 2, N_mcmc = 2, method = "logrank") ) })