tbl_survfit | R Documentation |
Function takes a survfit
object as an argument, and provides a
formatted summary table of the results
tbl_survfit(x, ...)
## S3 method for class 'survfit'
tbl_survfit(x, ...)
## S3 method for class 'data.frame'
tbl_survfit(x, y, include = everything(), conf.level = 0.95, ...)
## S3 method for class 'list'
tbl_survfit(
x,
times = NULL,
probs = NULL,
statistic = "{estimate} ({conf.low}, {conf.high})",
label = NULL,
label_header = ifelse(!is.null(times), "**Time {time}**",
"**{style_sigfig(prob, scale=100)}% Percentile**"),
estimate_fun = ifelse(!is.null(times), label_style_percent(suffix = "%"),
label_style_sigfig()),
missing = "--",
type = NULL,
reverse = FALSE,
quiet = TRUE,
...
)
x |
( | |||||||||
... |
For | |||||||||
y |
outcome call, e.g. | |||||||||
include |
Variable to include as stratifying variables. | |||||||||
conf.level |
(scalar | |||||||||
times |
( | |||||||||
probs |
( | |||||||||
statistic |
( | |||||||||
label |
( | |||||||||
label_header |
( | |||||||||
estimate_fun |
( | |||||||||
missing |
( | |||||||||
type |
(
| |||||||||
reverse |
||||||||||
quiet |
Daniel D. Sjoberg
library(survival)
# Example 1 ----------------------------------
# Pass single survfit() object
tbl_survfit(
survfit(Surv(ttdeath, death) ~ trt, trial),
times = c(12, 24),
label_header = "**{time} Month**"
)
# Example 2 ----------------------------------
# Pass a data frame
tbl_survfit(
trial,
y = "Surv(ttdeath, death)",
include = c(trt, grade),
probs = 0.5,
label_header = "**Median Survival**"
)
# Example 3 ----------------------------------
# Pass a list of survfit() objects
list(survfit(Surv(ttdeath, death) ~ 1, trial),
survfit(Surv(ttdeath, death) ~ trt, trial)) |>
tbl_survfit(times = c(12, 24))
# Example 4 Competing Events Example ---------
# adding a competing event for death (cancer vs other causes)
set.seed(1123)
library(dplyr, warn.conflicts = FALSE, quietly = TRUE)
trial2 <- trial |>
dplyr::mutate(
death_cr =
dplyr::case_when(
death == 0 ~ "censor",
runif(n()) < 0.5 ~ "death from cancer",
TRUE ~ "death other causes"
) |>
factor()
)
survfit(Surv(ttdeath, death_cr) ~ grade, data = trial2) |>
tbl_survfit(times = c(12, 24), label = "Tumor Grade")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.