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::fifelse() #182

Merged
merged 1 commit into from
Dec 12, 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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: simtrial
Type: Package
Title: Clinical Trial Simulation
Version: 0.3.2
Version: 0.3.2.1
Authors@R: c(
person("Keaven", "Anderson", email = "[email protected]", role = c("aut")),
person("Yilong", "Zhang", email = "[email protected]", role = c("aut")),
Expand Down Expand Up @@ -38,7 +38,7 @@ VignetteBuilder: knitr
Depends: R (>= 4.1.0)
Imports:
Rcpp,
data.table,
data.table (>= 1.12.4),
doFuture,
foreach,
future,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ importFrom(data.table,":=")
importFrom(data.table,.N)
importFrom(data.table,as.data.table)
importFrom(data.table,data.table)
importFrom(data.table,fifelse)
importFrom(data.table,frankv)
importFrom(data.table,last)
importFrom(data.table,merge.data.table)
Expand Down
6 changes: 3 additions & 3 deletions R/early_zero_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' @return A data frame. The column `weight` contains the weights for the
#' early zero weighted logrank test for the data in `x`.
#'
#' @importFrom data.table ":=" as.data.table merge.data.table setDF
#' @importFrom data.table ":=" as.data.table fifelse merge.data.table setDF
#'
#' @export
#'
Expand Down Expand Up @@ -97,7 +97,7 @@ early_zero_weight <- function(x, early_period = 4, fail_rate = NULL) {

# If it is unstratified design
if (n_stratum == 1) {
ans[, weight := ifelse(tte < early_period, 0, 1)]
ans[, weight := fifelse(tte < early_period, 0, 1)]
} else {
if (is.null(fail_rate)) {
stop("For stratified design to use `early_zero_weight()`, `fail_rate` can't be `NULL`.")
Expand All @@ -114,7 +114,7 @@ early_zero_weight <- function(x, early_period = 4, fail_rate = NULL) {

ans <- merge.data.table(ans, late_hr, by = "stratum", all.x = TRUE)
ans <- merge.data.table(ans, delay_change_time, by = "stratum", all.x = TRUE)
ans[, weight := ifelse(tte < duration, 0, hr)]
ans[, weight := fifelse(tte < duration, 0, hr)]
}

setDF(ans)
Expand Down
4 changes: 2 additions & 2 deletions R/mb_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#' "Non‐proportional hazards in immuno‐oncology: Is an old perspective needed?"
#' _Pharmaceutical Statistics_ 20 (3): 512--527.
#'
#' @importFrom data.table ":=" as.data.table data.table merge.data.table setDF
#' @importFrom data.table ":=" as.data.table data.table fifelse merge.data.table setDF
#'
#' @export
#'
Expand Down Expand Up @@ -151,7 +151,7 @@ mb_weight <- function(x, delay = 4, w_max = Inf) {
# Get back stratum with no records before delay ends
ans <- ans[tbl_all_stratum, on = "stratum"]
# `max_weight` is 1 when there are no records before delay ends
ans[, max_weight := ifelse(is.na(max_weight), 1, max_weight)]
ans[, max_weight := fifelse(is.na(max_weight), 1, max_weight)]
# Cut off weights at w_max
ans[, max_weight := pmin(w_max, max_weight)]
# Now merge max_weight back to stratified dataset
Expand Down