View source: R/tbl_survfit_quantiles.R
tbl_survfit_quantiles | R Documentation |
Create a gtsummary table with Kaplan-Meier estimated survival quantiles. If you must further customize the way these results are presented, see the Details section below for the full details.
tbl_survfit_quantiles(
data,
y = "survival::Surv(time = AVAL, event = 1 - CNSR, type = 'right', origin = 0)",
by = NULL,
header = "Time to event",
estimate_fun = label_style_number(digits = 1, na = "NE"),
method.args = list(conf.int = 0.95)
)
## S3 method for class 'tbl_survfit_quantiles'
add_overall(
x,
last = FALSE,
col_label = "All Participants \nN = {gtsummary::style_number(N)}",
...
)
data |
( |
y |
( |
by |
( |
header |
( |
estimate_fun |
( |
method.args |
(named Note that this list may contain non-standard evaluation components, and
must be handled similarly to tidyselect inputs by using
rlang's embrace operator |
x |
( |
last |
(scalar |
col_label |
( |
... |
These dots are for future extensions and must be empty. |
a gtsummary table
This function is a helper for creating a common summary. But if you need to modify the appearance of this table, you may need to build it from ARDs.
Here's the general outline for creating this table directly from ARDs.
Create an ARD of survival quantiles using cardx::ard_survival_survfit()
.
Construct an ARD of the minimum and maximum survival times using cards::ard_summary()
.
Combine the ARDs and build summary table with gtsummary::tbl_ard_summary()
.
# get the survival quantiles with 95% CI ard_surv_quantiles <- cardx::ard_survival_survfit( x = cards::ADTTE, y = survival::Surv(time = AVAL, event = 1 - CNSR, type = 'right', origin = 0), variables = "TRTA", probs = c(0.25, 0.50, 0.75) ) |> # modify the shape of the ARD to look like a # 'continuous' result to feed into `tbl_ard_summary()` dplyr::mutate( stat_name = paste0(.data$stat_name, 100 * unlist(.data$variable_level)), variable_level = list(NULL) ) # get the min/max followup time ard_surv_min_max <- cards::ard_summary( data = cards::ADTTE, variables = AVAL, by = "TRTA", statistic = everything() ~ cards::continuous_summary_fns(c("min", "max")) ) # stack the ARDs and pass them to `tbl_ard_summary()` cards::bind_ard( ard_surv_quantiles, ard_surv_min_max ) |> tbl_ard_summary( by = "TRTA", type = list(prob = "continuous2", AVAL = "continuous"), statistic = list( prob = c("{estimate50}", "({conf.low50}, {conf.high50})", "{estimate25}, {estimate75}"), AVAL = "{min} to {max}" ), label = list( prob = "Time to event", AVAL = "Range" ) ) |> # directly modify the labels in the table to match spec modify_table_body( ~ .x |> dplyr::mutate( label = dplyr::case_when( .data$label == "Survival Probability" ~ "Median", .data$label == "(CI Lower Bound, CI Upper Bound)" ~ "95% CI", .data$label == "Survival Probability, Survival Probability" ~ "25% and 75%-ile", .default = .data$label ) ) ) |> # update indentation to match spec modify_indent(columns = "label", rows = label == "95% CI", indent = 8L) |> modify_indent(columns = "label", rows = .data$label == "Range", indent = 4L) |> # remove default footnotes remove_footnote_header(columns = all_stat_cols())
# Example 1 ----------------------------------
tbl_survfit_quantiles(
data = cards::ADTTE,
by = "TRTA",
estimate_fun = label_style_number(digits = 1, na = "NE")
) |>
add_overall(last = TRUE, col_label = "**All Participants** \nN = {n}")
# Example 2: unstratified analysis -----------
tbl_survfit_quantiles(data = cards::ADTTE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.