[R] integrate lgamma from 0 to Inf

Andreas Wittmann andreas_wittmann at gmx.de
Wed Apr 22 09:28:09 CEST 2009


Dear R users,

i try to integrate lgamma from 0 to Inf. But here i get the message "roundoff error is detected in the extrapolation table", if i use 1.0e120 instead of Inf the computation works, but this is against the suggestion of integrates help information to use Inf explicitly. Using stirlings approximation doesnt bring the solution too.

## Stirlings approximation
lgammaApprox <- function(x)
{
  0.5*log(2*pi)+(x-(1/2))*log(x)-x
}

integrate(lgamma, lower = 0, upper = 1.0e120)
integrate(lgammaApprox, lower = 0, upper = 1.0e120)
> integrate(lgamma, lower = 0, upper = 1.0e120)
1.374051e+242 with absolute error < 3.2e+235
> integrate(lgammaApprox, lower = 0, upper = 1.0e120)
1.374051e+242 with absolute error < 3.2e+235

integrate(lgamma, lower = 0, upper = Inf)
integrate(lgammaApprox, lower = 0, upper = Inf)
> integrate(lgamma, lower = 0, upper = Inf)
Fehler in integrate(lgamma, lower = 0, upper = Inf) : 
  roundoff error is detected in the extrapolation table
> integrate(lgammaApprox, lower = 0, upper = Inf)
Fehler in integrate(lgammaApprox, lower = 0, upper = Inf) : 
  roundoff error is detected in the extrapolation table


Many thanks if you have any advice for me!

best regards

Andreas
--




More information about the R-help mailing list