# NOT RUN {
library(survival)
cfit <- coxph(Surv(time, status) ~ age + sex, lung)
sfit <- survfit(cfit)
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)
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)
# }
Run the code above in your browser using DataLab