O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Plotting the curve

The curve can be plotted using the generic plot function:

plot(survfit(CoxModel.1),col=c('red','blue') ,lty=1,xlab="Months", ylab="Hazard")title(main = "Model Survival Curve")dev.copy(jpeg,Ch5 - Coxmodel1 plot.jpg); dev.off()

You can also plot a prettier version of the curve using ggplot and ggfortify:

library(ggplot2)library(ggfortify)autoplot(survfit(CoxModel.1), surv.linetype = 'dashed', surv.colour = 'blue',         conf.int.fill = 'dodgerblue3', conf.int.alpha = 0.5, censor = FALSE)

Here is a side by side comparison of the curves produced by the native plot function (left plot) and autoplot functions (right plot). The major difference is that the shaded bands replace the confidence interval dotted lines:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required