survfit_tidiers {broom} | R Documentation |
Construct tidied data frames showing survival curves over time.
## S3 method for class 'survfit' tidy(x, ...) ## S3 method for class 'survfit' glance(x, ...)
x |
"survfit" object |
... |
extra arguments, not used |
glance
does not work on multi-state survival curves,
since the values glance
outputs would be calculated for each state.
tidy
does work for multi-state survival objects, and includes a
state
column to distinguish between them.
All tidying methods return a data.frame without rownames, whose structure depends on the method chosen.
tidy
returns a row for each time point, with columns
time |
timepoint |
n.risk |
number of subjects at risk at time t0 |
n.event |
number of events at time t |
n.censor |
number of censored events |
estimate |
estimate of survival |
std.error |
standard error of estimate |
conf.high |
upper end of confidence interval |
conf.low |
lower end of confidence interval |
glance
returns one-row data.frame with the columns
displayed by print.survfit
records |
number of observations |
n.max |
n.max |
n.start |
n.start |
events |
number of events |
rmean |
Restricted mean (see print.survfit) |
rmean.std.error |
Restricted mean standard error |
median |
median survival |
conf.low |
lower end of confidence interval on median |
conf.high |
upper end of confidence interval on median |
if (require("survival", quietly = TRUE)) { cfit <- coxph(Surv(time, status) ~ age + sex, lung) sfit <- survfit(cfit) head(tidy(sfit)) glance(sfit) library(ggplot2) ggplot(tidy(sfit), aes(time, estimate)) + geom_line() + geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha=.25) # multi-state fitCI <- survfit(Surv(stop, status * as.numeric(event), type = "mstate") ~ 1, data = mgus1, subset = (start == 0)) td_multi <- tidy(fitCI) head(td_multi) tail(td_multi) ggplot(td_multi, aes(time, estimate, group = state)) + geom_line(aes(color = state)) + geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .25) # perform simple bootstrapping library(dplyr) bootstraps <- lung %>% bootstrap(100) %>% do(tidy(survfit(coxph(Surv(time, status) ~ age + sex, .)))) ggplot(bootstraps, aes(time, estimate, group = replicate)) + geom_line(alpha = .25) bootstraps_bytime <- bootstraps %>% group_by(time) %>% summarize(median = median(estimate), low = quantile(estimate, .025), high = quantile(estimate, .975)) ggplot(bootstraps_bytime, aes(x = time, y = median)) + geom_line() + geom_ribbon(aes(ymin = low, ymax = high), alpha = .25) # bootstrap for median survival glances <- lung %>% bootstrap(100) %>% do(glance(survfit(coxph(Surv(time, status) ~ age + sex, .)))) glances qplot(glances$median, binwidth = 15) quantile(glances$median, c(.025, .975)) }