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.
  • 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... – jbowman Oct 15 at 16:20
  • 1
    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? – whuber Oct 15 at 17:11
  • 1
    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. – user158565 Oct 15 at 18:17
  • @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. – Cliff AB Oct 15 at 19:34
up vote 7 down vote accepted

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
    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. – Hazardous Oct 15 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

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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