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, cancer$status)
> sfit <- survfit(Surv(time, status)~sex, data=cancer)
  1. Lets plot the curve:
        > plot(sfit)
Plot of sfit (Kalpan-Meier Estimator)
  1. Let's plot using ggsurvplot, which will beautify the plot:
        > ggsurvplot(sfit)
  1. Add the label for gender and the risk table:
        > ggsurvplot(sfit, risk.table = TRUE, legend.labs=c("Male", 
"Female"))
Survival plot with risk table.
  1. In the same way, we can see the other options instead of gender. The following shows the survival rate by institute:
        >  ggsurvplot(survfit(Surv(time, status)~inst, data=cancer))
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset