Visualizing the Survival Curve
Once we have created a curve model, we want to plot and see it. When we plot the data, we can actually see the survival against the time for males and females in our case.
Getting ready
You need to have completed the previous recipe.
How to do it...
- Perform the following step to generate a diagnostic plot of the fitted model:
> install.packages("survminer") > library(survminer)
- 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
- 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.
- 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 <...