Experimental lifecycle Calculate and add a p-value

# S3 method for tbl_survfit
add_p(
  x,
  test = "logrank",
  test.args = NULL,
  pvalue_fun = style_pvalue,
  include = everything(),
  quiet = NULL,
  ...
)

Arguments

x

Object of class "tbl_survfit"

test

string indicating test to use. Must be one of "logrank", "survdiff", "petopeto_gehanwilcoxon", "coxph_lrt", "coxph_wald", "coxph_score". See details below

test.args

Named list of additional arguments passed to method in test=. Does not apply to all test types.

pvalue_fun

Function to round and format p-values. Default is style_pvalue. The function must have a numeric vector input (the numeric, exact p-value), and return a string that is the rounded/formatted p-value (e.g. pvalue_fun = function(x) style_pvalue(x, digits = 2) or equivalently, purrr::partial(style_pvalue, digits = 2)).

include

Variables to include in output. Input may be a vector of quoted variable names, unquoted variable names, or tidyselect select helper functions. Default is everything().

quiet

Logical indicating whether to print messages in console. Default is FALSE

...

Not used

test argument

The most common way to specify test= is by using a single string indicating the test name. However, if you need to specify different tests within the same table, the input in flexible using the list notation common throughout the gtsummary package. For example, the following code would call the log-rank test, and a second test of the G-rho family.

... %>%
  add_p(test = list(trt ~ "logrank", grade ~ "survdiff"),
        test.args = grade ~ list(rho = 0.5))

Example Output

Example 1

Example 2

See also

Examples

library(survival) gts_survfit <- list(survfit(Surv(ttdeath, death) ~ grade, trial), survfit(Surv(ttdeath, death) ~ trt, trial)) %>% tbl_survfit(times = c(12, 24)) # Example 1 ---------------------------------- add_p_tbl_survfit_ex1 <- gts_survfit %>% add_p()
#> Calculating p-value with #> `survival::survdiff(formula = Surv(ttdeath, death) ~ grade, data = trial)`
# Example 2 ---------------------------------- # Pass `rho=` argument to `survdiff()` add_p_tbl_survfit_ex2 <- gts_survfit %>% add_p(test = "survdiff", test.args = list(rho = 0.5))
#> Calculating p-value with #> `survival::survdiff(formula = Surv(ttdeath, death) ~ grade, data = trial, rho = 0.5)`