# Time-dependent coefficients in cox regression CPH (RMS)

I found in the R vignettes a nice article about perform time transformations in coxph (R function, package survival). This works fine for me in coxph, but I need to use cph (RMS package) because of the added functionality. This should be easy to translate, since cph is coxph with added features, but I can't get it to work.

Can some tell me how to add a continuous time transformation to variables in cph?

My code is as follow:

data(lung)
fit = coxph(Surv(time,status) ~ tt(ph.karno) + age, data=lung,x=T,y=T,tt=function(x,t,...) x*log(t))


Which works, but I need this to work:

data(lung)

fit = cph(Surv(time,status) ~ tt(ph.karno) + age, data=lung,x=T,y=T,tt=function(x,t,...) x*log(t))


I have struggled with coxph's tt subfunction as well. A (easy) workaround is to work with a 'counting process’ format dataset. In such a dataset the data for each individual is cut into periods of time. Each period will have a start time, stop time, and event status, and this is needed for each record/individual. In the resulting dataset you will be able to use an 'actual' time (is not the survival time) to model interactions with time. Finally, for the way I've used this workaround, you'll need to construct the interaction variable before entering it in the final cph code.

For your example/case I have done this as follows:

library(survival)
library(rms)

data(lung)
# original coxph tt fit
fit <- coxph(Surv(time,status) ~ ph.karno + tt(ph.karno) + age, data=lung,x=T,y=T,tt=function(x,t,...) x*log(t))

# Creating a countingprocess-format survival file using survSplit
lung.long<-survSplit(Surv(time,status)~.,data=lung,cut=1:max(lung$$time),episode="timegroup") # constructing the ph.karno and interaction with log-time variable lung.long$$ph.karnologtime<-lung.long$$ph.karno*log(lung.long$$timegroup)
# some settings required for cph and other rms functions to work
exp(fit$$coefficients) exp(fit.long$$coefficients)