#Commands to practical
exercise 3
#Read data (directly from the
web-page):
melanoma<-read.table("http://www.uio.no/studier/emner/matnat/math/STK4080/h06/computing/melanoma.dat", header=T)
# Attach the library with
commands for survival analysis:
library(survival)
# a)
#Compute and plot Kaplan-Meier
separately for the two genders:
fit.mel<- survfit(Surv(lifetime,status==1)~sex,
data=melanoma, conf.type="plain")
plot(fit.mel, mark.time=F, lty=1:2, xlab="Years after
operation")
#Compute and plot Nelson-Aalen separately for the two genders:
fit.mel<- survfit(Surv(lifetime,status==1)~sex,
data=melanoma, type="fh", error="ts", conf.type="plain")
plot(fit.mel, fun="cumhaz", mark.time=F, lty=1:2, xlab="Years after operation", ylab="Cumulative
hazard")
#Compute logrank
test for gender:
survdiff(Surv(lifetime,status==1)~sex,
data=melanoma)
# b)
#Compute and plot
Kaplan-Meier separately for the three thickness groups:
fit.mel<- survfit(Surv(lifetime,status==1)~grthick, data=melanoma, conf.type="plain")
plot(fit.mel, mark.time=F, lty=1:3, xlab="Years after
operation")
#Compute and plot Nelson-Aalen separately for the three thickness groups:
fit.mel<- survfit(Surv(lifetime,status==1)~grthick, data=melanoma, type="fh",
error="ts", conf.type="plain")
plot(fit.mel, fun="cumhaz", mark.time=F, lty=1:3, xlab="Years after operation", ylab="Cumulative
hazard")
#Compute logrank
test for thickness group:
survdiff(Surv(lifetime,status==1)~grthick, data=melanoma)
# c)
#Compute and plot
Kaplan-Meier for ulceration (absent, present):
fit.mel<- survfit(Surv(lifetime,status==1)~ulcer,
data=melanoma, conf.type="plain")
plot(fit.mel, mark.time=F, lty=1:2, xlab="Years after
operation")
#Compute and plot Nelson-Aalen separately for the two genders:
fit.mel<- survfit(Surv(lifetime,status==1)~ulcer,
data=melanoma, type="fh", error="ts", conf.type="plain")
plot(fit.mel, fun="cumhaz", mark.time=F, lty=1:2, xlab="Years after operation", ylab="Cumulative
hazard")
#Compute logrank
test for gender:
survdiff(Surv(lifetime,status==1)~ulcer,
data=melanoma)
# d)
#Determine the quartiles of
the age distribution:
quantile(melanoma$age)
#Compute and plot
Kaplan-Meier separately for four age groups (almost corresponding to
quartiles):
fit.mel<- survfit(Surv(lifetime,status==1)~cut(age,
breaks=c(0,40,55,65,100)), data=melanoma, conf.type="plain")
plot(fit.mel, mark.time=F, lty=1:4, xlab="Years after
operation")
#Compute and plot Nelson-Aalen separately for the for four age groups
fit.mel<- survfit(Surv(lifetime,status==1)~ cut(age,
breaks=c(0,40,55,65,100)), data=melanoma, type="fh",
error="ts", conf.type="plain")
plot(fit.mel, fun="cumhaz", mark.time=F, lty=1:4, xlab="Years after operation", ylab="Cumulative
hazard")
#Compute logrank
test for thickness group:
survdiff(Surv(lifetime,status==1)~
cut(age, breaks=c(0,40,55,65,100)), data=melanoma)