ard_survival_survfit {cardx} | R Documentation |
ARD Survival Estimates
Description
Analysis results data for survival quantiles and x-year survival estimates, extracted
from a survival::survfit()
model.
Usage
ard_survival_survfit(x, ...)
## S3 method for class 'survfit'
ard_survival_survfit(x, times = NULL, probs = NULL, type = NULL, ...)
## S3 method for class 'data.frame'
ard_survival_survfit(
x,
y,
variables = NULL,
times = NULL,
probs = NULL,
type = NULL,
method.args = list(conf.int = 0.95, conf.type = "log"),
...
)
Arguments
x |
( | |||||||||
... |
These dots are for future extensions and must be empty. | |||||||||
times |
( | |||||||||
probs |
( | |||||||||
type |
(
| |||||||||
y |
( | |||||||||
variables |
( | |||||||||
method.args |
(named |
Details
Only one of either the
times
orprobs
parameters can be specified.Times should be provided using the same scale as the time variable used to fit the provided survival fit model.
Value
an ARD data frame of class 'card'
Formula Specification
When passing a survival::survfit()
object to ard_survival_survfit()
,
the survfit()
call must use an evaluated formula and not a stored formula.
Including a proper formula in the call allows the function to accurately
identify all variables included in the estimation. See below for examples:
library(cardx) library(survival) # include formula in `survfit()` call survfit(Surv(time, status) ~ sex, lung) |> ard_survival_survfit(time = 500) # you can also pass a data frame to `ard_survival_survfit()` as well. lung |> ard_survival_survfit(y = Surv(time, status), variables = "sex", time = 500)
You cannot, however, pass a stored formula, e.g. survfit(my_formula, lung)
,
but you can use stored formulas with rlang::inject(survfit(!!my_formula, lung))
.
Variable Classes
When the survfit
method is called, the class of the stratifying variables
will be returned as a factor.
When the data frame method is called, the original classes are retained in the resulting ARD.
Examples
library(survival)
library(ggsurvfit)
survfit(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) |>
ard_survival_survfit(times = c(60, 180))
survfit(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE, conf.int = 0.90) |>
ard_survival_survfit(probs = c(0.25, 0.5, 0.75))
cards::ADTTE |>
ard_survival_survfit(y = Surv_CNSR(AVAL, CNSR), variables = c("TRTA", "SEX"), times = 90)
# Competing Risks Example ---------------------------
set.seed(1)
ADTTE_MS <- cards::ADTTE %>%
dplyr::mutate(
CNSR = dplyr::case_when(
CNSR == 0 ~ "censor",
runif(dplyr::n()) < 0.5 ~ "death from cancer",
TRUE ~ "death other causes"
) %>% factor()
)
survfit(Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>%
ard_survival_survfit(times = c(60, 180))