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

Use data.table for grouped sort in pw_info() #300

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1.1.0.1
Version: 1.1.0.2
Authors@R: c(
person("Keaven", "Anderson", email = "[email protected]", role = c("aut")),
person("Yilong", "Zhang", email = "[email protected]", role = c("aut")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ importFrom(data.table,last)
importFrom(data.table,rbindlist)
importFrom(data.table,setDF)
importFrom(data.table,setDT)
importFrom(data.table,setorderv)
importFrom(dplyr,"%>%")
importFrom(dplyr,all_of)
importFrom(dplyr,arrange)
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ utils::globalVariables(
unique(
c(
# From data.table expressions
".",
".", ".SD",
# From `ahr()`
c("stratum", "rate", "hr", "treatment", "time", "info0", "info"),
# From `as_gt.gs_design()`
Expand Down
8 changes: 3 additions & 5 deletions R/gs_info_ahr.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' @param interval An interval that is presumed to include the time at which
#' expected event count is equal to targeted event.
#'
#' @return A tibble with columns Analysis, Time, AHR, Events, theta, info, info0.
#' @return A data frame with columns Analysis, Time, AHR, Events, theta, info, info0.
#' `info`, and `info0` contain statistical information under H1, H0, respectively.
#' For analysis `k`, `Time[k]` is the maximum of `analysis_time[k]` and the
#' expected time required to accrue the targeted `event[k]`.
Expand All @@ -46,7 +46,7 @@
#' \item If analysis_time is specified, calculate average hazard ratio using \code{AHR()}.
#' \item If event is specified, calculate average hazard ratio using \code{expected_time()}.
#' }
#' \item Return a tibble of Analysis, Time, AHR, Events, theta, info, info0.
#' \item Return a data frame of Analysis, Time, AHR, Events, theta, info, info0.
#' }
#' }
#' \if{html}{The contents of this section are shown in PDF user manual only.}
Expand All @@ -56,8 +56,6 @@
#' event times. The [expected_time()] function is used to get events and
#' average HR at targeted `analysis_time`.
#'
#' @importFrom tibble tibble
#'
#' @export
#'
#' @examples
Expand Down Expand Up @@ -172,6 +170,6 @@ gs_info_ahr <- function(
# ----------------------------#
# output results #
# ----------------------------#
ans <- avehr %>% dplyr::transmute(analysis, time, event, ahr, theta, info, info0)
ans <- avehr[, c("analysis", "time", "event", "ahr", "theta", "info", "info0")]
return(ans)
}
1 change: 1 addition & 0 deletions R/gs_info_rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#' theta0 (standardized treatment effect under null hypothesis),
#' and statistical information.
#'
#' @importFrom dplyr group_by left_join mutate select summarize ungroup
#'
#' @export
#'
Expand Down
8 changes: 3 additions & 5 deletions R/pw_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#' \if{html}{The contents of this section are shown in PDF user manual only.}
#'
#' @importFrom data.table ":=" as.data.table copy first last rbindlist setDF
#' @importFrom dplyr group_by summarize ungroup "%>%"
#' setorderv
#'
#' @export
#'
Expand Down Expand Up @@ -204,10 +204,8 @@ pw_info <- function(
ans <- rbindlist(ans_list)
# output the results
ans <- ans[, .(time, stratum, t, hr, event, info, info0)]
ans <- ans %>%
group_by(time, stratum) %>%
arrange(t, .by_group = TRUE) %>%
ungroup()
setorderv(ans, cols = c("time", "stratum"))
ans <- ans[order(t), .SD, by = .(time, stratum)]
setDF(ans)
return(ans)
}
4 changes: 2 additions & 2 deletions man/gs_info_ahr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.