I need to evaluate a hazard function $h(t;\theta) = \dfrac{f(t;\theta)}{1-F(t;\theta)}$, where $f$ and $F$ are a pdf and a cdf, respectively, at many values of $t$ (and for several values of the parameter $\theta$). In some cases, when I evaluate $F(t;\theta)$, it returns the value $1$ for some values of $t$, making $h$ infinite.

For example, in R pweibull(100,1,1) returns 1.

Is there any trick to avoid this problem?

  • I wasn't sure if I should ask this question on stackoverflow instead, but since the question is related to a function that is widely used in statistics, I thought crossvalidated was a better place as some people may know of a "classical" solution.
  • $\begingroup$ Why do you care about the hazard rate out in the tail where the probability of the lifetime lasting that long is on the order of $10^{-15}$? You'll never see a lifetime that long anyway, assuming of course that the model is correct... $\endgroup$ – jbowman Oct 15 '18 at 16:20
  • 1
    $\begingroup$ There are myriad possible solutions, depending on $F$ as well as the capabilities of your software. One generic method is that when $f$ is differentiable in $t,$ you could use L'Hopital's Rule. Another is to use an asymptotic expansion of $F$ around $t=\infty,$ if that exists. Do you have a specific form of $F$ in mind? $\endgroup$ – whuber Oct 15 '18 at 17:11
  • 1
    $\begingroup$ For the parametric distribution, you can calculate the hazard from the hazard function directly, instead of going through CDF and PDF. For example, the hazard function is $h(x)=γx^{(γ−1)}$ for standard Weibull distribution. $\endgroup$ – user158565 Oct 15 '18 at 18:17
  • $\begingroup$ @jbowman: these calculations can be required in something like a proportional hazards model: a given time may be in the 99.999'th percentile of the baseline distribution, but 90th percentile conditional on the covariates. Without taking advantage of methods like those mentioned by a_statistician (which aren't always available), you may need to first calculate the baseline hazard and then adjust it. $\endgroup$ – Cliff AB Oct 15 '18 at 19:34

If the matter is numerical stability, you could look at the log of the hazard function:

$$log(h(t; \theta)) = log(f(t;\theta)) - log(1-F(t;\theta))$$

You could use the log / log.p = TRUE flag in R for log values and the lower.tail flag for obtaining $log(1 - F(t;\theta))$ values:

dweibull(100,1,1, log = T) # -100
pweibull(100, 1, 1, log.p = TRUE, lower.tail = FALSE) # -100

Which gives you an estimate: $h(t;\theta) = exp(-100 + 100) = 1$

Edit: By the way, when you have a $Weibull(1, 1)$ distribution, I believe that this is an $Exponential(1)$, so it has a constant hazard function.

  • 1
    $\begingroup$ Thanks, the lower.tail = FALSE is a nice trick. Yeah, the Weibull(1,1) was just a silly example, but of course, I am using more interesting hazards. $\endgroup$ – Hazardous Oct 15 '18 at 16:28

For a survival curve based on a parametric distribution, often the hazard is an explicit function of the parameters. For example, this link provides several hazard functions for different distribtuons. So when we know the values of parameters and want to calculate the hazard, as asked in this question, the best way is to use the hazard function directly, instead of going through CDF and PDF.

For example, the hazard function is $h(x)=γx^{(γ−1)}$ for the standard Weibull distribution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.