# PRACTICAL EXERCISE 3 # ==================== # Read data: melanoma=read.table("http://www.uio.no/studier/emner/matnat/math/STK4080/h12/melanoma.txt",header=T) # Load survival library: library(survival) # Question a # We compute Kaplan-Meier estimates for females and males # with standard confidence intervals: fit.sex=survfit(Surv(lifetime,status==1)~sex,data=melanoma,conf.type="plain") # We then make a plot of the estimestes: plot(fit.sex, mark.time=F, xlab="Years after operation",lty=1:2) legend("bottomleft",c("females","males"),lty=1:2) # Finally we use the summary command to obtain the estimated survival # with confidence interval summary(fit.sex) # From the summary we may read of an estimate for the lower quartile # with confidence limits, cf. section 3.2.3 and exercise 3.8 in the ABG-book. # For females the lower quartile becomes 8.33 years with # 95% confidence limit from 5.30 years and upwards # (no upper limit can be obtained) # For males the lower quartile becomes 3.36 years with # 95% confidence limits from 2.17 to 5.76 years. # We may also find the lower quartile with confidence limits by the commands (given here for males) fit.female=survfit(Surv(lifetime,status==1)~1,data=melanoma,subset=(sex==2),conf.type="plain") q1=min(fit.female$time[fit.female$surv <= 0.75]) q1.L=min(fit.female$time[fit.female$lower <= 0.75]) q1.U=min(fit.female$time[fit.female$upper <= 0.75]) c(q1,q1.L,q1.U) # Questions b and c # The commands are as for question a, but using "ulcer" and "grthick" # instead of "sex" when computing the Kaplan-Meier estimates