surv_extract: Extract 'survfit' summaries

surv_extractR Documentation

Extract survfit summaries

Description

Convenience functions to print results from summary(x)$table where x is a survfit object.

surv_median and surv_prob extract median(s) and survival estimate(s) with optional confidence intervals, respectively. surv_extract is a generic extractor.

Usage

surv_extract(object, what = "median")

surv_median(
  object,
  ci = FALSE,
  digits = 0L,
  which = NULL,
  print = TRUE,
  na = ifelse(ci, "NR", "not reached"),
  show_conf = TRUE,
  type = c("conf.int", "range")
)

surv_prob(
  object,
  times = pretty(object$time),
  ci = FALSE,
  digits = ifelse(percent, 0L, 2L),
  which = 1L,
  print = TRUE,
  show_conf = TRUE,
  percent = FALSE
)

Arguments

object

an object of class survfit

what

the data to return, either the index, character string(s), or NULL (returns the entire table)

ci

logical; if TRUE, the confidence interval is printed

digits

number of digits past the decimal point to keep

which

optional integer or character vector to select or re-order the output; which = NULL and returns results for all strata

print

logical; if TRUE, output is prepared for in-line printing

na

a character string to replace NA when median times have not yet been reached

show_conf

logical; if TRUE, includes the confidence level

type

if ci = TRUE, the type of confidence interval to show: "conf.int" for the object$conf.int * 100 interval (default) or "range" for the full range

times

vector of times passed to surv_table

percent

logical; if TRUE, percentages are shown instead of probabilities

Examples

library('survival')
sfit1 <- survfit(Surv(time, status) ~ 1, lung)
sfit2 <- survfit(Surv(time, status) ~ sex, lung, conf.int = 0.9)

surv_extract(sfit1, NULL)
surv_extract(sfit1, 2:3)
surv_extract(sfit2, 'median|CL')
surv_extract(sfit2, c('events', 'median'))


surv_median(sfit1)
surv_median(sfit2)
surv_median(sfit2, print = FALSE)

surv_median(sfit1, ci = TRUE)
surv_median(sfit2, ci = TRUE)
surv_median(sfit2, ci = TRUE, print = FALSE)

surv_median(sfit1, ci = TRUE, type = 'range')
surv_median(sfit2, ci = TRUE, type = 'range')
surv_median(sfit2, ci = TRUE, print = FALSE, type = 'range')


times <- 365.242 * c(0.5, 1, 2)
surv_prob(sfit1, times)
## compare
summary(sfit1, times)

surv_prob(sfit2, times, which = 'sex=2', digits = 3)
## compare
summary(sfit2, times)

surv_prob(sfit2, times = 365, ci = TRUE, which = NULL)


raredd/rawr documentation built on May 9, 2024, 6:14 p.m.