[R] Plotting Cumulative Hazard Functions with Strata

David Winsemius dwinsemius at comcast.net
Sat Jun 20 13:18:52 CEST 2009


On Jun 20, 2009, at 12:23 AM, j0645073 wrote:

>
> Hello:
>
> So i've fit a hazard function to a set of data using
> kmfit<-survfit(Surv(int, event)~factor(cohort))
>
> this factor variable, "cohort" has four levels so naturally the strata
> variable has 4 values.
>
> I can use this data to estimate the hazard rate
> haz<-n.event/n.risk

That's not valid, but it's close. Try instead:

> haz <- kmfit$n.event/kmfit$n.risk

The problem will be to properly categorize the vectors in the survfit  
object with your covariate factor, "cohort". (Strata is a somewhat  
different term in the language of Cox models.)
>
> and calculate the cumulative hazard function by
> H<--log(haz)

Since that is not valid R syntax at all and you say you want  
cumulative, then why aren't you summing the hazards?

>
> Now, I would like to plot this cumulative hazard function by time and
> differentiate the curves by strata. For the life of me I cannot seem  
> to do
> it.
>
If you are being asked to do this from scratch and show your work for  
homework grading purposes, then by all means, carry on. If not, then  
you should be trying:

  plot(kmfit, fun="cumhaz")

> Any help would be greatly appreciated.
>
> Regards,
>
> j

> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list