Learn R Programming

DPQ (version 0.5-9)

gammaVer: Gamma Function Versions

Description

Provide different variants or versions of computing the Gamma (\(\Gamma\)) function.

Usage


gammaVer(x, version, stirlerrV = c("R3", "R4..1", "R4.4_0"), traceLev = 0L)

Value

numeric vector as x

Arguments

x

numeric vector of absissa value for the Gamma function.

version

integer in {1,2,..,5} specifying which variant is desired.

stirlerrV

a string, specifying the stirlerr() version/variant to use.

traceLev

non-negative integer indicating the amount of diagnostic “tracing” output to the console during computation.

Author

Martin Maechler

Details

All of these are good algorithms to compute \(\Gamma(x)\) (for real \(x\)), and indeed correspond to the versions R's implementation of gamma(x) over time. More specifically, the current version numbers correspond to

  1. . TODO

  2. .

  3. .

  4. Used in R from ... up to versions 4.3.z

  5. Possibly to be used in R 4.4.z and newer.

The stirlerrV must be a string specifying the version of stirlerr() to be used:

"R3":

the historical version, used in all R version up to R 4.3.z.

"R4..1":

only started using lgamma1p(n) instead of lgamma(n + 1.) in stirlerr(n) for \(n \le 15\), in the direct formula.

"R4.4_0":

uses 10 cutoffs instead 4, and these are larger to gain accuracy.

%% \item{"...."}{}

References

.... TODO ....

See Also

gamma(), R's own Gamma function.

Examples

Run this code
xx <- seq(-4, 10, by=1/2)
gx <- sapply(1:5, gammaVer, x=xx)
gamx <- gamma(xx)
cbind(xx, gx, gamma=gamx)
apply(gx, 2, all.equal, target=gamx, tol = 0) # typically: {T,T,T,T, 1.357e-16}
stopifnot( apply(gx, 2, all.equal, target = gamx, tol = 1e-14))
                                                 # even 2e-16 (Lnx, 64b, R 4.2.1)

Run the code above in your browser using DataLab