11
$\begingroup$

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?

$\endgroup$
  • 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 Mar 27 '12 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 Mar 27 '12 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 Mar 27 '12 at 17:35
16
$\begingroup$

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.

$\endgroup$
13
$\begingroup$

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.

$\endgroup$

Your Answer

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

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