# Re: [R] The gamma function and infinity

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue 06 Dec 2005 - 03:51:56 EST

>>>>> "PD" == Peter Dalgaard <p.dalgaard@biostat.ku.dk> >>>>> on 05 Dec 2005 17:14:47 +0100 writes:

PD> Florent Bresson <f_bresson@yahoo.fr> writes:
>> I have to calculate some formula like:
>>
>> gamma(x)/(gamma(x+y)
>>
>> and I observed that for relatively big values of x, R
>> returns infinity and so cannot compute the formula. Is it
>> possible to force R to give the real value of gamma(x)

PD> No, it is overflowing the floating point representation.

PD> How about using lgamma? That's basically what it is for.

Indeed. Note however that in the case of really large x and moderate y, even in the lgamma() formulation, there will be loss of precision due to cancellation. There are "famous" asymptotic (non-convergent series) formulae, you can use in that case, the most simple one being

Gamma(a + y) / Gamma(a) ~ a^y (for a -> Inf, y << a) and hence

log(Gamma(a + y)) - log(Gamma(a)) ~ y*ln(a)

```--
Martin Maechler, ETH Zurich

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help