2
$\begingroup$

I'm using a Cox proportional hazards model, estimate the hazard rate for Levamisole relative to 5-FU, adjusting for Age and Sex.

library(survival)
Colon<-subset(colon,etype==2 & rx!='Obs')
fitcox<-coxph(Surv(time,status)~rx+age+sex,data=Colon)

Now if I want to make some prediction about the conditional expected lifetime given survival time up to t0, rx, age and sex, are there any convenient functions? If there's no similar function and I have to write my own, then here's a piece of pseudo code expressing what I want, but I don't know how to implement it:

function(rx, sex, age, t0, baseline, fitcox) {    
    coef <- get_coef_from(fitcox)

    //Get survival function from cumulative hazard function
    baseline$survival <- exp(-basehaz$hazard*exp(coef[1]*rx+coef[2]*sex+coef[3]*age))

    //Calculate expected life time, formula is provided below 
    survival_t0 <- baseline[t is nearest t0, survival]
    1/survival_t0*integrate(survival, t0, inf, data=baseline)
}

The formula I use is from http://en.wikipedia.org/wiki/Survival_analysis $$\frac{1}{S(t_0)} \int_0^{\infty} t\,f(t+t_0)\,dt = \frac{1}{S(t_0)} \int_{t_0}^{\infty} S(t)\,dt$$

It's fine you can help me with other hazards models, but it's better to provide example on the same dataset, thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.