40  Surv

ImportantDisclaimer

These packages (Note 1) are a one-person project undergoing rapid evolution. Backward compatibility (per Hadley Wickham) is provided as a courtesy rather than a guarantee.

Until further notice, these packages should

  • not be used as a basis for research grant applications,
  • not be cited as an actively maintained tool in a peer-reviewed manuscript,
  • not be used to support or fulfill requirements for pursuing an academic degree.

In addition, work primarily based on these packages (Note 1) should not be presented at academic conferences or similar scholarly venues.

Furthermore, a person’s ability to use these packages (Note 1) does not necessarily imply an understanding of their underlying mechanisms. Accordingly, demonstration of their use alone should not be considered sufficient evidence of expertise, nor should it be credited as a basis for academic promotion or advancement.

These statements do not apply to the contributors (Tip 1) to these packages (Note 1) with respect to their specific contributions.

These statements do not apply when the maintainer of these packages (Note 1), Tingting Zhan, is credited as the first author, the lead author, and/or the corresponding author in a peer-reviewed manuscript, or as the Principal Investigator or Co-Principal Investigator in a research grant application and/or a final research progress report.

These statements are advisory in nature and do not modify or restrict the rights granted under the GNU General Public License https://www.r-project.org/Licenses/.

The function Surv() (Therneau 2026, v3.8.6) creates a survival object, i.e., an R object of S3 class 'Surv'. Listing 40.1 summarizes the S3 methods for the class 'Surv' in package survival,

Listing 40.1: S3 methods survival::*.Surv
Code
library(survival)
.S3methods(class = 'Surv', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = (from %in% c('survival', 'registered S3method')))
#                    visible                from       generic  isS4
# [.Surv               FALSE registered S3method             [ FALSE
# anyDuplicated.Surv   FALSE registered S3method anyDuplicated FALSE
# as.character.Surv    FALSE registered S3method  as.character FALSE
# as.data.frame.Surv   FALSE registered S3method as.data.frame FALSE
# as.logical.Surv      FALSE registered S3method    as.logical FALSE
# as.matrix.Surv       FALSE registered S3method     as.matrix FALSE
# barplot.Surv         FALSE registered S3method       barplot FALSE
# c.Surv               FALSE registered S3method             c FALSE
# density.Surv         FALSE registered S3method       density FALSE
# duplicated.Surv      FALSE registered S3method    duplicated FALSE
# format.Surv           TRUE            survival        format FALSE
# head.Surv            FALSE registered S3method          head FALSE
# hist.Surv            FALSE registered S3method          hist FALSE
# identify.Surv        FALSE registered S3method      identify FALSE
# image.Surv           FALSE registered S3method         image FALSE
# is.na.Surv            TRUE            survival         is.na FALSE
# length.Surv          FALSE registered S3method        length FALSE
# levels.Surv          FALSE registered S3method        levels FALSE
# lines.Surv           FALSE registered S3method         lines FALSE
# Math.Surv            FALSE registered S3method          Math FALSE
# median.Surv          FALSE registered S3method        median FALSE
# names.Surv           FALSE registered S3method         names FALSE
# names<-.Surv         FALSE registered S3method       names<- FALSE
# Ops.Surv             FALSE registered S3method           Ops FALSE
# pairs.Surv           FALSE registered S3method         pairs FALSE
# plot.Surv            FALSE registered S3method          plot FALSE
# points.Surv          FALSE registered S3method        points FALSE
# print.Surv           FALSE registered S3method         print FALSE
# quantile.Surv        FALSE registered S3method      quantile FALSE
# rep_len.Surv         FALSE registered S3method       rep_len FALSE
# rep.int.Surv         FALSE registered S3method       rep.int FALSE
# rep.Surv             FALSE registered S3method           rep FALSE
# rev.Surv             FALSE registered S3method           rev FALSE
# Summary.Surv         FALSE registered S3method       Summary FALSE
# survfit.Surv         FALSE registered S3method       survfit FALSE
# t.Surv               FALSE registered S3method             t FALSE
# tail.Surv            FALSE registered S3method          tail FALSE
# text.Surv            FALSE registered S3method          text FALSE
# unique.Surv          FALSE registered S3method        unique FALSE
# xtfrm.Surv           FALSE registered S3method         xtfrm FALSE
Note

The examples in Chapter 40 require

library(groupedHyperframe)

Table 40.1 summarizes the S3 methods for the class 'Surv' in package groupedHyperframe (v0.4.0),

Table 40.1: S3 methods groupedHyperframe::*.Surv (v0.4.0)
visible generic isS4
[.Surv FALSE base::[ FALSE
anyDuplicated.Surv FALSE base::anyDuplicated FALSE
as.character.Surv FALSE base::as.character FALSE
as.data.frame.Surv FALSE base::as.data.frame FALSE
as.logical.Surv FALSE base::as.logical FALSE
as.matrix.Surv FALSE base::as.matrix FALSE
barplot.Surv FALSE graphics::barplot FALSE
c.Surv FALSE base::c FALSE
density.Surv FALSE stats::density FALSE
duplicated.Surv FALSE base::duplicated FALSE
head.Surv FALSE utils::head FALSE
hist.Surv FALSE graphics::hist FALSE
identify.Surv FALSE graphics::identify FALSE
image.Surv FALSE graphics::image FALSE
length.Surv FALSE base::length FALSE
levels.Surv FALSE base::levels FALSE
lines.Surv FALSE graphics::lines FALSE
Math.Surv FALSE methods::Math FALSE
median.Surv FALSE stats::median FALSE
names.Surv FALSE base::names FALSE
names<-.Surv FALSE base::`names<-` FALSE
Ops.Surv FALSE methods::Ops FALSE
pairs.Surv FALSE graphics::pairs FALSE
plot.Surv FALSE base::plot FALSE
points.Surv FALSE graphics::points FALSE
print.Surv FALSE base::print FALSE
quantile.Surv FALSE stats::quantile FALSE
rep_len.Surv FALSE base::rep_len FALSE
rep.int.Surv FALSE base::rep.int FALSE
rep.Surv FALSE base::rep FALSE
rev.Surv FALSE base::rev FALSE
summary.Surv FALSE base::summary FALSE
Summary.Surv FALSE methods::Summary FALSE
survfit.Surv FALSE survival::survfit FALSE
t.Surv FALSE base::t FALSE
tail.Surv FALSE utils::tail FALSE
text.Surv FALSE graphics::text FALSE
unique.Surv FALSE base::unique FALSE
xtfrm.Surv FALSE base::xtfrm FALSE

40.1 Summary

aml2 = survival::aml |>
  within.data.frame(expr = {
    os = survival::Surv(time = time, event = status)
    time = status = NULL
  })
aml2
#                x   os
# 1     Maintained    9
# 2     Maintained   13
# 3     Maintained  13+
# 4     Maintained   18
# ✂️ --- output truncated --- ✂️
Listing 40.2: Example: function summary.Surv()
aml2$os |> 
  summary()
#  <time-to-event> [right-censored]       [observed] 
#         "(Surv)"              "5"             "18"
Listing 40.3: Review: function summary.data.frame()
aml2 |>
  summary()
#              x                     os        
#  Maintained   :11   <time-to-event> :(Surv)  
#  Nonmaintained:12   [right-censored]:5       
#                     [observed]      :18