Description Usage Arguments Value Examples
This function takes a dataset, along with variables names for time and event status for KM fit, and possibly strata
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | run_pretty_km_output(
strata_in = NA,
model_data,
time_in,
event_in,
event_level = NULL,
time_est = NULL,
group_name = NULL,
title_name = NULL,
conf_level = 0.95,
surv_est_prefix = "Time",
surv_est_digits = 2,
median_est_digits = 1,
p_digits = 4,
output_type = NULL,
sig_alpha = 0.05,
background = "yellow",
...
)
|
strata_in |
name of strata variable, or NA (default) if no strata desired |
model_data |
dataset that contains |
time_in |
name of time variable component of outcome measure |
event_in |
name of event status variable. If |
event_level |
event level for event status 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 |
conf_level |
the confidence level required (default is 0.95). |
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 |
p_digits |
number of digits to round p values for Log-Rank p value |
output_type |
output type, either NULL (default), "latex", or "html" (making special charaters latex friendly) |
sig_alpha |
the defined significance level. Default = 0.05 |
background |
background color of significant values, or no highlighting if NULL. Default is "yellow" |
... |
other params to pass to |
A tibble with: Name
(if provided), Group
(if strata variable in fit), Level
(if strata variable in fit), Time:X
(Survival estimates for each time provided), Median Estimate
. 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # Basic survival model examples
set.seed(542542522)
ybin <- sample(0:1, 100, replace = TRUE)
ybin2 <- sample(0:1, 100, replace = TRUE)
ybin3 <- sample(c('Dead','Alive'), 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_data <- data.frame(y, ybin, ybin2, ybin3, x1, x2)
Hmisc::label(my_data$x1) <- "X1 Variable"
# Single runs
run_pretty_km_output(strata_in = 'x1', model_data = my_data,
time_in = 'y', event_in = 'ybin', time_est = NULL)
run_pretty_km_output(strata_in = 'x1', model_data = my_data,
time_in = 'y', event_in = 'ybin', time_est = c(5,10))
run_pretty_km_output(strata_in = 'x2', model_data = my_data,
time_in = 'y', event_in = 'ybin3', event_level = 'Dead', time_est = c(5,10))
# Multiple runs for different variables
library(dplyr)
vars_to_run = c(NA, 'x1', 'x2')
purrr::map_dfr(vars_to_run, run_pretty_km_output, model_data = my_data,
time_in = 'y', event_in = 'ybin', event_level = '0', time_est = NULL) %>%
select(Group, Level, everything())
km_info <- purrr::map_dfr(vars_to_run, run_pretty_km_output, model_data = my_data, time_in = 'y',
event_in = 'ybin3', event_level = 'Dead', time_est = c(5,10), surv_est_prefix = 'Year',
title_name = 'Overall Survival') %>%
select(Group, Level, everything())
km_info2 <- purrr::map_dfr(vars_to_run, run_pretty_km_output, model_data = my_data, time_in = 'y',
event_in = 'ybin2', time_est = c(5,10), surv_est_prefix = 'Year',
title_name = 'Cancer Specific Survival') %>%
select(Group, Level, everything())
options(knitr.kable.NA = '')
kableExtra::kable(bind_rows(km_info, km_info2), escape = FALSE
, longtable = FALSE, booktabs = TRUE, linesep = '',
caption = 'Survival Percentage Estimates at 5 and 10 Years') %>%
kableExtra::collapse_rows(c(1:2), row_group_label_position = 'stack'
, headers_to_remove = 1:2)
# Real World Example
data(Bladder_Cancer)
vars_to_run = c(NA, 'Gender', 'Clinical_Stage_Grouped', 'PT0N0', 'Any_Downstaging')
purrr::map_dfr(vars_to_run, run_pretty_km_output, model_data = Bladder_Cancer,
time_in = 'Survival_Months', event_in = 'Vital_Status', event_level = 'Dead',
time_est = c(24,60), surv_est_prefix = 'Month', p_digits=5) %>%
select(Group, Level, everything())
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.