I have the following Cox PH model:

(Time, Event) ~ X + Y + Z

I would like to get the predicted hazard rates (i am talking about hazard rates NOT hazard ratios) given specific values of X, Y, Z. I know the muhaz R package can calculate the observed hazard rates, but I am interested in the predicted model.

Is there a way to do this in R?

  • 2
    $\begingroup$ It seems that your "equation" models a binary outcome. Now, Cox's PH model deals with survival data and what lies it the left-hand side should be an hazard rate... I think you should clarify... $\endgroup$
    – ocram
    Commented Mar 27, 2012 at 5:23
  • 2
    $\begingroup$ The Cox model does not estimate the baseline hazard function (usually indicated as $\lambda_0(t)$). To estimate the incidence rate from a model, you should use a parametric survival model instead. $\endgroup$
    – boscovich
    Commented Mar 27, 2012 at 7:53
  • 1
    $\begingroup$ There's some ambiguity in your question. The hazard function is a probability, not a rate. Is it the hazard function you want, or something else? $\endgroup$
    – Fomite
    Commented Mar 27, 2012 at 17:35

2 Answers 2


The function in the R survival package to get the baseline hazard rate is basehaz.

Then you need to multiply it for the various $e^{\beta}$ to get the specific hazard rate given the coefficients you have found.

A simple example may help:

library(survival) #survival analysis
library(eha) #used for data 
data(oldmort) #create the data

# Create surv data set
mort <- Surv(time=oldmort$enter,time2=oldmort$exit,event=oldmort$event)

reg_fit <- coxph(formula=mort~oldmort$sex)

# Now get baseline curve
baseline <- basehaz(reg_fit)

# Draw baseline hazard (that's male)
plot(baseline$time, baseline$hazard, type='l',main="Hazard rates") 

# Draw female hazard
lines(baseline$time, exp(-0.1929)*baseline$hazard, col="blue") 

the $\exp(-0.1929)=0.8245$ is copied and pasted from the summary results of cox regression, summary(reg_fit), implying that the females in the data have hazard rates $18\%$ lower than the males.


The function basehaz (from the previous answer) provides the cumulative hazard, not the hazard function (the rate). I believe that question was about the hazard function. Estimating the hazard function would require specification of the type of smoothing (like in density estimation). The Muhaz R package can do this for one sample data. I am not aware of a function that can do this for the baseline hazard in the Cox model. I also need this. I think I will need to smooth the cumulative hazard on my own.


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.