3
$\begingroup$

I'm trying to use a Cox proportional hazard model to predict the time until an employee terminates from an organization. There are a bunch of covariates (~20), some of them time-dependent. So I've structured my data appropriately, created a survival object, and fed it to the coxph function successfully. Abbreviated code sample:

surv1 = Surv(Interval.Start, Interval.End, Is.Term.Record)
fit1 = coxph(surv1 ~ Age + Tenure + Gender + Stock + Perf, data=mydata)

I have a limited understanding of semi-parametric models and I'm a beginner in R, so I understand the coef and stats output but I don't know how to use fit1 to make predictions given data on a current employee despite reading some of the other posts on this topic. Should I be using something like

predict(fit1,newdata=covs,type="expected")

...but in that case, what should covs look like? And what will the output be--the expected time-to-termination or something else?

Thanks.

$\endgroup$
6
  • $\begingroup$ Yes, you should be using that sort of call. You need to provide a set of covariates that match both the original set as well as covering the time intervals of interest for the prediction. See ?predict.coxph and you may also need ?survfit.coxph $\endgroup$
    – DWin
    Commented Aug 4, 2015 at 4:15
  • $\begingroup$ You may also need ?survfit.coxph. Unless you have attach-ed the dataset, your creation of the Surv() object will not have succeeded. Therneau specifically warns against creating Surv-objects outside of the 'coxph' function because of later difficulties with the environments not being correctly accessible. $\endgroup$
    – DWin
    Commented Aug 4, 2015 at 4:22
  • $\begingroup$ I actually did nest Surv() inside coxph() in my original code. I changed it in my post for aesthetics, but you're right, I should've been more careful. My mistake. Also, after reading ?predict.coxph several times, I still don't understand exactly what the newdata argument should look like when making a new prediction. I'm also not sure what you mean by "a set of covariates that match the original set as well as covering the time intervals of interest for the prediction". Can you provide an example table? Thanks for your responses...I've been struggling with this for days! $\endgroup$ Commented Aug 5, 2015 at 16:33
  • $\begingroup$ I don't understand why I should be expected to create an example when you have not yet provided one. $\endgroup$
    – DWin
    Commented Aug 5, 2015 at 17:50
  • $\begingroup$ Fair enough...the code link, the model training data link, and the data for the employee of interest link. The first 6 rows of data for the employee of interest are intended to be the employee's history up to the current day. After this the data is forward looking and is simply forecast with everything staying constant except for age, which is predictable $\endgroup$ Commented Aug 6, 2015 at 16:33

1 Answer 1

1
$\begingroup$

I suggest to use the rms package. I extracted codes from the relevant posts (Predicting Cox survival with time-dependent covariates):

vfit2 <- cph(Surv(tstart, time, status) ~ trt + prior + karno*strat(tgroup), data=vet2,surv = T,x=T,y=T)
prob = survest(vfit2,newdata=vet2[vet2$id==2,],times=210)$surv
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.