Skip to content

Commit

Permalink
Merge pull request #303 from jdblischak/survival-formula
Browse files Browse the repository at this point in the history
Do not preface Surv() or strata() with survival:: in formulas
  • Loading branch information
LittleBeannie authored Jan 9, 2025
2 parents 258a911 + 2d13005 commit ea88914
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion R/rmst.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -280,7 +281,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
Expand Down
5 changes: 3 additions & 2 deletions R/sim_fixed_n.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#' @importFrom doFuture "%dofuture%"
#' @importFrom future nbrOfWorkers plan
#' @importFrom methods is
#' @importFrom survival strata Surv
#'
#' @export
#'
Expand Down Expand Up @@ -405,12 +406,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
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-independent_test_fh_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])) |>
Expand Down Expand Up @@ -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])) |>
Expand Down Expand Up @@ -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])) |>
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-independent_test_pvalue_maxcombo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])) |>
Expand All @@ -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])) |>
Expand Down

0 comments on commit ea88914

Please sign in to comment.