Bjoern
2011-Jul-15 06:57 UTC
[R] Plotting survival curves from a Cox model with time dependent covariates
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.
Terry Therneau
2011-Jul-15 13:19 UTC
[R] Plotting survival curves from a Cox model with time dependent covariates
The time-transform (tt() arguments) feature is the most recent addition to coxph. Most of the follow-up functions, in particular survfit(fit) have not yet been updated to deal with such models. Your message points out that I need to at least update them to add a "not yet available" error message. I'm still learning what can be done with the tt() option. If I assume that your trmt variable is 0/1, then the code below is a clever way to look at time dependent treatment effects. I had not thought of it. Terry Therneau --- begin included message --- 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))
Seemingly Similar Threads
- Predicted Cox survival curves - factor coding problems..
- Survfit: why different survival curves but same parameter estimates?
- Predicted Cox survival curves - factor coding problems...
- importing SAS data
- non-cumulative hazard in Cox model with time-dependent covariates