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 and calculate the cumulative hazard function by H<--log(haz) 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. Any help would be greatly appreciated. Regards, j -- View this message in context: http://www.nabble.com/Plotting-Cumulative-Hazard-Functions-with-Strata-tp24121979p24121979.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2009-Jun-20 11:18 UTC
[R] Plotting Cumulative Hazard Functions with Strata
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.riskThat's not valid, but it's close. Try instead:> haz <- kmfit$n.event/kmfit$n.riskThe 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