[R] Hazard curves

Terry Therneau therneau at mayo.edu
Tue Sep 30 15:47:32 CEST 2008

-- begin included message -----
I am looking at a continuous variable, age.  I am looking at time to
12-month remission and can calculate the HR and 95% confidence interval are
coxfita = coxph(Surv(rem.Remtime,rem.Rcens)~nearma$all.age,data=nearma)

However, because I am looking at age as a continuous variable I cannot draw
a Kaplan-Meier curve.  Instead I need to draw a plot of hazard against age.
How do I do this? I don't think
plot(nearma$all.age,coxfita$linear.predictors) is quite right.

Thank you for your help,


--- End included

 There is not a simple plot: hazard is a function of both time and age, so will 
be a 2-d surface.
  A common plan is to plot the predicted survival for a small set of ages.
  ageset <- c( 40, 55, 70)
  curves <- survfit(coxfita, newdata= data.frame(all.age = ageset))
  plot(curves, col=1:3)
This will give a plot with 3 predicted survival curves, for ages 40, 55 and 70.

  The plot of hazard vs age at any particular time point is not very 
interesting: it will be h(t, age) = k exp(coefficient * age).  This does not 
reflect the data in any way, just your decision that age would be a linear term 
in the model.  If you want to explore the effect of age, then fit the 
generalized additive Cox model
  	addfit <- coxph(Surv(rem.Remtime,rem.Rcens)~ pspline(all.age), nearma)
  	temp <- predict(addfit, type='terms', se=TRUE)
  	matplot(nearma$all.age, exp(cbind(temp$fit,
  	                                  temp$fit - 2* temp$se.fit,
  	                                  temp$fit + 2* temp$se.fit)),
  	             log='y', xlab="Age", ylab="Estimated Relative Risk")
  I suspect this is what you actually want.
  	Terry Therneau

More information about the R-help mailing list