From 9fa9c61dc26da88dcc1ecf4beccb82dbfafe4661 Mon Sep 17 00:00:00 2001 From: John Blischak Date: Fri, 20 Dec 2024 11:36:31 -0500 Subject: [PATCH 1/2] Do not preface Surv() or strata() with survival:: in formulas --- DESCRIPTION | 2 +- R/rmst.R | 2 +- R/sim_fixed_n.R | 4 ++-- tests/testthat/test-independent_test_fh_weight.R | 6 +++--- tests/testthat/test-independent_test_pvalue_maxcombo.R | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 410115a6..d6252065 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,7 @@ Imports: methods, mvtnorm, stats, - survival, + survival (>= 3.8), utils Suggests: Matrix, diff --git a/R/rmst.R b/R/rmst.R index 3574c7b1..b3015b1e 100644 --- a/R/rmst.R +++ b/R/rmst.R @@ -280,7 +280,7 @@ rmst_single_arm <- function( stopifnot(0 <= alpha & alpha <= 1) # Fit a single Kaplan-Meier curve - fit <- survival::survfit(survival::Surv(time_var, event_var) ~ 1) + fit <- survival::survfit(Surv(time_var, event_var) ~ 1) # Extract survival probability, number of event, number at risk, # and number of censored along with observed time from the fitted model diff --git a/R/sim_fixed_n.R b/R/sim_fixed_n.R index fb34a84d..4dfa5084 100644 --- a/R/sim_fixed_n.R +++ b/R/sim_fixed_n.R @@ -405,12 +405,12 @@ doAnalysis <- function(d, rho_gamma, n_stratum) { event <- sum(d$event) if (n_stratum > 1) { - ln_hr <- survival::coxph(survival::Surv(tte, event) ~ (treatment == "experimental") + survival::strata(stratum), data = d)$coefficients + ln_hr <- survival::coxph(Surv(tte, event) ~ (treatment == "experimental") + strata(stratum), data = d)$coefficients ln_hr <- as.numeric(ln_hr) ans$event <- rep(event, nrow(rho_gamma)) ans$ln_hr <- rep(ln_hr, nrow(rho_gamma)) } else { - ln_hr <- survival::coxph(survival::Surv(tte, event) ~ (treatment == "experimental"), data = d)$coefficients + ln_hr <- survival::coxph(Surv(tte, event) ~ (treatment == "experimental"), data = d)$coefficients ln_hr <- as.numeric(ln_hr) ans$event <- event ans$ln_hr <- ln_hr diff --git a/tests/testthat/test-independent_test_fh_weight.R b/tests/testthat/test-independent_test_fh_weight.R index f8a85c91..79dc07d8 100644 --- a/tests/testthat/test-independent_test_fh_weight.R +++ b/tests/testthat/test-independent_test_fh_weight.R @@ -11,7 +11,7 @@ test_that("the z values match with the correspondings in fh_weight", { max <- TRUE alpha <- 0.025 data.anal <- data.frame(cbind(y$tte, y$event, y$treatment)) - fit <- survMisc::ten(survival::Surv(y$tte, y$event) ~ y$treatment, data = y) + fit <- survMisc::ten(Surv(y$tte, y$event) ~ y$treatment, data = y) # Testing survMisc::comp(fit, p = sapply(wt, function(x) x[1]), q = sapply(wt, function(x) x[2])) |> @@ -42,7 +42,7 @@ test_that("fh_weight calculated correct correlation value when input a sequence max <- TRUE alpha <- 0.025 data.anal <- data.frame(cbind(y$tte, y$event, y$treatment)) - fit <- survMisc::ten(survival::Surv(y$tte, y$event) ~ y$treatment, data = y) + fit <- survMisc::ten(Surv(y$tte, y$event) ~ y$treatment, data = y) # Testing survMisc::comp(fit, p = sapply(wt, function(x) x[1]), q = sapply(wt, function(x) x[2])) |> @@ -70,7 +70,7 @@ test_that("fh_weight calculated correct correlation value when input a sequence d1 <- data.frame(do.call(rbind, wt2)) wt3 <- unique(wt2) d2 <- data.frame(do.call(rbind, wt3)) - fit2 <- survMisc::ten(survival::Surv(y$tte, y$event) ~ y$treatment, data = y) + fit2 <- survMisc::ten(Surv(y$tte, y$event) ~ y$treatment, data = y) # Testing (for calculating the covariances) survMisc::comp(fit2, p = sapply(wt3, function(x) x[1]), q = sapply(wt3, function(x) x[2])) |> diff --git a/tests/testthat/test-independent_test_pvalue_maxcombo.R b/tests/testthat/test-independent_test_pvalue_maxcombo.R index 7e0d73c5..8c34ab0f 100644 --- a/tests/testthat/test-independent_test_pvalue_maxcombo.R +++ b/tests/testthat/test-independent_test_pvalue_maxcombo.R @@ -12,7 +12,7 @@ test_that("the p-values correspond to pvalue_maxcombo", { HT.est <- FALSE max <- TRUE alpha <- 0.025 - fit <- survMisc::ten(survival::Surv(y$tte, y$event) ~ y$treatment, data = y) + fit <- survMisc::ten(Surv(y$tte, y$event) ~ y$treatment, data = y) # Testing survMisc::comp(fit, p = sapply(wt, function(x) x[1]), q = sapply(wt, function(x) x[2])) |> @@ -35,7 +35,7 @@ test_that("the p-values correspond to pvalue_maxcombo", { d1 <- data.frame(do.call(rbind, wt2)) wt3 <- unique(wt2) d2 <- data.frame(do.call(rbind, wt3)) - fit2 <- survMisc::ten(survival::Surv(y$tte, y$event) ~ y$treatment, data = y) + fit2 <- survMisc::ten(Surv(y$tte, y$event) ~ y$treatment, data = y) # Testing (for calculating the covariances) survMisc::comp(fit2, p = sapply(wt3, function(x) x[1]), q = sapply(wt3, function(x) x[2])) |> From 2d1300585267354d0a33883031208308b774209e Mon Sep 17 00:00:00 2001 From: John Blischak Date: Tue, 7 Jan 2025 11:24:59 -0500 Subject: [PATCH 2/2] Import strata() and Surv() and remove min survival version --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/rmst.R | 1 + R/sim_fixed_n.R | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d6252065..410115a6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,7 @@ Imports: methods, mvtnorm, stats, - survival (>= 3.8), + survival, utils Suggests: Matrix, diff --git a/NAMESPACE b/NAMESPACE index 6a2a608b..0f0b6393 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,5 +54,6 @@ importFrom(mvtnorm,GenzBretz) importFrom(mvtnorm,pmvnorm) importFrom(survival,Surv) importFrom(survival,is.Surv) +importFrom(survival,strata) importFrom(survival,survfit) useDynLib(simtrial, .registration = TRUE) diff --git a/R/rmst.R b/R/rmst.R index b3015b1e..6aaa3132 100644 --- a/R/rmst.R +++ b/R/rmst.R @@ -126,6 +126,7 @@ rmst <- function( #' - `rmst_diff`: the calculation results of RMST differences. #' #' @importFrom data.table setDF rbindlist +#' @importFrom survival Surv #' @keywords internal #' #' @examples diff --git a/R/sim_fixed_n.R b/R/sim_fixed_n.R index 4dfa5084..b830ace0 100644 --- a/R/sim_fixed_n.R +++ b/R/sim_fixed_n.R @@ -70,6 +70,7 @@ #' @importFrom doFuture "%dofuture%" #' @importFrom future nbrOfWorkers plan #' @importFrom methods is +#' @importFrom survival strata Surv #' #' @export #'