#Read data (directly from the web-page):
lungcancer<-read.table("http://www.uio.no/studier/emner/matnat/math/STK4080/h06/computing/lungcancer.dat", header=T)
# Attach the library with commands for survival analysis:
library(survival)
#Compute and plot for all data:
fit.lung<- survfit(Surv(time,cens)~1, data=lungcancer, type="fh", error="ts", conf.type="plain")
plot(fit.lung, fun="cumhaz", mark.time=F, xlab="Months", ylab="Cumulative hazard")
#Compute and make separate plots for males and females:
fit.lung<- survfit(Surv(time,cens)~sex, data=lungcancer, type="fh", error="ts", conf.type="plain")
plot(fit.lung, fun="cumhaz", mark.time=F, lty=c(1,4), xlab="Months", ylab="Cumulative hazard")