Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

84 api #96

Merged
merged 73 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
4eef854
Re-org inst
LittleBeannie Nov 10, 2022
18afc09
update API in AHR
LittleBeannie Nov 10, 2022
5555a68
update API in `check_arg`
LittleBeannie Nov 10, 2022
6b15946
update API in `eEvents_df`
LittleBeannie Nov 10, 2022
b8a3c73
update 2 check vignettes
LittleBeannie Nov 10, 2022
949e04e
update API of `eAccrual`
LittleBeannie Nov 10, 2022
4de469e
html is updated
LittleBeannie Nov 10, 2022
e023f88
update API in `tEvents.R`
LittleBeannie Nov 10, 2022
b9884ff
2 minor update to vignettes
LittleBeannie Nov 10, 2022
e0d9063
update API for `gs_design_ahr`, `gs_power_ahr` and `gs_info_ahr`
LittleBeannie Nov 10, 2022
5ea2c3a
update IF -> info_frac in the output of `gs_design_npe` and `gs_power…
LittleBeannie Nov 10, 2022
70f753e
update API for `gs_design_wlr`, gs_power_wlr`, `gs_info_wlr` and `uti…
LittleBeannie Nov 10, 2022
c7efa4c
delete redundant vignettes
LittleBeannie Nov 10, 2022
4b5deff
update API for `gs_design_combo`, `gs_power_combo`, `gs_info_combo`, …
LittleBeannie Nov 10, 2022
79d42de
one left combo uncomitted
LittleBeannie Nov 10, 2022
f147bdf
update API of `rmst`
LittleBeannie Nov 10, 2022
8a1e86d
update API of `fixed_design`
LittleBeannie Nov 10, 2022
2694159
update `usage_ahr` vignette
LittleBeannie Nov 10, 2022
8b049f3
update `usage_eEvents` vignette
LittleBeannie Nov 10, 2022
b758924
update API of `gs_design_rd`, `gs_power_rd`
LittleBeannie Nov 10, 2022
7354573
update the `usage_fixed_design` vignette
LittleBeannie Nov 10, 2022
df5ad5a
delete a place holder vignette
LittleBeannie Nov 10, 2022
8b34f1b
minor update of a vignette
LittleBeannie Nov 10, 2022
80188f1
delete place holder vignettes
LittleBeannie Nov 10, 2022
bc8100f
update `usage_as_gt` vignette
LittleBeannie Nov 10, 2022
2185e46
update `usage_tEvents` vignette
LittleBeannie Nov 10, 2022
7fe3a86
update `usage_gs_spending_bound` vignette
LittleBeannie Nov 10, 2022
5488222
update `usage_gs_power_npe` vignette
LittleBeannie Nov 10, 2022
4a30c3f
update `usage_gs_info_ahr`
LittleBeannie Nov 10, 2022
1a98732
update `story_ahr_under_nph` vignette
LittleBeannie Nov 10, 2022
e1ffeec
update `story_compare_power_delay_effect` vignette
LittleBeannie Nov 10, 2022
98b9c2e
update `story_compute_expected_events` vignette
LittleBeannie Nov 10, 2022
f6543b5
update `story_nph_futility` vignette
LittleBeannie Nov 10, 2022
d0c8e18
update the `story_summarize_design` vignette
LittleBeannie Nov 11, 2022
4b0d2bd
update `staory_spending_time_example` vignette
LittleBeannie Nov 11, 2022
fa69a9a
update `story_risk_difference` vignette
LittleBeannie Nov 11, 2022
48809f6
update `story_quick_start` vignette
LittleBeannie Nov 11, 2022
e9ad613
update `story_nph_futility`
LittleBeannie Nov 11, 2022
dfd43a0
update `story_design_with_ahr` vignette
LittleBeannie Nov 11, 2022
e340911
update `story_design_with_spending` vignette
LittleBeannie Nov 11, 2022
995b47f
update tests
LittleBeannie Nov 11, 2022
e14b522
update tests to new API
LittleBeannie Nov 11, 2022
55804c5
solve conflict
LittleBeannie Nov 11, 2022
09d34c4
Merge branch 'main' into 84-api
LittleBeannie Nov 11, 2022
6249392
update WLR tests to the new API from the master
LittleBeannie Nov 11, 2022
4ebd6f7
update `wlr_weight` tests to new API
LittleBeannie Nov 11, 2022
0a651c1
Merge branch '84-api' of https://github.com/Merck/gsDesign2 into 84-api
LittleBeannie Nov 11, 2022
84a381c
update documentations
LittleBeannie Nov 11, 2022
1ddd1e1
CMD check
LittleBeannie Nov 11, 2022
94cf263
solve cmd check error
LittleBeannie Nov 11, 2022
56e0c1b
fix cmd check error
LittleBeannie Nov 11, 2022
7ab9e26
fix cmd check error
LittleBeannie Nov 11, 2022
5141f71
fix cmd check error
LittleBeannie Nov 11, 2022
707e97d
fix cmd check error
LittleBeannie Nov 11, 2022
f4bce8c
`eAccrual` -> `expected_accural`
LittleBeannie Nov 11, 2022
8e0b46a
`tEvents` -> `expected_time`
LittleBeannie Nov 11, 2022
290cb62
`tEvents` -> `expected_time`
LittleBeannie Nov 11, 2022
5d2df5e
`eEvents_df` -> `expected_event`
LittleBeannie Nov 11, 2022
a357e5e
solve cmd check error
LittleBeannie Nov 11, 2022
5f2807a
rename
LittleBeannie Nov 11, 2022
d52aac0
update 2 vignette with new API
LittleBeannie Nov 13, 2022
eae0c11
rename
LittleBeannie Nov 13, 2022
9930d38
correct a typo
LittleBeannie Nov 14, 2022
435ade4
another typo
LittleBeannie Nov 14, 2022
95bf85b
2 more typo
LittleBeannie Nov 14, 2022
db6d238
1 typo corrected
LittleBeannie Nov 14, 2022
b713c8b
update API in vignettes
LittleBeannie Nov 14, 2022
4a74db4
correct a typo
LittleBeannie Nov 14, 2022
6ad4058
update `gs_info_wlr`
LittleBeannie Nov 14, 2022
8ae4691
update tests with new API
LittleBeannie Nov 14, 2022
2dff37a
update spec
LittleBeannie Nov 14, 2022
8f31a82
new API in `gs_design_combo`
LittleBeannie Nov 14, 2022
0cfe37b
update version number
LittleBeannie Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gsDesign2
Title: Group Sequential Design with Non-Constant Effect
Version: 0.2.0.9000
Version: 0.2.0.9001
Authors@R: c(
person("Keaven", "Anderson", email = "keaven_anderson@merck.com", role = c("aut")),
person("Yilong", "Zhang", email = "elong0527@gmail.com", role = c("aut")),
Expand Down
6 changes: 3 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ S3method(summary,fixed_design)
S3method(summary,gs_design)
export(AHR)
export(as_gt)
export(eAccrual)
export(eEvents_df)
export(expected_accrual)
export(expected_event)
export(expected_time)
export(fixed_design)
export(gs_b)
export(gs_design_ahr)
Expand All @@ -29,7 +30,6 @@ export(gs_spending_combo)
export(pmvnorm_combo)
export(ppwe)
export(s2pwe)
export(tEvents)
export(wlr_weight_1)
export(wlr_weight_fh)
export(wlr_weight_n)
Expand Down
62 changes: 31 additions & 31 deletions R/AHR.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ NULL
#' various non-proportional hazards assumptions for either single or multiple strata studies.
#' The piecewise exponential distribution allows a simple method to specify a distribution
#' and enrollment pattern where the enrollment, failure and dropout rates changes over time.
#' @param enrollRates Piecewise constant enrollment rates by stratum and time period.
#' @param failRates Piecewise constant control group failure rates, duration for each piecewise constant period,
#' @param enroll_rate Piecewise constant enrollment rates by stratum and time period.
#' @param fail_rate Piecewise constant control group failure rates, duration for each piecewise constant period,
#' hazard ratio for experimental vs control, and dropout rates by stratum and time period.
#' @param totalDuration Total follow-up from start of enrollment to data cutoff;
#' @param total_duration Total follow-up from start of enrollment to data cutoff;
#' this can be a single value or a vector of positive numbers.
#' @param ratio ratio of experimental to control randomization.
#' @param simple logical; if TRUE (default), for each value in input totalDuration overall event count,
#' @param simple logical; if TRUE (default), for each value in input total_duration overall event count,
#' statistical information and average hazard ratio are given;
#' if FALSE, hazard ratio, expected events and statistical information are produced by stratum and underlying hazard ratio.
#' @section Specification:
Expand Down Expand Up @@ -63,7 +63,7 @@ NULL
#' information under the null and the given scenarios.
#' }
#' \item Return a tibble of overall event count, statistical information and average hazard ratio
#' of each value in totalDuration if the input simple is true, or a tibble of hazard ratio,
#' of each value in total_duration if the input simple is true, or a tibble of hazard ratio,
#' expected events and statistical information produced by stratum and
#' underlying hazard ratio if the input simple is false.
#' \item Calculation of \code{AHR} for different design scenarios, and the comparison to the
Expand All @@ -72,55 +72,55 @@ NULL
#' }
#' \if{html}{The contents of this section are shown in PDF user manual only.}
#'
#' @return A `tibble` with `Time` (from `totalDuration`), `AHR` (average hazard ratio),
#' @return A `tibble` with `Time` (from `total_duration`), `AHR` (average hazard ratio),
#' `Events` (expected number of events), info (information under given scenarios),
#' and info0 (information under related null hypothesis) for each value of `totalDuration` input;
#' and info0 (information under related null hypothesis) for each value of `total_duration` input;
#' if `simple=FALSE`, `Stratum` and `t` (beginning of each constant HR period) are also returned
#' and `HR` is returned instead of `AHR`
#'
#' @examples
#' # Example: default
#' AHR()
#'
#' # Example: default with multiple analysis times (varying totalDuration)
#' # Example: default with multiple analysis times (varying total_duration)
#'
#' AHR(totalDuration = c(15, 30))
#' AHR(total_duration = c(15, 30))
#'
#' # Stratified population
#' enrollRates <- tibble::tibble(Stratum = c(rep("Low", 2), rep("High", 3)),
#' enroll_rate <- tibble::tibble(Stratum = c(rep("Low", 2), rep("High", 3)),
#' duration = c(2, 10, 4, 4, 8),
#' rate = c(5, 10, 0, 3, 6))
#' failRates <- tibble::tibble(Stratum = c(rep("Low", 2), rep("High", 2)),
#' fail_rate <- tibble::tibble(Stratum = c(rep("Low", 2), rep("High", 2)),
#' duration = 1,
#' failRate = c(.1, .2, .3, .4),
#' fail_rate = c(.1, .2, .3, .4),
#' hr = c(.9, .75, .8, .6),
#' dropoutRate = .001)
#' AHR(enrollRates = enrollRates, failRates = failRates, totalDuration = c(15, 30))
#' dropout_rate = .001)
#' AHR(enroll_rate = enroll_rate, fail_rate = fail_rate, total_duration = c(15, 30))
#'
#' # Same example, give results by strata and time period
#' AHR(enrollRates = enrollRates, failRates = failRates, totalDuration = c(15, 30), simple = FALSE)
#' AHR(enroll_rate = enroll_rate, fail_rate = fail_rate, total_duration = c(15, 30), simple = FALSE)
#'
#' @export
#'
AHR <- function(enrollRates = tibble::tibble(Stratum = "All",
AHR <- function(enroll_rate = tibble::tibble(Stratum = "All",
duration = c(2, 2, 10),
rate = c(3, 6, 9)),
failRates = tibble::tibble(Stratum = "All",
fail_rate = tibble::tibble(Stratum = "All",
duration = c(3, 100),
failRate = log(2) / c(9, 18),
fail_rate = log(2) / c(9, 18),
hr = c(.9, .6),
dropoutRate = rep(.001, 2)),
totalDuration = 30,
dropout_rate = rep(.001, 2)),
total_duration = 30,
ratio = 1,
simple = TRUE
){
# ----------------------------#
# check input values #
# ----------------------------#
check_enrollRates(enrollRates)
check_failRates(failRates)
check_enrollRates_failRates(enrollRates, failRates)
check_totalDuration(totalDuration)
check_enroll_rate(enroll_rate)
check_fail_rate(fail_rate)
check_enroll_rate_fail_rate(enroll_rate, fail_rate)
check_total_duration(total_duration)
check_ratio(ratio)
if(!is.logical(simple)){stop("gsDesign2: simple in `AHR()` must be logical")}

Expand All @@ -130,28 +130,28 @@ AHR <- function(enrollRates = tibble::tibble(Stratum = "All",

# compute expected events by treatment group, stratum and time period
ans <- NULL
strata <- unique(enrollRates$Stratum)
strata <- unique(enroll_rate$Stratum)

for(td in totalDuration){
for(td in total_duration){

events <- NULL

for(s in strata){
# subset to stratum
enroll <- enrollRates %>% filter(Stratum == s)
fail <- failRates %>% filter(Stratum == s)
enroll <- enroll_rate %>% filter(Stratum == s)
fail <- fail_rate %>% filter(Stratum == s)

# update enrollment rates
enroll_c <- enroll %>% mutate(rate = rate * Qc)
enroll_e <- enroll %>% mutate(rate = rate * Qe)

# update failure rates
fail_c <- fail
fail_e <- fail %>% mutate(failRate = failRate * hr)
fail_e <- fail %>% mutate(fail_rate = fail_rate * hr)

# compute expected number of events
events_c <- eEvents_df(enrollRates = enroll_c, failRates = fail_c, totalDuration = td, simple = FALSE)
events_e <- eEvents_df(enrollRates = enroll_e, failRates = fail_e, totalDuration = td, simple = FALSE)
events_c <- expected_event(enroll_rate = enroll_c, fail_rate = fail_c, total_duration = td, simple = FALSE)
events_e <- expected_event(enroll_rate = enroll_e, fail_rate = fail_e, total_duration = td, simple = FALSE)

# Combine control and experimental; by period recompute HR, events, information
events <- rbind(events_c %>% mutate(Treatment = "Control"),
Expand Down
90 changes: 45 additions & 45 deletions R/as_gt.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ as_gt <- function(x, ...) {
#' library(tibble)
#'
#' # Enrollment rate
#' enrollRates <- tibble(
#' enroll_rate <- tibble(
#' Stratum = "All",
#' duration = 18,
#' rate = 20)
#'
#' # Failure rates
#' failRates <- tibble(
#' fail_rate <- tibble(
#' Stratum = "All",
#' duration = c(4, 100),
#' failRate = log(2) / 12,
#' fail_rate = log(2) / 12,
#' hr = c(1, .6),
#' dropoutRate = .001)
#' dropout_rate = .001)
#'
#' # Study duration in months
#' studyDuration <- 36
#' study_duration <- 36
#'
#' # Experimental / Control randomization ratio
#' ratio <- 1
Expand All @@ -79,8 +79,8 @@ as_gt <- function(x, ...) {
#' fixed_design(
#' x = "AHR",
#' alpha = alpha, power = 1 - beta,
#' enrollRates = enrollRates, failRates = failRates,
#' studyDuration = studyDuration, ratio = ratio
#' enroll_rate = enroll_rate, fail_rate = fail_rate,
#' study_duration = study_duration, ratio = ratio
#' ) %>%
#' summary() %>%
#' as_gt()
Expand All @@ -90,71 +90,71 @@ as_gt <- function(x, ...) {
#' # ------------------------- #
#' # under fixed power
#' fixed_design(
#' x = "FH",
#' "fh",
#' alpha = alpha, power = 1 - beta,
#' enrollRates = enrollRates, failRates = failRates,
#' studyDuration = studyDuration, ratio = ratio
#' enroll_rate = enroll_rate, fail_rate = fail_rate,
#' study_duration = study_duration, ratio = ratio
#' ) %>%
#' summary() %>%
#' as_gt()
#'
as_gt.fixed_design <- function(x, title = NULL, footnote = NULL, ...){
# get the design method
if("AHR" %in% class(x)){
design_mtd <- "AHR"
}else if("FH" %in% class(x)){
design_mtd <- "FH"
}else if("MB" %in% class(x)){
design_mtd <- "MB"
}else if("LF" %in% class(x)){
design_mtd <- "LF"
}else if("RD" %in% class(x)){
design_mtd <- "RD"
}else if("MaxCombo" %in% class(x)){
design_mtd <- "MaxCombo"
}else if("Milestone" %in% class(x)){
design_mtd <- "Milestone"
}else if("RMST" %in% class(x)){
design_mtd <- "RMST"
}else if("RD" %in% class(x)){
design_mtd <- "RD"
if("ahr" %in% class(x)){
design_mtd <- "ahr"
}else if("fh" %in% class(x)){
design_mtd <- "fh"
}else if("mb" %in% class(x)){
design_mtd <- "mb"
}else if("lf" %in% class(x)){
design_mtd <- "lf"
}else if("rd" %in% class(x)){
design_mtd <- "rd"
}else if("maxcombo" %in% class(x)){
design_mtd <- "maxcombo"
}else if("milestone" %in% class(x)){
design_mtd <- "milestone"
}else if("rmst" %in% class(x)){
design_mtd <- "rmst"
}else if("rd" %in% class(x)){
design_mtd <- "rd"
}


# set the default title
if(is.null(title)){
title <- switch (design_mtd,
"AHR" = {"Fixed Design under AHR Method"},
"FH" = {"Fixed Design under Fleming-Harrington Method"},
"MB" = {"Fixed Design under Magirr-Burman Method"},
"LF" = {"Fixed Design under Lachin and Foulkes Method"},
"RD" = {"Fixed Design of Risk Difference under Farrington-Manning Method"},
"MaxCombo" = {"Fixed Design under Max Combo Method"},
"Milestone" = {"Fixed Design under Milestone Method"},
"RMST" = {"Fixed Design under Restricted Mean Survival Time Method"},
"RD" = {"Fixed Design of Risk Difference"}
"ahr" = {"Fixed Design under AHR Method"},
"fh" = {"Fixed Design under Fleming-Harrington Method"},
"mb" = {"Fixed Design under Magirr-Burman Method"},
"lf" = {"Fixed Design under Lachin and Foulkes Method"},
"rd" = {"Fixed Design of Risk Difference under Farrington-Manning Method"},
"maxcombo" = {"Fixed Design under Max Combo Method"},
"milestone" = {"Fixed Design under Milestone Method"},
"rmst" = {"Fixed Design under Restricted Mean Survival Time Method"},
"rd" = {"Fixed Design of Risk Difference"}
)
}


# set the default footnote
if(is.null(footnote)){
footnote <- switch (design_mtd,
"AHR" = {"Power computed with average hazard ratio method."},
"FH" = {paste0("Power for Fleming-Harrington test ",
"ahr" = {"Power computed with average hazard ratio method."},
"fh" = {paste0("Power for Fleming-Harrington test ",
substr(x$Design, 19, nchar(x$Design)),
" using method of Yung and Liu.")},
"MB" = {paste0("Power for ",
"mb" = {paste0("Power for ",
x$Design,
" computed with method of Yung and Liu.")},
"LF" = {"Power using Lachin and Foulkes method applied using expected average hazard ratio (AHR) at time of planned analysis."},
"RD" = {"Risk difference power without continuity correction using method of Farrington and Manning."},
"MaxCombo" = {paste0("Power for MaxCombo test with Fleming-Harrington tests",
"lf" = {"Power using Lachin and Foulkes method applied using expected average hazard ratio (AHR) at time of planned analysis."},
"rd" = {"Risk difference power without continuity correction using method of Farrington and Manning."},
"maxcombo" = {paste0("Power for MaxCombo test with Fleming-Harrington tests",
substr(x$Design, 9, nchar(x$Design)), "."
# paste(apply(do.call(rbind, x$design_par), 2 , paste , collapse = "," ), collapse = ") and ("),
)},
"Milestone" = {paste0("Power for ", x$Design, " computed with method of Yung and Liu.")},
"RMST" = {paste0("Power for ", x$Design, " computed with method of Yung and Liu.")}
"milestone" = {paste0("Power for ", x$Design, " computed with method of Yung and Liu.")},
"rmst" = {paste0("Power for ", x$Design, " computed with method of Yung and Liu.")}
)
}

Expand Down
Loading