Tidy summarizes information about the components of a model. A model component might be a single term in a regression, a single hypothesis, a cluster, or a class. Exactly what tidy considers to be a model component varies cross models but is usually self-evident. If a model has several distinct types of components, you will need to specify which components to return.

# S3 method for survfit
tidy(x, ...)

Arguments

x

An survfit object returned from survival::survfit().

...

Additional arguments. Not used. Needed to match generic signature only. Cautionary note: Misspelled arguments will be absorbed in ..., where they will be ignored. If the misspelled argument has a default value, the default value will be used. For example, if you pass conf.lvel = 0.9, all computation will proceed using conf.level = 0.95. Additionally, if you pass newdata = my_tibble to an augment() method that does not accept a newdata argument, it will use the default value for the data argument.

See also

Value

A tibble::tibble() with columns:

conf.high

The upper end of a confidence interval for the term under consideration. Included only if `conf.int = TRUE`.

conf.low

The lower end of a confidence interval for the term under consideration. Included only if `conf.int = TRUE`.

n.censor

number of censored events

n.event

number of events at time t

n.risk

Number of individuals at risk at time zero.

std.error

The standard error of the regression term.

time

Point in time.

estimate

estimate of survival or cumulative incidence rate when multistate

state

state if multistate survfit object input

strata

strata if stratified survfit object input

Examples

library(survival) cfit <- coxph(Surv(time, status) ~ age + sex, lung) sfit <- survfit(cfit) tidy(sfit)
#> # A tibble: 186 x 8 #> time n.risk n.event n.censor estimate std.error conf.high conf.low #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 5 228 1 0 0.996 0.00419 1 0.988 #> 2 11 227 3 0 0.983 0.00845 1.000 0.967 #> 3 12 224 1 0 0.979 0.00947 0.997 0.961 #> 4 13 223 2 0 0.971 0.0113 0.992 0.949 #> 5 15 221 1 0 0.966 0.0121 0.990 0.944 #> 6 26 220 1 0 0.962 0.0129 0.987 0.938 #> 7 30 219 1 0 0.958 0.0136 0.984 0.933 #> 8 31 218 1 0 0.954 0.0143 0.981 0.927 #> 9 53 217 2 0 0.945 0.0157 0.975 0.917 #> 10 54 215 1 0 0.941 0.0163 0.972 0.911 #> # ... with 176 more rows
glance(sfit)
#> # A tibble: 1 x 9 #> records n.max n.start events rmean rmean.std.error median conf.low conf.high #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 228 228 228 165 381. 20.3 320 285 363
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
#> # A tibble: 474 x 9 #> time n.risk n.event n.censor estimate std.error conf.high conf.low state #> * <dbl> <int> <int> <int> <dbl> <dbl> <dbl> <dbl> <fct> #> 1 6 0 0 0 0 0 NaN NA 2 #> 2 7 0 0 0 0 0 NaN NA 2 #> 3 31 0 0 0 0 0 NaN NA 2 #> 4 32 0 0 0 0 0 NaN NA 2 #> 5 39 0 0 0 0 0 NaN NA 2 #> 6 60 0 0 0 0 0 NaN NA 2 #> 7 61 0 0 0 0 0 NaN NA 2 #> 8 152 0 0 0 0 0 NaN NA 2 #> 9 153 0 0 0 0 0 NaN NA 2 #> 10 174 0 0 0 0 0 NaN NA 2 #> # ... with 464 more rows
ggplot(td_multi, aes(time, estimate, group = state)) + geom_line(aes(color = state)) + geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .25)