R-help to extra exercise on survival analysis

 

 

# Read the data into a dataframe:

melanom<-read.table("http://www.uio.no/studier/emner/matnat/math/STK4900/v09/annet/melanoma.dat", header=T)

 

# Attach the dataframe

attach(melanom)

 

# Attach the R-library for survival analysis (if you have not already done so):

library(survival)
 
 
# QUESTION a
 
# Commands:
fit.sex<-survfit(Surv(lifetime,status==1)~sex)
plot(fit.sex, lty=1:2, mark.time=F)
survdiff(Surv(lifetime,status==1)~sex)
 

 

# QUESTIONS b and c are done by similar commands

 

 

# QUESTIONS d and e
 
# Commands for sex 
coxfit.sex<-coxph(Surv(lifetime,status==1)~factor(sex))
summary(coxfit.sex)
 

# The other covariates in question d are done by similar commands, and so is question e