[R] Plotting survival curves from a Cox model with time dependent covariates

Bjoern bjoernholzhauer at gmail.com
Fri Jul 15 08:57:53 CEST 2011


Dear all,

Let's assume I have a clinical trial with two treatments and a time to 
event outcome. I am trying to fit a Cox model with a time dependent 
treatment effect and then plot the predicted survival curve for one 
treatment (or both).

library(survival)
test <- 
list(time=runif(100,0,10),event=sample(0:1,100,replace=T),trmt=sample(0:1,100,replace=T))
model1 <- coxph(Surv(time, event) ~ tt(trmt), data=test, tt=function(x, 
t, ...) pspline(x + t))
newdat1 <- data.frame(trmt=1,time=list(0,1,2,3,4,5))
plot(survfit(model1,newdata=newdat1,individual=T), xlab = "Years", 
ylab="Survival")

Where I think I am failing is with how to correctly specify what I want 
the survfit function to do. My understanding on reading the 
documentation for the survival package is that I should use newdata to 
not only specify the treatment, but also timepoints for which I want 
survival estimates and that this is the scenario for which the 
individual=T option can be appropriate. However, I just seem to fail to 
figure out exactly how I should specify this.

It would be greatly appreciated if someone who has done this before or 
knows how to do it could give me a quick (or extensive, of course) hint.

Many thanks,
Björn

PS: Yes, I realise that a Kaplan-Meier plot would do something like the 
above very nicely, but once I get this to work, I am actually looking at 
something a bit more complicated where a KM plot would not help me.



More information about the R-help mailing list