Create a gtsummary table with Kaplan-Meier estimated survival estimates and specified times.

tbl_survfit_times(
  data,
  times,
  y = "survival::Surv(time = AVAL, event = 1 - CNSR, type = 'right', origin = 0)",
  by = NULL,
  label = "Time {time}",
  statistic = c("{n.risk}", "{estimate}", "({conf.low}, {conf.high})"),
  estimate_fun = label_roche_number(digits = 1, scale = 100),
  method.args = list(conf.int = 0.95)
)

# S3 method for class 'tbl_survfit_times'
add_difference_row(
  x,
  reference,
  statistic = c("{estimate}", "({conf.low}, {conf.high})", "{p.value}"),
  conf.level = 0.95,
  pvalue_fun = label_roche_pvalue(),
  estimate_fun = label_roche_number(digits = 2, scale = 100),
  ...
)

# S3 method for class 'tbl_survfit_times'
add_overall(
  x,
  last = FALSE,
  col_label = "All Participants  \nN = {style_roche_number(N)}",
  ...
)

Arguments

data

(data.frame)
A data frame

times

(numeric)
a vector of times for which to return survival probabilities.

y

(string or expression)
A string or expression with the survival outcome, e.g. survival::Surv(time, status). The default value is survival::Surv(time = AVAL, event = 1 - CNSR, type = "right", origin = 0).

by

(tidy-select)
A single column from data. Summary statistics will be stratified by this variable. Default is NULL, which returns results for the unstratified model.

label

(string)
Label to appear in the header row. Default is "Time {time}", where the glue syntax injects the time estimate into the label.

statistic

(character)
Character vector of the statistics to report. May use any of the following statistics: c(n.risk, estimate, std.error, conf.low, conf.high), Default is c("{n.risk}", "{estimate}", "({conf.low}, {conf.high})")

Statistics available to include when using add_difference_row() are: "estimate", "std.error", "statistic", "conf.low", "conf.high", "p.value".

estimate_fun

(function)
Function used to style/round the c(estimate, conf.low, conf.high) statistics.

method.args

(named list)
Named list of arguments that will be passed to survival::survfit().

Note that this list may contain non-standard evaluation components, and must be handled similarly to tidyselect inputs by using rlang's embrace operator {{ . }} or !!enquo() when programming with this function.

x

(tbl_survfit_times)
A stratified 'tbl_survfit_times' object

reference

(string)
Value of the tbl_survfit_times(by) variable value that is the reference for each of the difference calculations. For factors, use the character level. The reference column will appear as the leftmost column in the table.

conf.level

(numeric)
a scalar in the interval (0, 1) indicating the confidence level. Default is 0.95

pvalue_fun

(function)
Function to round and format the p.value statistic. Default is label_roche_pvalue(). The function must have a numeric vector input, and return a string that is the rounded/formatted p-value (e.g. pvalue_fun = label_style_pvalue(digits = 3)).

...

These dots are for future extensions and must be empty.

last

(scalar logical)
Logical indicator to display overall column last in table. Default is FALSE, which will display overall column first.

col_label

(string)
String indicating the column label. Default is "**Overall** \nN = {style_number(N)}"

Value

a gtsummary table

Details

When the statistic argument is modified, the statistic labels will likely also need to be updated. To change the label, call the modify_table_body() function to directly update the underlying x$table_body data frame.

Methods (by generic)

  • add_difference_row(tbl_survfit_times): Adds survival differences between groups as additional rows to tables created by tbl_survfit_times().

    Difference statistics are calculated using cardx::ard_survival_survfit_diff() for all tbl_survfit_times(times) variable values, using survfit formula:

    survival::survfit(y ~ by, data = data)

    where y, by and data are the inputs of the same names to the tbl_survfit_times() object x.

    Pairwise differences are calculated relative to the specified by variable's specified reference level.

Examples

# Example 1 ----------------------------------
tbl_survfit_times(
  data = cards::ADTTE,
  by = "TRTA",
  times = c(30, 60),
  label = "Day {time}"
) |>
  add_overall()
All Participants
N = 254
Placebo
(N = 86)
Xanomeline High Dose
(N = 84)
Xanomeline Low Dose
(N = 84)
Day 30



    Patients remaining at risk 149 69 38 42
    Event Free Rate (%) 64.1 84.4 53.0 53.4
    95% CI (58.2, 70.5) (77.0, 92.6) (42.8, 65.7) (43.4, 65.6)
Day 60



    Patients remaining at risk 93 59 14 20
    Event Free Rate (%) 45.7 76.8 24.3 31.1
    95% CI (39.6, 52.7) (68.2, 86.6) (15.8, 37.3) (21.9, 44.1)
# Example 2 - Survival Differences ----------- tbl_survfit_times( data = cards::ADTTE, by = "TRTA", times = c(30, 60), label = "Day {time}" ) |> add_difference_row(reference = "Placebo")
Placebo
(N = 86)
1
Xanomeline High Dose
(N = 84)
1
Xanomeline Low Dose
(N = 84)
1
Day 30


    Patients remaining at risk 69 38 42
    Event Free Rate (%) 84.4 53.0 53.4
    95% CI (77.0, 92.6) (42.8, 65.7) (43.4, 65.6)
    Difference in Event Free Rates 31.43 31.07
        95% CI (17.66, 45.20) (17.56, 44.58)
        p-value (Z-test) <0.0001 <0.0001
Day 60


    Patients remaining at risk 59 14 20
    Event Free Rate (%) 76.8 24.3 31.1
    95% CI (68.2, 86.6) (15.8, 37.3) (21.9, 44.1)
    Difference in Event Free Rates 52.54 45.77
        95% CI (38.65, 66.43) (31.57, 59.97)
        p-value (Z-test) <0.0001 <0.0001
1 n (%)