R Under development (unstable) (2024-12-13 r87441 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # > # Check that my updates to a. remove survival:: out of formulas and > # b: ensure that Surv(), cluster(), strata(), pspline(), and tt() use > # these functions from the survival namespace, when called in a coxph, > # survfit, survreg, etc formula > library(survival) > aeq <- function(x,y, ...) all.equal(as.vector(x), as.vector(y)) > > c1 <- coxph(Surv(time, status) ~ age + strata(inst), lung) > > # a local Surv that gives the wrong answer but won't error out (makes it > # simpler to write the tests) > Surv <- function(x, ...) survival::Surv(x, rep(1, length(x))) > c2 <- coxph(Surv(time, status) ~ age + strata(inst), lung) > > c3 <- coxph(survival::Surv(time, status) ~ age + survival::strata(inst), lung) > # in prior releases the above fits a different model, stata is not recognized > # as a special and becomes a factor > > all.equal(coef(c1), coef(c2)) [1] TRUE > all.equal(coef(c1), coef(c3)) [1] TRUE > > !(c2$call$formula == c3$call$formula) # the call doesn't get changed [1] TRUE > c2$formula == c3$formula # but the formula is changed [1] TRUE > > nocall <- function(x, omit="call") { + z <- unclass(x) # needed for any object with a [ method + z[-match(omit, names(z))] # all but $call + } > y2 <- with(lung, survival::Surv(time, status)) # outside a formula > > fit1a <- coxph(Surv(time, status) ~ age + strata(sex) + cluster(inst), lung) > fit1b <- coxph(Surv(time, status) ~ age + survival::strata(sex) + + survival::cluster(inst), lung) > fit1c <- coxph(y2 ~ age + strata(sex) + survival::cluster(inst), lung) > all.equal(nocall(fit1a), nocall(fit1b)) [1] TRUE > aeq(coef(fit1a), coef(fit1c)) [1] TRUE > > fit2a <- survdiff(Surv(time, status) ~ sex + strata(inst), lung) > fit2b <- survdiff(survival::Surv(time, status) ~ sex + survival::strata(inst), + data= lung) > all.equal(nocall(fit2a), nocall(fit2b)) [1] TRUE > aeq(rowSums(fit2a$obs), c(111, 53)) # make sure it use the correct Surv [1] TRUE > > fit3a <- survreg(Surv(time, status) ~ ph.ecog + strata(sex), lung) > fit3b <- survreg(survival::Surv(time, status) ~ ph.ecog + survival::strata(sex), + data= survival::lung) > all.equal(nocall(fit3a), nocall(fit3b)) [1] TRUE > > fit4a <- concordance(Surv(time, status) ~ ph.ecog + strata(sex), lung) > fit4b <- concordance(Surv(time, status) ~ ph.ecog + survival::strata(sex), lung) > all.equal(nocall(fit4a), nocall(fit4b)) [1] TRUE > > fit5a <- survfit(Surv(time, status) ~ sex, lung) > fit5b <- survfit(Surv(time, status) ~ strata(sex), lung) > fit5c <- survfit(survival::Surv(time, status) ~ survival::strata(sex), lung) > fit5d <- survfit(y2 ~ survival::strata(sex), lung) > all.equal(nocall(fit5a, c("call", "strata")), nocall(fit5b, c("call", "strata"))) [1] TRUE > all.equal(nocall(fit5b), nocall(fit5c)) [1] TRUE > aeq(fit5a$surv, fit5d$surv) [1] TRUE > > proc.time() user system elapsed 0.82 0.14 0.93