# Prediction in Cox regression

I am doing a multivariate Cox regression, I have my significant independent variables and beta values. The model fits to my data very well.

Now, I would like to use my model and predict the survival of a new observation. I am unclear how to do this with a Cox model. In a linear or logistic regression, it would be easy, just put the values of new observation in the regression and multiply them with betas and so I have the prediction of my outcome.

How can I determine my baseline hazard? I need it in addition to computing the prediction.

How is this done in a Cox model?

-

Following Cox model, the estimated hazard for individual $i$ with covariate vector $x_i$ has the form $$\hat{h}_i(t) = \hat{h}_0(t) \exp(x_i' \hat{\beta}),$$ where $\hat{\beta}$ is found by maximising the partial likelihood, while $\hat{h}_0$ follows from the Nelson-Aalen estimator, $$\hat{h}_0(t_i) = \frac{d_i}{\sum_{j:t_j \geq t_i} \exp(x_j' \beta)}$$ with $t_1$, $t_2, \dotsc$ the distinct event times and $d_i$ the number of ties at $t_i$ (see, e.g., Section 3.6).

Similarly, $$\hat{S}_i(t) = \hat{S}_0(t)^{\exp(x_i' \hat{\beta})}$$ with $\hat{S}_0(t) = \exp(- \hat{\Lambda}_0(t))$ and $$\hat{\Lambda}_0(t) = \sum_{j:t_j \leq t} \hat{h}_0(t_j).$$

EDIT: This might also be of interest :-)

-
Wow, great! Thanks a lot. –  Marja Sep 11 '12 at 7:00
Maybe I should ask my question in another way. What I am looking for is the way to predict an outcome in Cox model. For my survival analysis, I used a Cox proportional hazard approach. I got a list of sig. factors for my outcome and now, I would like to use my model to predict the survival of a new observation. Do I need estimation of baseline hazard? How can I predict my survival? –  Marja Sep 11 '12 at 7:14
Survival analysis is not commonly used to predict future times to an event. There could be a variety of ways to do this say by applying median survival time or mean survival time to take two examples. But the properties of the survival curve that you need would require an estimated survival curve which for the Cox model would require specification of the baseline hazard function (that is not provided in the Cox approach). –  Michael Chernick Sep 11 '12 at 10:58
@Marjan by saying that you got a list of "significant" factors you imply that you used variable selection that may result in unreliable predictions. Bootstrap validation, repeating all variable selection steps for, say, 300 resamples, may be worth doing. –  Frank Harrell Sep 11 '12 at 11:29
@Marjan the jackknife may not properly reflect uncertainty caused by variable selection. The bootstrap properly shows more variability in which variables are labeled "significant". If you want to do a "relative validation" you can show that predictive discrimination is good after correcting for overfitting. This does not require dealing with the baseline hazard, but is validating relative log hazard estimates. The validate function in the R rms package in conjunction with the cph function will do that. The only stepwise algorithm implemented in validate is backwards stepdown. –  Frank Harrell Sep 12 '12 at 12:44

The function predictSurvProb in the pec package can give you absolute risk estimates for new data based on an existing cox model if you use R.

The mathematical details I cannot explain.

EDIT: The function provides survival probabilities, which I have so far taken as 1-(Event probability).

-
Thank you very much. I will check this function. –  Marja Sep 11 '12 at 7:15
1-Survival probability is the cumulative hazard. I think the OP requests the instantaneous hazard function (of the baseline) or some kind of smoothed estimate of it (muhaz packages in R). –  ECII Mar 9 at 21:32

The whole point of the Cox model is the proportional hazard's assumption and the use of the partial likelhood. The partial likelihood has the baseline hazard function eliminated. So you do not need to specify one. That is the beauty of it!

-
If you however want to get an estimate of the hazard or the survival for a particular value of the covariate vector, then you do need an estimate of the baseline hazard or survival. The Nelson-Aalen estimate usually makes the job... –  ocram Sep 10 '12 at 15:13
Often with the Cox model you are comparing two survival functions and the key is the hazard ratio rather than the hazard function. The baseline hazard is like a nuisance parameter that Cox so cleverly eliminated from the problem using the proportional hazards assumption. Whatever method you would like to use for estimating the hazard function and/or the baseline hazard in the context of the model would require using the Cox form of the model which forces proportionality. –  Michael Chernick Sep 10 '12 at 15:30
Thank you so much, It would be great if you see my comment on the answer of ocram. Maybe you could help me too? –  Marja Sep 11 '12 at 7:17
You can also stratify on factors that are not in proportional hazards. But at any rate the Cox model and its after-the-fit estimator of the baseline hazard can be used to get predicted quantiles of survival time, various survival probabilities, and predicted mean survival time if you have long-term follow-up. All these quantities are easy to get in the R package rms. –  Frank Harrell Sep 11 '12 at 11:31

The basehaz function of survival packages provides the baseline hazard at the event time points. From that you can work your way up the math that ocram provides and include the ORs of your coxph estimates.

-

Maybe you would also like to try something like this? Fit a coxph model and use it to get the predicted Survival curve for a new instance.

Taken out of the help file for the survfit.coxph in R (I just added the lines part)

#fit a Cox proportional hazards model and plot the
#predicted survival for a 60 year old
fit <- coxph(Surv(futime, fustat) ~ age, data = ovarian)
plot(survfit(fit, newdata=data.frame(age=60)),
xscale=365.25, xlab = "Years", ylab="Survival",conf.int=F)
#also plot the predicted survival for a 70 year old
lines(survfit(fit, newdata=data.frame(age=70)),
xscale=365.25, xlab = "Years", ylab="Survival")


You should keep in mind though that for the Proportional Hazards assumption to still hold for your prediction, the patient for which you predict should be from a group that is qualitatively the same as the one used to derive the coxph model you used for the prediction.

-