R: Asymptotic Log Gamma Function

lgammaAsymp {DPQ} | R Documentation

## Asymptotic Log Gamma Function

### Description

Compute an n-th order asymptotic approximation to log Gamma function, using Bernoulli numbers `Bern(k)` for `k` in 1, …, 2n.

### Usage

    lgammaAsymp(x, n)

### Arguments

`x` | numeric vector
`n` | integer specifying the approximation order.

### Value

numeric vector with the same attributes (`length()` etc) as `x`, containing approximate `lgamma(x)` values.

### Author(s)

Martin Maechler

### See Also

`lgamma`.

### Examples

    ##---- 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
      }

[Package DPQ version 0.5-2 Index]