lgammaAsymp {DPQ} | R Documentation |
Compute an n-th order asymptotic approximation to log Gamma function,
using Bernoulli numbers Bern(k)
for k
in
1, …, 2n.
lgammaAsymp(x, n)
x |
numeric vector |
n |
integer specifying the approximation order. |
numeric vector with the same attributes (length()
etc) as
x
, containing approximate lgamma(x)
values.
Martin Maechler
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (x, n) { s <- (x - 1/2) * log(x) - x + log(2 * pi)/2 if (n >= 1) { Ix2 <- 1/(x * x) k <- 1:n Bern(2 * n) Bf <- rev(.bernoulliEnv$.Bern[k]/(2 * k * (2 * k - 1))) bsum <- Bf[1] for (i in k[-1]) bsum <- Bf[i] + bsum * Ix2 s + bsum/x } else s }