print("# ------------------------------------ #") print("# Code for Simple Trial Example #") print("# ------------------------------------ #") library("BayesCTDesign") library("ggplot2") set.seed(2250) SampleHistData <- genweibulldata(sample_size = 60, scale1 = 2.82487, hazard_ratio = 1.0, common_shape = 3, censor_value = 3) histdata <- subset(SampleHistData, subset = (treatment == 0)) histdata$id <- histdata$id + 10000 weibull_test <- historic_sim(trial_reps = 100, outcome_type = "weibull", subj_per_arm = c(40, 70, 100), a0_vals = c(1), effect_vals = c(0.6), rand_control_diff = c(1), hist_control_data = histdata, censor_value = 3, alpha = 0.05, get_var = TRUE, get_bias = TRUE, get_mse = TRUE, seedval = 123) print(weibull_test) print("# ------------------------------------ #") print("# Code for Complex Trial Example 1 #") print("# ------------------------------------ #") library("BayesCTDesign") set.seed(2250) SampleHistData <- genweibulldata(sample_size = 60, scale1 = 2.82487, hazard_ratio = 1.0, common_shape = 3, censor_value = 3) histdata <- subset(SampleHistData, subset = (treatment == 0)) histdata$id <- histdata$id + 10000 weibull_test <- historic_sim(trial_reps = 500, outcome_type = "weibull", subj_per_arm = c(75, 100, 125, 150, 175), a0_vals = c(0, 0.25, 0.5, 0.75, 1), effect_vals = c(0.6, 0.7, 0.8, 0.9, 1), rand_control_diff = c(0.8, 1, 1.2), hist_control_data = histdata, censor_value = 3, alpha = 0.05, get_var = TRUE, get_bias = TRUE, get_mse = TRUE, seedval = 123) test_table0_6 <- print(weibull_test, measure = "power", tab_type = "WX|YZ", effect_val = 0.6, rand_control_diff_val = 1.0) test_table0_6 test_table0_7 <- print(weibull_test, measure = "power", tab_type = "WX|YZ", effect_val = 0.7, rand_control_diff_val = 1.0) test_table0_7 test_table1_0 <- print(weibull_test, measure = "power", tab_type = "WX|YZ", effect_val = 1.0, rand_control_diff_val = 1.0) test_table1_0 test_table0_7_1_2 <- print(weibull_test, measure = "power", tab_type = "WX|YZ", effect_val = 0.7, rand_control_diff_val = 1.2) test_table0_7_1_2 test_table0_7_1_2e <- print(weibull_test, measure = "est", tab_type = "WX|YZ", effect_val = 0.7, rand_control_diff_val = 1.2) test_table0_7_1_2e test_table0_7_1_2v <- print(weibull_test, measure = "var", tab_type = "WX|YZ", effect_val = 0.7, rand_control_diff_val = 1.2) test_table0_7_1_2v test_table0_7_0_8 <- print(weibull_test, measure = "power", tab_type = "WX|YZ", effect_val = 0.7, rand_control_diff_val = 0.8) test_table0_7_0_8 test_table0_7_0_8e <- print(weibull_test, measure = "est", tab_type = "WX|YZ", effect_val = 0.7, rand_control_diff_val = 0.8) test_table0_7_0_8e test_table150_0_7 <- print(weibull_test, measure = "power", tab_type = "ZX|WY", subj_per_arm_val = 150, effect_val = 0.7) test_table150_0_7 test_table175_0_7 <- print(weibull_test, measure = "power", tab_type = "ZX|WY", subj_per_arm_val = 175, effect_val = 0.7) test_table175_0_7 test_table175_1_0 <- print(weibull_test, measure = "power", tab_type = "ZX|WY", subj_per_arm_val = 175, effect_val = 1.0) test_table175_1_0 pdf("Figure9.pdf") plot(weibull_test, measure = "power", tab_type = "WX|YZ", smooth = FALSE, plot_out = TRUE, effect_val = 0.7, rand_control_diff_val = 1.2) dev.off() print("# ------------------------------------ #") print("# Code for Complex Trial Example 2 #") print("# ------------------------------------ #") library("BayesCTDesign") set.seed(2250) time.vec <- c(0.3, 0.9, 1.5, 2.1, 2.4) lambdaHC.vec <- c(0.19, 0.35, 0.56, 0.47, 0.38, 0.34) pwe_test <- simple_sim(trial_reps = 500, outcome_type = "pwe", subj_per_arm = c(400, 425, 450, 475, 500, 525, 550), effect_vals = c(0.6, 0.7, 0.8, 0.9, 1), control_parms = lambdaHC.vec, time_vec = time.vec, censor_value = 3, alpha = 0.05, get_var = TRUE, get_bias = TRUE, get_mse = TRUE, seedval = 123) pwe_test_table <- print(pwe_test, measure = "power") pwe_test_table print("# ------------------------------ #") print("# Code for Complex Example 3 #") print("# ------------------------------ #") library("BayesCTDesign") BasicTwoArm.Bernoulli <- simple_sim(trial_reps = 10000, outcome_type = "bernoulli", subj_per_arm = c(180, 220, 240, 280, 320, 360, 400, 440, 480, 520), effect_vals = c(0.6, 0.7, 0.8, 0.9, 1), control_parms = c(0.6), alpha = 0.05, get_bias = TRUE, get_mse = TRUE, seedval = 123, quietly = FALSE) print(BasicTwoArm.Bernoulli) # Create a plot of the power simulation results. BasicPlot <- plot(BasicTwoArm.Bernoulli, measure = "power", tab_type = "WX|YZ", smooth = TRUE) BasicPlot <- BasicPlot + geom_hline(yintercept = 0.8) + geom_vline(xintercept = 480) + ggtitle("Two Arm Study, No Historical Data, Bernoulli Outcome") + xlab("Sample Size per Arm") + ylab("Estimated Power") pdf("Figure10.pdf") BasicPlot dev.off() library("BayesCTDesign") set.seed(2250) samplehistdata <- genbernoullidata(sample_size = 60, prob1 = 0.6, odds_ratio = 1.0) histdata <- subset(samplehistdata, subset = (treatment == 0)) histdata$id <- histdata$id + 10000 HistoricTwoArm.Bernoulli <- historic_sim(trial_reps = 10000, outcome_type = "bernoulli", subj_per_arm = c(180, 220, 240, 280, 320, 360, 400, 440, 480, 520), a0_vals = c(0, 0.25, 0.5, 0.75, 1), effect_vals = c(0.6, 0.7, 0.8, 0.9, 1), rand_control_diff = c(0.6, 0.8, 1, 1.2, 1.4), hist_control_data = histdata, time_vec = NULL, alpha = 0.05, get_var = TRUE, get_bias = TRUE, get_mse = TRUE, seedval = 123, quietly = FALSE) print(HistoricTwoArm.Bernoulli, measure = "power", tab_type = "WY|XZ", a0_val = 1.0, rand_control_diff_val = 1.0) HistoricPlot <- plot(HistoricTwoArm.Bernoulli, measure = "power", tab_type = "WY|XZ", a0_val = 1.0, rand_control_diff_val = 1.0, smooth = TRUE) HistoricPlot <- HistoricPlot + geom_hline(yintercept = 0.8) + geom_vline(xintercept = 480) + ggtitle("Two Arm Study, With Historical Data: Binary Outcome") + xlab("Sample Size per Arm, a0_val=1.0, control_diff=1.0") + ylab("Estimated Power") pdf("Figure11.pdf") HistoricPlot dev.off() HistoricPlot2 <- plot(HistoricTwoArm.Bernoulli, measure = "power", tab_type = "WZ|XY", a0_val = 1.0, effect_val = 0.7, smooth = TRUE) HistoricPlot2 <- HistoricPlot2 + ggtitle("Two Arm Study, With Historical Data: Binary Outcome") + xlab("Sample Size per Arm, a0_val=1.0, effect=0.7") + ylab("Estimated Power") pdf("Figure12.pdf") HistoricPlot2 dev.off() library("BayesCTDesign") HistoricTwoArm.Bernoulli2 <- historic_sim(trial_reps = 100000, outcome_type = "bernoulli", subj_per_arm = c(480), a0_vals = c(0, 0.33, 0.67, 1), effect_vals = c(1.0), rand_control_diff = c(0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6), hist_control_data = histdata, time_vec = NULL, alpha = 0.05, get_var = TRUE, get_bias = TRUE, get_mse = TRUE, seedval = 123, quietly = FALSE) HistoricPlot3 <- plot(HistoricTwoArm.Bernoulli2, measure = "power", tab_type = "XZ|WY", effect_val = 1.0, subj_per_arm_val = 480, smooth = FALSE) HistoricPlot3 <- HistoricPlot3 + ggtitle("Two Arm Study, With Historical Data: Binary Outcome") + xlab("a0 Value, Sample Size=480, effect value =1.0") + ylab("Type 1 Error") pdf("Figure15.pdf") HistoricPlot3 dev.off() HistoricTwoArm.Bernoulli3 <- historic_sim(trial_reps = 10000, outcome_type = "bernoulli", subj_per_arm = c(480), a0_vals = c(0, 0.33, 0.66, 1), effect_vals = c(0.7), rand_control_diff = c(0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4), hist_control_data = histdata, time_vec = NULL, alpha = 0.05, get_var = TRUE, get_bias = TRUE, get_mse = TRUE, seedval = 123, quietly = FALSE) HistoricPlot4 <- plot(HistoricTwoArm.Bernoulli3, measure = "power", tab_type = "ZX|WY", subj_per_arm = 480, effect_val = 0.7, smooth = TRUE) HistoricPlot4 <- HistoricPlot4 + ggtitle("Two Arm Study, With Historical Data: Binary Outcome") + xlab("Control Differences (OR), subj_per_arm=480, effect=0.7") + ylab("Power") pdf("Figure16.pdf") HistoricPlot4 dev.off() HistoricPlot5 <- plot(HistoricTwoArm.Bernoulli3, measure = "est", tab_type = "ZX|WY", subj_per_arm = 480, effect_val = 0.7, smooth = TRUE) HistoricPlot5 <- HistoricPlot5 + ggtitle("Two Arm Study, With Historical Data: Binary Outcome") + xlab("Control Differences (OR), subj_per_arm=480, effect=0.7") + ylab("Estimated Odds Ratio") pdf("Figure17.pdf") HistoricPlot5 dev.off()