Skip to contents

Calculates and adds a p-value comparing the survival curves of each stratified model in a table created with tbl_survfit(). Called as add_p() on a tbl_survfit object.

Value

A tbl_survfit table with a p.value column.

Arguments

  • x (tbl_survfit)
    A table created with tbl_survfit().

  • test (string or formula-list)
    The test: one of "logrank", "survdiff", "petopeto_gehanwilcoxon", "coxph_lrt", "coxph_wald" and "coxph_score". A string applies to every model; a formula list sets the test per variable, e.g. list(trt ~ "logrank", grade ~ "survdiff"). Default is "logrank". See tests for how each is computed.

  • test.args (named list or formula-list)
    Additional arguments passed to the test, e.g. list(rho = 0.5) for a test of the G-rho family with test = "survdiff". A named list applies to every model; a formula list sets the arguments per variable.

  • pvalue_fun (function)
    Function that rounds and formats the p-values. Default is label_style_pvalue(digits = 1).

  • include (selector)
    The stratified models to compute a p-value for. Default is everything().

  • ... Not used.

Note

The p-values are computed by survival::survdiff() or survival::coxph() from the formula and data of the original survfit() call, so both must be evaluable; see the formula specification section of tbl_survfit() and tbl_survfit_errors.

Examples

library(survival)

tbl <- list(
  survfit(Surv(ttdeath, death) ~ grade, trial),
  survfit(Surv(ttdeath, death) ~ trt, trial)
) |>
  tbl_survfit(times = c(12, 24))

# Example 1 ----------------------------------
tbl |>
  add_p()
# Example 2 ---------------------------------- # a test of the G-rho family, with `rho` passed to `survdiff()` tbl |> add_p(test = "survdiff", test.args = list(rho = 0.5))