Skip to content

Hazard function or cumulative Hazard function in R

4 messages · yassir rabhi, Kjetil Halvorsen, Spencer Graves +1 more

#
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
#
yassir rabhi wrote:

            
library(survival)


-- 

Kjetil Halvorsen.

Peace is the most effective weapon of mass construction.
               --  Mahdi Elmandjra
#
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. 

      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:

            
#
On Mon, Mar 21, 2005 at 04:04:50PM -0800, Spencer Graves wrote:
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.