# Fluctuations in hazard function at high (x) values

Using a best-fit algorithm, i've obtained gamma-distribution parameter MLEs for my data (scale and shape). When evaluating the hazard function, calculated as the PDF divided by the reciprocal CDF, over large values of (x), the function begins to fluctuate and break down:

What is causing this to occur?

Secondly: Is there a way to estimate the maximal (y) value of the hazard function curve prior to this area of fluctuation without actually calculating the curve in full? i.e. here, estimating a value of ~2.4.

This kind of wild fluctuation arises from floating point rounding errors in the calculations.

The hazard function of a $\Gamma(a,1)$ distribution, with shape parameter $a$ and scale parameter $1$, equals

$$H(x; a) = \frac{x^{a-1}\exp(-x)}{\int_x^\infty t^{a-1} \exp(-t) dt }.$$

The maximum requested in the question is also the limiting value as $x\to\infty$, because the hazard function in this case is increasing.

Both the numerator and denominator are differentiable functions approaching zero as $x$ increases, so L'Hopital's Rule applies, telling us the limiting value of the ratio is the limit of the ratio of the derivatives:

$$\lim_{x\to\infty} H(x;a) = \lim_{x\to\infty}\frac{\exp(-x)\left((a-1)x^{a-2} - x^{a-1}\right)}{-x^{a-1}\exp(-x)} = \lim_{x\to\infty} 1 - \frac{a-1}{x} = 1.$$

When the scale is changed to $b$, the PDF must be divided by $b$ to compensate (to keep the total area equal to unity), implying the limiting value of the hazard function for a Gamma distribution with scale parameter $b$ is $1/b$.

A better way to compute this hazard function for large $x$ is to use the first few terms of its Taylor expansion around $x=\infty$:

$$H(x;a,b) \approx x^{-a} \left(\frac{(a-1) \left(\frac{1}{b}\right)^{-a-1}}{x^2}-\frac{(a-1) \left(\frac{1}{b}\right)^{-a}}{x}+\left(\frac{1}{b}\right)^{1-a}\right ) \left(\frac{x}{b}\right)^a.$$

This will be extremely accurate well before $x$ gets so large that the brute-force computation of the ratio breaks down. It is, of course, not accurate for small $x$.

• Very informative and helpful answer +1. Commented Aug 24, 2015 at 18:11