How to do it...

  1. Perform the following step to generate a diagnostic plot of the fitted model:
        > install.packages("survminer")
        > library(survminer)  
  1. Generate sfit in case the previous recipe is not completed:
        > hist(cancer$time, xlab="Survival Time", main="Histogram         of survival time")
Histogram of survival times
  1. We can see from the preceding diagram that as days increase, the survival chances are low. The survival rate is high for 100 to 300 days.
  2. We want to see how gender plays a role in survival or we want to see the survival by gender. This can be achieved by the Kalpan-Meier Estimator plot. Perform the following step:
 > s <- Surv(cancer$time, ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.