View source: R/postsurvplots.R
plot.glmnetsurvfit | R Documentation |
Plot estimated survival and cumulative hazard curves for glmnet
model.
glmnetsurvfit.glmnetsurv
## S3 method for class 'glmnetsurvfit' plot(x, ..., type = c("surv", "cumhaz"), lsize = 0.3, compare = FALSE)
x |
a |
... |
for future implementations |
type |
type of curve to generate. Either |
lsize |
line size for the curves. Default is |
compare |
logical. Whether to return plot with labels to add additional |
Depending on the specification in glmnetsurvfit.glmnetsurv
, this function plots either average or individual survival or cumulative hazard curves. The plot is a ggplot
object, hence can be be customized further, see example below.
a ggplot
object.
library(ggplot2) data(veteran, package="survival") gmodel <- glmnetsurv(Surv(time, status) ~ factor(trt) + karno + diagtime + age + prior , data = veteran , lambda = 0 , alpha = 1 ) # Survival estimate gsurv <- glmnetsurvfit(fit = gmodel) # Plot survival curves plot(gsurv) # Baseline survival estimate gbsurv <- glmnetbasehaz(gmodel, centered = FALSE) plot(gbsurv) # Compare overall and baseline cumulative hazard p1 <- plot(gsurv, type = "cumhaz", compare = TRUE) df2 <- data.frame(time = gbsurv$time, cumhaz = gbsurv$hazard) p2 <- (p1 + geom_line(data = df2, aes(x = time, y = cumhaz, group = 1, col = "baseline")) + scale_colour_manual(name = "C. hazard" , values = c("#E41A1C", "#000000") , labels = c("baseline", "overall") ) ) print(p2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.