11

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?

David C.
  • 123
  • 7
nostock
  • 1,337
  • 4
  • 15
  • 22
  • 2
    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... – ocram Mar 27 '12 at 05:23
  • 2
    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. – boscovich Mar 27 '12 at 07:53
  • 1
    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? – Fomite Mar 27 '12 at 17:35

2 Answers2

18

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)
summary(reg_fit)

# 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.

russt
  • 3
  • 2
CarrKnight
  • 1,218
  • 9
  • 18
14

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.

David C.
  • 123
  • 7
user21413
  • 141
  • 1
  • 3