Function accepts survival::Surv() object, extracts the follow-up times among the censored observations, and returns the requested summary statistics. Use this function to report follow-up in-line in R Markdown reports.

followup_time(
  Surv,
  data = NULL,
  pattern = "{median} (IQR {p25}, {p75})",
  style_fun = gtsummary::style_sigfig
)

Arguments

Surv

An object of class "Surv" created with survival::Surv()---not a multi-state endpoint.

data

A data frame

pattern

Statistics pattern to return. Default is "{median} (IQR {p25}, {p75})". User may select the following summary statistics to report, "{median}", "{mean}", "{p25}", "{p75}", "{sd}", "{var}", "{min}", and "{max}". Also available are "{n}" (the number of events) and "{N}" (number of non-missing observations).

style_fun

Function used to style/format the summary statistics. Default is gtsummary::style_sigfig. Argument accepts anonymous function notation, e.g. ~gtsummary::style_sigfig(., digits = 3)

Value

string of summary statistics

Examples

library(survival)

followup_time(Surv(time, status), data = lung)
#> 284 (IQR 222, 428)

followup_time(
  Surv(time, status), data = lung,
  pattern = "{median} days",
  style_fun = ~gtsummary::style_sigfig(., digits = 4)
)
#> 284.0 days

followup_time(
  survival::Surv(time, status),
  data = survival::lung,
  pattern = "{n} events with a follow-up time of {median} days (IQR {p25}, {p75})"
)
#> 165 events with a follow-up time of 284 days (IQR 222, 428)