#Commands to Practical exercise 1

 

 

# Read the data into R:

melanoma=read.table("http://www.uio.no/studier/emner/matnat/math/STK4080/h08/computing/melanoma.txt", header=T)

 

# Attach survival library:

library(survival)

 

 

# a) Nelson-Aalen plots for males and females:

 

fit.mel.a=survfit(Surv(lifetime,status==1)~sex, data=melanoma, type="fl", error="ts", conf.type="plain")

plot(fit.mel.a, fun="cumhaz", mark.time=F, lty=c(1,2), xlim=c(0,10), xlab="Years after operation", ylab="Cumulative hazard", main="Sex")

legend(0.5,0.55,legend=c("Females","Males"),lty=c(1,2))

 

 

# b) Nelson-Aalen plots for ulceration:

 

fit.mel.b=survfit(Surv(lifetime,status==1)~ulcer, data=melanoma, type="fl", error="ts", conf.type="plain")

plot(fit.mel.b, fun="cumhaz", mark.time=F, lty=c(1,2), xlim=c(0,10), xlab="Years after operation", ylab="Cumulative hazard", main="Ulceration")

legend(0.5,0.8,legend=c("Present","Absent"),lty=c(1,2))

 

# With confidence intervals

 

plot(fit.mel.b, fun="cumhaz", conf.int=T, mark.time=F, lty=c(1,2), xlim=c(0,10), xlab="Years after operation", ylab="Cumulative hazard", main="Ulceration")

legend(0.5,0.8,legend=c("Present","Absent"),lty=c(1,2))

 

 

# c) Nelson-Aalen plots for thickness groups:

 

fit.mel.c=survfit(Surv(lifetime,status==1)~grthick, data=melanoma, type="fl", error="ts", conf.type="plain")

plot(fit.mel.c, fun="cumhaz", mark.time=F, lty=c(1,2,3), xlim=c(0,10), xlab="Years after operation", ylab="Cumulative hazard", main="Ulceration")

legend(0.5,0.8,legend=c("0-1 mm","2-5 mm","5+ mm"),lty=c(1,2,3))