View source: R/add_p.tbl_survfit.R
add_p.tbl_survfit | R Documentation |
Calculate and add a p-value to stratified tbl_survfit()
tables.
## S3 method for class 'tbl_survfit'
add_p(
x,
test = "logrank",
test.args = NULL,
pvalue_fun = label_style_pvalue(digits = 1),
include = everything(),
quiet,
...
)
x |
( |
test |
( |
test.args |
(named |
pvalue_fun |
( |
include |
( |
quiet |
|
... |
These dots are for future extensions and must be empty. |
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))
To calculate the p-values, the formula is re-constructed from the the call in the
original survfit()
object.
When the survfit()
object is created a for loop, lapply()
, purrr::map()
setting the call may not reflect the true formula which may result in an
error or an incorrect calculation.
To ensure correct results, the call formula in survfit()
must represent the
formula that will be used in survival::survdiff()
.
If you utilize the tbl_survfit.data.frame()
S3 method, this is handled for you.
Other tbl_survfit tools:
add_nevent.tbl_survfit()
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 ----------------------------------
gts_survfit |>
add_p()
# Example 2 ----------------------------------
# Pass `rho=` argument to `survdiff()`
gts_survfit |>
add_p(test = "survdiff", test.args = list(rho = 0.5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.