[R] Actual vs. predicted survival times
Bonnett, Laura
L.J.Bonnett at liverpool.ac.uk
Tue Feb 7 16:32:41 CET 2012
Dear R-help,
I am using R 2.14.1 on Windows 7.
I would like to produce a plot like the attached - although simplified to actual vs. Predicted survival time with distinguishing marks for censored and observed points. I have a dataset and have fitted a Cox model to it. In an attempt to visualise how accurate the model is it would be ideal if I could plot the actual survival times against the predicted survival times.
I have been looking on the internet to see if there are ways to do this in R. The only post I found (https://stat.ethz.ch/pipermail/r-help/2009-February/189888.html) that seemed directly relevant suggested that I shouldn't be generating survival times at all. Given that, I was concerned about proceeding but I would like to have access to a plot to make a decision on its usefulness.
I appreciate that there are predict.coxph and predict.cph options available to me.
My first attempt was as follows:
# fit Cox model #
coxfita = coxph(Surv(tsecond,seccens)~stroke(smess)+rels(smess)+asleep(smess)+eeg1(smess)+eeg2(smess)+ct1(smess)+ct2(smess)+treat(smess),data=smess)
# Find censored and observed groups #
messcens <- subset(smess,seccens==1)
messobs <- subset(smess,seccens==0)
# Obtain predicted survival times #
explp <- exp(predict(coxfita,type="lp"))
explp2 <- mean(ssmess$tsecond,na.rm=TRUE)*explp
smess2 <- data.frame(ssmess,explp2)
# Find censored and observed groups #
smesscens <- subset(smess2,seccens==1)
smessobs <- subset(smess2,seccens==0)
# Produce plot #
plot(smesscens$explp2,messcens$tsecond,pch=4,col="blue",ylab="Actual Survival Time",xlab="Predicted Survival Time",main="Survival Times",xlim=c(0,3500),ylim=c(0,3500))
points(smessobs$explp2,messobs$tsecond,pch=4,col="red")
This leads to the attached plot. It doesn't seem correct though as the predicted times all start over 500 days.
Any suggestions would be very welcome.
Many thanks,
Laura
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Actual vs. Survival LJB.pdf
Type: application/pdf
Size: 12927 bytes
Desc: Actual vs. Survival LJB.pdf
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120207/0c6e1e57/attachment.pdf>
More information about the R-help
mailing list