Skip to content
Prev 66334 / 398503 Next

Hazard function or cumulative Hazard function in R

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.