Skip to content

Commit 1eba1ea

Browse files
committed
Merge branch '472-ensure-integer-sample-size-and-number-of-events' of https://github.com/Merck/gsDesign2 into 472-ensure-integer-sample-size-and-number-of-events
2 parents e6143fa + 94c9b8b commit 1eba1ea

File tree

5 files changed

+60
-70
lines changed

5 files changed

+60
-70
lines changed

R/gs_info_ahr.R

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
#' Based on piecewise enrollment rate, failure rate, and dropout rates computes
2222
#' approximate information and effect size using an average hazard ratio model.
2323
#'
24-
#' @param enroll_rate Enrollment rates.
25-
#' @param fail_rate Failure and dropout rates.
24+
#' @param enroll_rate Enrollment rates from [define_enroll_rate()].
25+
#' @param fail_rate Failure and dropout rates from [define_fail_rate()].
2626
#' @param ratio Experimental:Control randomization ratio.
2727
#' @param event Targeted minimum events at each analysis.
2828
#' @param analysis_time Targeted minimum study duration at each analysis.
2929
#' @param interval An interval that is presumed to include the time at which
3030
#' expected event count is equal to targeted event.
3131
#'
32-
#' @return A data frame with columns Analysis, Time, AHR, Events, theta, info, info0.
33-
#' `info`, and `info0` contain statistical information under H1, H0, respectively.
34-
#' For analysis `k`, `Time[k]` is the maximum of `analysis_time[k]` and the
32+
#' @return A data frame with columns `analysis`, `time`, `ahr`, `event`, `theta`, `info`, `info0`.
33+
#' The columns `info` and `info0` contain statistical information under H1, H0, respectively.
34+
#' For analysis `k`, `time[k]` is the maximum of `analysis_time[k]` and the
3535
#' expected time required to accrue the targeted `event[k]`.
36-
#' `AHR` is the expected average hazard ratio at each analysis.
36+
#' `ahr` is the expected average hazard ratio at each analysis.
3737
#'
3838
#' @section Specification:
3939
#' \if{latex}{
@@ -43,7 +43,7 @@
4343
#' \item Validate if inputs event and analysis_time have the same length if they are both specified.
4444
#' \item Compute average hazard ratio:
4545
#' \itemize{
46-
#' \item If analysis_time is specified, calculate average hazard ratio using \code{AHR()}.
46+
#' \item If analysis_time is specified, calculate average hazard ratio using \code{ahr()}.
4747
#' \item If event is specified, calculate average hazard ratio using \code{expected_time()}.
4848
#' }
4949
#' \item Return a data frame of Analysis, Time, AHR, Events, theta, info, info0.
@@ -67,8 +67,8 @@
6767
#' # Only put in targeted events
6868
#' gs_info_ahr(event = c(30, 40, 50))
6969
#' }
70-
#' # Example 2 ----
7170
#'
71+
#' # Example 2 ----
7272
#' # Only put in targeted analysis times
7373
#' gs_info_ahr(analysis_time = c(18, 27, 36))
7474
#'
@@ -79,84 +79,74 @@
7979
#' gs_info_ahr(event = c(30, 40, 50), analysis_time = c(16, 19, 26))
8080
#' gs_info_ahr(event = c(30, 40, 50), analysis_time = c(14, 20, 24))
8181
#' }
82-
gs_info_ahr <- function(
83-
enroll_rate = define_enroll_rate(
84-
duration = c(2, 2, 10),
85-
rate = c(3, 6, 9)
86-
),
87-
fail_rate = define_fail_rate(
88-
duration = c(3, 100),
89-
fail_rate = log(2) / c(9, 18),
90-
hr = c(.9, .6),
91-
dropout_rate = .001
92-
),
93-
ratio = 1, # experimental:Control randomization ratio
94-
event = NULL, # event at analyses
95-
analysis_time = NULL, # times of analyses
96-
interval = c(.01, 1000)) {
97-
# Check input values ----
82+
gs_info_ahr <- function(enroll_rate = define_enroll_rate(duration = c(2, 2, 10),
83+
rate = c(3, 6, 9)),
84+
fail_rate = define_fail_rate(duration = c(3, 100),
85+
fail_rate = log(2) / c(9, 18),
86+
hr = c(.9, .6),
87+
dropout_rate = .001),
88+
ratio = 1,
89+
event = NULL,
90+
analysis_time = NULL,
91+
interval = c(.01, 1000)) {
92+
# -------------------------- #
93+
# Check input values #
94+
# -------------------------- #
9895
check_enroll_rate(enroll_rate)
9996
check_fail_rate(fail_rate)
10097
check_enroll_rate_fail_rate(enroll_rate, fail_rate)
10198

102-
if (is.null(analysis_time) && is.null(event)) {
103-
stop("gs_info_ahr(): One of `event` and `analysis_time`
104-
must be a numeric value or vector with increasing values")
105-
}
106-
107-
n_analysis <- 0
10899
if (!is.null(analysis_time)) {
109100
check_analysis_time(analysis_time)
110-
n_analysis <- length(analysis_time)
111101
}
112102

113103
if (!is.null(event)) {
114104
check_event(event)
105+
}
115106

116-
if (n_analysis == 0) {
117-
n_analysis <- length(event)
118-
} else if (n_analysis != length(event)) {
119-
stop("gs_info_ahr(): If both event and analysis_time
120-
specified, must have same length")
107+
# at least one of `analysis_time` or `event` should be provided
108+
if (is.null(analysis_time) && is.null(event)) {
109+
stop("gs_info_ahr(): One of `event` and `analysis_time`
110+
must be a numeric value or vector with increasing values")
111+
}
112+
# if both `analysis_time` and `event` are provided, check they are of same length
113+
if (!is.null(analysis_time) && !is.null(event)) {
114+
if (length(analysis_time) != length(event)) {
115+
stop("gs_info_ahr(): If both event and analysis_time specified, must have same length")
121116
}
122117
}
123118

124-
# Check input values ----
119+
# -------------------------- #
120+
# Calc statistical info #
121+
# -------------------------- #
125122
avehr <- NULL
126123
if (!is.null(analysis_time)) {
127-
# calculate AHR, Events, info, info0 given the analysis_time
128-
avehr <- ahr(
129-
enroll_rate = enroll_rate, fail_rate = fail_rate,
130-
ratio = ratio, total_duration = analysis_time
131-
) |> select(-n)
132-
# check if the output Events is larger enough than the targeted events
124+
# calculate events given the `analysis_time`
125+
avehr <- ahr(enroll_rate = enroll_rate, fail_rate = fail_rate,
126+
ratio = ratio, total_duration = analysis_time) |> select(-n)
127+
# check if the above events >= targeted events
133128
for (i in seq_along(event)) {
134129
if (avehr$event[i] < event[i]) {
135-
avehr[i, ] <- expected_time(
136-
enroll_rate = enroll_rate, fail_rate = fail_rate,
137-
ratio = ratio, target_event = event[i],
138-
interval = interval
139-
)
130+
avehr[i, ] <- expected_time(enroll_rate = enroll_rate, fail_rate = fail_rate,
131+
ratio = ratio, target_event = event[i],
132+
interval = interval)
140133
}
141134
}
142135
} else {
143136
for (i in seq_along(event)) {
144-
avehr <- rbind(
145-
avehr,
146-
expected_time(
147-
enroll_rate = enroll_rate, fail_rate = fail_rate,
148-
ratio = ratio, target_event = event[i],
149-
interval = interval
150-
)
151-
)
137+
avehr <- rbind(avehr,
138+
expected_time(enroll_rate = enroll_rate, fail_rate = fail_rate,
139+
ratio = ratio, target_event = event[i],
140+
interval = interval))
152141
}
153142
}
154143

155-
# Compute theta ----
144+
# -------------------------- #
145+
# Tidy outputs #
146+
# -------------------------- #
156147
avehr$analysis <- seq_len(nrow(avehr))
157148
avehr$theta <- -log(avehr$ahr)
158149

159-
# Output results ----
160150
ans <- avehr[, c("analysis", "time", "event", "ahr", "theta", "info", "info0")]
161151
return(ans)
162152
}

R/gs_update_ahr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#' Group sequential design using average hazard ratio under non-proportional hazards
2020
#'
21-
#' @param x A design created by either \code{gs_design_ahr} or \code{gs_power_ahr}.
21+
#' @param x A design created by either [gs_design_ahr()] or [gs_power_ahr()].
2222
#' @param alpha Type I error for the updated design.
2323
#' @param ustime Default is NULL in which case upper bound spending time is determined by timing.
2424
#' Otherwise, this should be a vector of length k (total number of analyses)

man/gs_create_arm.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gs_info_ahr.Rd

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gs_update_ahr.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)