Description Usage Arguments Details Value Examples
This function takes a Kaplan-Meier model fit object (from survival::survfit) and calculate survival estimates at a specified time, and Median Survival Estimates. This can be performed on an overall KM fit or a fit including a categorical variable (strata).
1 2 3 4 5 6 7 8 9 10 | pretty_km_output(
fit,
time_est = NULL,
group_name = NULL,
title_name = NULL,
surv_est_prefix = "Time",
surv_est_digits = 2,
median_est_digits = 1,
output_type = NULL
)
|
fit |
survfit object (with or without single strata variable) |
time_est |
numerical vector of time estimates. If NULL (default) no time estimates are calculated |
group_name |
strata variable name. If NULL and strata exists then using variable |
title_name |
title to use |
surv_est_prefix |
prefix to use in survival estimate names. Default is Time (i.e. Time:5, Time:10,...) |
surv_est_digits |
number of digits to round p values for survival estimates for specified times |
median_est_digits |
number of digits to round p values for Median Survival Estimates |
output_type |
output type, either NULL (default), "latex", or "html" (making special charaters latex friendly) |
Currently works with multiple strata in the fit (i.e. survfit(Surv(time, event) ~ x1 + x2)
), although level and Group
column names may be off.
A tibble with: Name
(if provided), Group
(if strata variable in fit), Level
(if strata variable in fit), Median Estimate
, Time:X
(Survival estimates for each time provided, if any). In no strata variable tibble is one row, otherwise nrows = number of strata levels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # Basic linear model example
set.seed(542542522)
ybin <- sample(0:1, 100, replace = TRUE)
ybin2 <- sample(0:1, 100, replace = TRUE)
y <- rexp(100,.1)
x1 <- factor(sample(LETTERS[1:2],100,replace = TRUE))
x2 <- factor(sample(letters[1:4],100,replace = TRUE))
my_fit <- survival::survfit(survival::Surv(y, ybin) ~ 1)
my_fit2 <- survival::survfit(survival::Surv(y, ybin) ~ x1)
my_fit3 <- survival::survfit(survival::Surv(y, ybin) ~ x2)
my_fit_y2 <- survival::survfit(survival::Surv(y, ybin2) ~ 1)
pretty_km_output(fit = my_fit3, time_est = c(5,10), title_name = 'Overall Fit')
library(dplyr)
km_info <- bind_rows(
pretty_km_output(fit = my_fit, time_est = c(5,10),
group_name = 'Overall', title_name = 'Overall Survival---ybin'),
pretty_km_output(fit = my_fit2, time_est = c(5,10),
group_name = NULL, title_name = 'Overall Survival---ybin'),
pretty_km_output(fit = my_fit3, time_est = c(5,10),
group_name = 'x2', title_name = 'Overall Survival---ybin'),
pretty_km_output(fit = my_fit_y2, time_est = c(5,10),
group_name = 'Overall', title_name = 'Overall Survival---ybin2'),
) %>% select(Group, Level, everything())
kableExtra::kable(km_info, 'html', caption = 'Survival Percentage Estimates at 5 and 10 Years') %>%
kableExtra::collapse_rows(1:2, row_group_label_position = 'stack', headers_to_remove = 1:2)
# Real World Examples
data(Bladder_Cancer)
surv_obj <-survival::Surv(Bladder_Cancer$Survival_Months, Bladder_Cancer$Vital_Status == 'Dead')
downstage_fit <- survival::survfit(surv_obj ~ PT0N0, data = Bladder_Cancer)
pretty_km_output(fit = downstage_fit, time_est = c(24, 60),
surv_est_prefix = 'Month', surv_est_digits = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.