#Commands to practical
exercise 5
#The
commands below assume that the cirrhosis ("skrumplever")
data set has been stored
# in
the dataframe "skrumplever"
and that the survival library has been attached
# (cf. the
R commands to practical exercise 3).
# Define
treatment, gender, and ascites to be factors:
skrumplever$beh<-factor(skrumplever$beh)
skrumplever$kjonn<-factor(skrumplever$kjonn)
skrumplever$asc<-factor(skrumplever$asc)
# One possible model for the data is
(use years as time unit)
cox.fit<- coxph(Surv(tid/365.25,status)~ beh+kjonn+asc+alder+prot+beh:asc,
data=skrumplever)
# To
assess the appropriate functional form of a numeric covariate we may make a
smoothed plot
# of the martingale residuals
versus the covariate for a model fitted without the actual covariate.
# To
check whether age has a log-linear form, we first fit a model without age
cox.fit0<- coxph(Surv(tid/365.25,status)~
beh+kjonn+asc+prot+beh:asc,
data=skrumplever)
martres.fit0<-residuals(cox.fit0, type="mart")
#We
then make a plot of the martingale residuals versus age and add a smoothed
curve to the plot:
plot(skrumplever$alder, martres.fit0, xlab="Age",ylab=" ")
spline.fit<-smooth.spline(skrumplever$alder, martres.fit0)
lines(spline.fit$x, spline.fit$y)
#Similarily
for prothrombin
cox.fit0<- coxph(Surv(tid/365.25,status)~
beh+kjonn+asc+alder+beh:asc,
data=skrumplever)
martres.fit0<-residuals(cox.fit0, type="mart")
plot(skrumplever$prot, martres.fit0, xlab="Prothrombin",ylab=" ")
spline.fit<-smooth.spline(skrumplever$prot, martres.fit0)
lines(spline.fit$x, spline.fit$y)
#We
finally check for proportionality of the covariates:
cox.zph(cox.fit)
#and make plots that suggest
the (possible) time dependent effect of a covariate:
par(mfrow=c(2,4))
plot(cox.zph(cox.fit))