Skip to content

Commit

Permalink
Merge branch 'main' into 477-release-gsdesign2-v113
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleBeannie authored Nov 14, 2024
2 parents f8dd2bb + 57504c6 commit fe38ed5
Show file tree
Hide file tree
Showing 10 changed files with 563 additions and 53 deletions.
2 changes: 1 addition & 1 deletion R/fixed_design_lf.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#' x %>% summary()
#'
#' # Example 2: given sample size and compute power
#' x <- fixed_design_fh(
#' x <- fixed_design_lf(
#' alpha = .025,
#' enroll_rate = define_enroll_rate(duration = 18, rate = 20),
#' fail_rate = define_fail_rate(
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ utils::globalVariables(
# From `gs_design_wlr()`
c(
"IF", "time", "event", "info", "info0", "theta", "bound",
"z", "n", "rate"
"z", "n", "rate", "delta", "sigma2"
),
# From `gs_info_ahr()`
c("analysis", "time", "theta", "info", "info0"),
Expand Down
40 changes: 32 additions & 8 deletions R/gs_design_wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,18 @@ gs_design_wlr <- function(
interval = interval) %>%
dplyr::select(-c(n, delta, sigma2))

# get the FA events given the FA analysis time
final_event <- y$event[nrow(y)]
final_info <- max(y$info)
info_frac_by_time <- y$info / max(y$info)

# calculate the FA info according to different info_scale
# calculate the info_frac of planned analysis time provided by `analysis_time`
if(info_scale %in% c("h0_info", "h0_h1_info")) {
final_info <- max(y$info0)
info_frac_by_time <- y$info0 / final_info
} else {
final_info <- max(y$info)
info_frac_by_time <- y$info / final_info
}

# if it is info frac driven group sequential design
# relabel the analysis to FA, and back calculate IAs from FA
Expand Down Expand Up @@ -206,7 +215,8 @@ gs_design_wlr <- function(
enroll_rate = enroll_rate, fail_rate = fail_rate, ratio = ratio,
weight = weight, approx = approx,
final_info = final_info, next_time = next_time,
input_info_frac = info_frac[n_analysis - i])$root
input_info_frac = info_frac[n_analysis - i],
info_scale = info_scale)$root

y_ia <- gs_info_wlr(enroll_rate, fail_rate, ratio = ratio,
event = NULL, analysis_time = ia_time,
Expand All @@ -224,7 +234,8 @@ gs_design_wlr <- function(
enroll_rate = enroll_rate, fail_rate = fail_rate, ratio = ratio,
weight = weight, approx = approx,
final_info = final_info, next_time = next_time,
input_info_frac = info_frac[n_analysis - i])$root
input_info_frac = info_frac[n_analysis - i],
info_scale = info_scale)$root

y_ia <- gs_info_wlr(enroll_rate, fail_rate, ratio = ratio,
event = ia_event, analysis_time = NULL,
Expand Down Expand Up @@ -304,6 +315,7 @@ gs_design_wlr <- function(
# analysis table
analysis <- allout %>%
select(analysis, time, n, event, ahr, theta, info, info0, info_frac) %>%
mutate(info_frac0 = info0 / max(info0)) %>%
unique() %>%
arrange(analysis)

Expand Down Expand Up @@ -335,25 +347,37 @@ gs_design_wlr <- function(
# utility function to find the analysis time to get the planned/input info_frac
find_time_by_info_frac <- function(x, enroll_rate, fail_rate, ratio, weight, approx,
final_info, next_time,
input_info_frac){
input_info_frac,
info_scale){

ia_info <- gs_info_wlr(analysis_time = x, event = NULL,
enroll_rate = enroll_rate, fail_rate = fail_rate,
weight = weight, approx = approx, ratio = ratio,
interval = c(.01, next_time))

ia_info_frac <- ia_info$info / final_info
if (info_scale %in% c("h0_info", "h0_h1_info")) {
ia_info_frac <- ia_info$info0 / final_info
} else {
ia_info_frac <- ia_info$info / final_info
}

return(ia_info_frac - input_info_frac)
}

# utility function to find the event to get the planned/input info_frac
find_event_by_info_frac <- function(x, enroll_rate, fail_rate, ratio, weight, approx,
final_info, next_time,
input_info_frac){
input_info_frac,
info_scale){
ia_info <- gs_info_wlr(analysis_time = NULL, event = x,
enroll_rate = enroll_rate, fail_rate = fail_rate,
weight = weight, approx = approx, ratio = ratio,
interval = c(.01, next_time))
if (info_scale %in% c("h0_info", "h0_h1_info")) {
ia_info_frac <- ia_info$info0 / final_info
} else {
ia_info_frac <- ia_info$info / final_info
}

ia_info_frac <- ia_info$info / final_info
return(ia_info_frac - input_info_frac)
}
2 changes: 1 addition & 1 deletion R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ summary.gs_design <- function(object,
# (2) decimals to be displayed for the analysis variables in (3)
default_vars <- if (method == "rd") c("n", "rd", "info_frac") else c(
"time", "n", "event", "ahr",
switch(method, ahr = "info_frac0", wlr = "info_frac", combo = "event_frac")
switch(method, ahr = "info_frac0", wlr = "info_frac0", combo = "event_frac")
)
default_decimals <- if (method == "rd") c(1, 4, 2) else c(1, 1, 1, 2, 2)

Expand Down
Loading

0 comments on commit fe38ed5

Please sign in to comment.