|
21 | 21 | #' Based on piecewise enrollment rate, failure rate, and dropout rates computes
|
22 | 22 | #' approximate information and effect size using an average hazard ratio model.
|
23 | 23 | #'
|
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()]. |
26 | 26 | #' @param ratio Experimental:Control randomization ratio.
|
27 | 27 | #' @param event Targeted minimum events at each analysis.
|
28 | 28 | #' @param analysis_time Targeted minimum study duration at each analysis.
|
29 | 29 | #' @param interval An interval that is presumed to include the time at which
|
30 | 30 | #' expected event count is equal to targeted event.
|
31 | 31 | #'
|
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 |
35 | 35 | #' 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. |
37 | 37 | #'
|
38 | 38 | #' @section Specification:
|
39 | 39 | #' \if{latex}{
|
|
43 | 43 | #' \item Validate if inputs event and analysis_time have the same length if they are both specified.
|
44 | 44 | #' \item Compute average hazard ratio:
|
45 | 45 | #' \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()}. |
47 | 47 | #' \item If event is specified, calculate average hazard ratio using \code{expected_time()}.
|
48 | 48 | #' }
|
49 | 49 | #' \item Return a data frame of Analysis, Time, AHR, Events, theta, info, info0.
|
|
67 | 67 | #' # Only put in targeted events
|
68 | 68 | #' gs_info_ahr(event = c(30, 40, 50))
|
69 | 69 | #' }
|
70 |
| -#' # Example 2 ---- |
71 | 70 | #'
|
| 71 | +#' # Example 2 ---- |
72 | 72 | #' # Only put in targeted analysis times
|
73 | 73 | #' gs_info_ahr(analysis_time = c(18, 27, 36))
|
74 | 74 | #'
|
|
79 | 79 | #' gs_info_ahr(event = c(30, 40, 50), analysis_time = c(16, 19, 26))
|
80 | 80 | #' gs_info_ahr(event = c(30, 40, 50), analysis_time = c(14, 20, 24))
|
81 | 81 | #' }
|
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 | + # -------------------------- # |
98 | 95 | check_enroll_rate(enroll_rate)
|
99 | 96 | check_fail_rate(fail_rate)
|
100 | 97 | check_enroll_rate_fail_rate(enroll_rate, fail_rate)
|
101 | 98 |
|
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 |
108 | 99 | if (!is.null(analysis_time)) {
|
109 | 100 | check_analysis_time(analysis_time)
|
110 |
| - n_analysis <- length(analysis_time) |
111 | 101 | }
|
112 | 102 |
|
113 | 103 | if (!is.null(event)) {
|
114 | 104 | check_event(event)
|
| 105 | + } |
115 | 106 |
|
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") |
121 | 116 | }
|
122 | 117 | }
|
123 | 118 |
|
124 |
| - # Check input values ---- |
| 119 | + # -------------------------- # |
| 120 | + # Calc statistical info # |
| 121 | + # -------------------------- # |
125 | 122 | avehr <- NULL
|
126 | 123 | 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 |
133 | 128 | for (i in seq_along(event)) {
|
134 | 129 | 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) |
140 | 133 | }
|
141 | 134 | }
|
142 | 135 | } else {
|
143 | 136 | 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)) |
152 | 141 | }
|
153 | 142 | }
|
154 | 143 |
|
155 |
| - # Compute theta ---- |
| 144 | + # -------------------------- # |
| 145 | + # Tidy outputs # |
| 146 | + # -------------------------- # |
156 | 147 | avehr$analysis <- seq_len(nrow(avehr))
|
157 | 148 | avehr$theta <- -log(avehr$ahr)
|
158 | 149 |
|
159 |
| - # Output results ---- |
160 | 150 | ans <- avehr[, c("analysis", "time", "event", "ahr", "theta", "info", "info0")]
|
161 | 151 | return(ans)
|
162 | 152 | }
|
0 commit comments