6
$\begingroup$

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.
$\endgroup$
4
  • $\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$ Commented Oct 15, 2018 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$ Commented Oct 15, 2018 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$ Commented Oct 15, 2018 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$ Commented Oct 15, 2018 at 19:34

2 Answers 2

8
$\begingroup$

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.

$\endgroup$
1
  • 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$ Commented Oct 15, 2018 at 16:28
2
$\begingroup$

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.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.