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

Better plots

There is another function that you could use that gives you better graphics and is a bit more customizable than the generic plot function. It is the survplot() function, which is contained in the rms library. Since we will want to demonstrate this function in a few different ways with varying parameters, we will wrap a few of the native functions into a new function called Plotsurv(), which will allow us to customize some of the plots.

First, define the function:

library(rms)plotsurv <- function(x,y,z=c('bars'),zz=FALSE){  objNpsurv <- npsurv(formula = Surv(Xtenure2,Churn ==1) ~ x, data = ChurnStudy)  class(objNpsurv)  survplot(objNpsurv,col=c('green','red','blue','yellow','orange','purple'), label.curves=list(keys=y),xlab='Months',conf=z,conf.int=.95,n.risk=zz) ...

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