Re: [R] Hazard function or cumulative Hazard function in R

From: Göran Broström <gb_at_stat.umu.se>
Date: Wed 23 Mar 2005 - 01:44:31 EST

On Mon, Mar 21, 2005 at 04:04:50PM -0800, Spencer Graves wrote:
> 1. Have you looked at the "survival" package? Venables and Ripley
> (2002) Modern Applied Statistics with S (Springer) has a chapter on
> survival analysis that I found quite helpful. The "survival" package
> includes hazard plots, which are discussed in Venables and Ripley.

It seems more likely that Yassir wants to calculate theoretical hazard and cumulative hazards functions (as he knows how to "program it") for a given distribution, and then the answer is 'No there are no such functions'.

But, taking the Weibull distribution as an example, they are easily calculated using 'pweibull' and 'dweibull':

  1. From ?pweibull:

   The cumulative hazard H(t) = - log(1 - F(t)) is    '-pweibull(t, a, b, lower = FALSE, log = TRUE)'

2. The hazard function hweibull itself can be given by    

   hweibull <- function(t, shape, scale = 1) dweibull(t, shape, scale) /    pweibull(t, shape, scale, lower.tail = FALSE)

'hweibull', as defined here, is not the numerically optimal solution, but the formula has the advantage of working for any distribution.

> 2. If that is not adequate, have you tried an "R Site Search"
> (from www.r-project.org -> search)?
>
> hope this helps. spencer graves
>
> yassir rabhi wrote:
>
> > Hi,
> >I'm student from canada, and i'work in survival
> >analysis.I want to know if there is a hazard function
> >or cumulative hazard function in R or not, i know how
> >to program it, but it is easy to use it if they exists
> >in R.
> >Thanks.
> > Yassir
> >
> >______________________________________________
> >R-help@stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> >http://www.R-project.org/posting-guide.html
> >
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

-- 
 Göran Broström                    tel: +46 90 786 5223
 Department of Statistics          fax: +46 90 786 6614
 Umeå University                   http://www.stat.umu.se/egna/gb/
 SE-90187 Umeå, Sweden             e-mail: gb@stat.umu.se

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Mar 23 01:52:20 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:52 EST