Created
August 29, 2020 07:49
-
-
Save Lakens/68ff55b4ab8b710cca129b5f5a11d501 to your computer and use it in GitHub Desktop.
Segmented vs. Sequential Analyses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(segHT) | |
library(rpact) | |
looks <- 3 | |
n_seg <- 50 | |
alpha_level <- 0.05 | |
true_d <- 0.5 # can not enter 0, segmented_hyp_test_outcomes gives error | |
############################### | |
# Segmented procedure ---- | |
expected_summary <- segmented_hyp_test_outcomes( | |
max_n_segments = looks, | |
n_per_segment = n_seg, | |
alpha_total = alpha_level, | |
alpha_strong = 0.025, | |
stat_procedure_name = "2t", | |
effect_size = true_d, | |
base_rate = 1 | |
) | |
# Reproduces Figure 2B | |
expected_summary$pr_reject_by_segment | |
expected_summary$pr_ftr_by_segment | |
####################################################### | |
# Pocock spending function, stopping for futility ---- | |
seq_design <- getDesignGroupSequential( | |
kMax = looks, | |
typeOfDesign = "asP", | |
typeBetaSpending="bsP", | |
alpha = alpha_level | |
) | |
sample_res <- getPowerMeans( | |
design = seq_design, | |
alternative = c(0, true_d), | |
stDev = 1, | |
maxNumberOfSubjects = n_seg*looks) | |
plot(sample_res, type = 6) | |
# power sequential | |
sample_res$overallReject | |
# power segmented | |
expected_summary$avg_power | |
# sample size sequential | |
sample_res$expectedNumberOfSubjects | |
# sample size segmented | |
expected_summary$exp_n_subj | |
########################################## | |
# Compared to not stopping for futility ---- | |
seq_design <- getDesignGroupSequential( | |
kMax = looks, | |
typeOfDesign = "asP", | |
alpha = alpha_level, | |
beta = 0.2 | |
) | |
sample_res <- getPowerMeans( | |
design = seq_design, | |
groups = 2, | |
alternative = true_d, | |
stDev = 1, | |
allocationRatioPlanned = 1, | |
maxNumberOfSubjects = n_seg*looks, | |
normalApproximation = FALSE) | |
# power sequential | |
sample_res$overallReject | |
# power segmented | |
expected_summary$avg_power | |
# sample size sequential | |
sample_res$expectedNumberOfSubjects | |
# sample size segmented | |
expected_summary$exp_n_subj | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment