shine_coxph {shinyCox} | R Documentation |
Generates a shiny app for predictions from Cox model(s)
Description
Writes a shiny app to visualize predicted survival curves from one or multiple Cox models. One feature of this function is that the shiny app, once created, will not contain any identifiable data, containing only information necessary for predictions.
Usage
shine_coxph(..., app.dir = NULL, theme = c("default", "dashboard"))
Arguments
... |
Arbitrary number of Cox proportional hazard models, created by
|
app.dir |
Directory where shiny app is created. Specifically, a
sub-folder will be made containing the |
theme |
Theme of shiny app.
|
Value
A list containing Cox model information along with the shiny app code. The app is written to the directory while the function is operating.
Notes
There are some requirements in order for this function to run without
error: in your original survival::coxph()
function or functions,
model = TRUE
and x = TRUE
are required arguments (used to create the
simplified "coxph"
object). Currently, this function does not support
penalized models (e.g., as created by ridge()
and pspline()
). Multiple
strata terms and strata by covariate interaction terms in the formula are
also not currently supported, but workarounds are available by respectively
using a new strata factor variable encompassing all combinations of desired
stratum variable levels. Use of time-varying covariates (e.g. with tt()
)
and multi-state models is not supported in our function. The package is not
intended to support Fine-gray models by survival::finegray()
creating Cox
models, but doing so will not result in an error.
Guidelines
This package is intended to visualize and present predicted survival
functions for fitted Cox models. In regards to formula notation, the
variable names used are ultimately what will be displayed in the
application. Using functions in the formula will work, but with multiple
nested functions it will fail. Using "." notation is not currently
supported. The na.action
is inherited from the Cox models, with omit
being the only option with support at this time. For these reasons, we
recommend creating all final variables (including suitable transformations)
with meaningful names prior to using survival::coxph()
.
Examples
library(survival)
# Data used is from survival package, renamed for legibility
names(leukemia)[names(leukemia) == "x"] <- "treatment"
# Make Cox model, with x = TRUE and model = TRUE
model1 <- coxph(Surv(time, status) ~ treatment,
leukemia, x = TRUE, model = TRUE)
# Use shine_coxph() to create shiny app in temporary directory
shine_coxph("Model 1" = model1)
# Get directory for shiny app (should be first, check file list if not)
filedir <- list.files(tempdir())[1]
# Run shiny app from temporary directory
shiny::runApp(paste0(tempdir(), "/", filedir))
# Remove app from directory once finished
unlink(paste0(tempdir(),"/",filedir), recursive = TRUE)