dgamma.R {DPQ}R Documentation

Gamma Density Function Alternatives

Description

dgamma.R() is aimed to be an R level “clone” of R's C level implementation dgamma (from package stats).

Usage

dgamma.R(x, shape, scale = 1, log)

Arguments

x

non-negative numeric vector.

shape

non-negative shape parameter of the Gamma distribution.

scale

positive scale parameter; note we do not see the need to have a rate parameter as the standard R function.

log

logical indicating if the result is desired on the log scale.

Value

numeric vector of the same length as x (which may have to be thought of recycled along shape and/or scale.

Author(s)

Martin Maechler

See Also

(As R's C code) this depends crucially on the “workhorse” function dpois_raw().

Examples


## TODO: ... regular case .. use all.equal() ...


## From R's  <R>/tests/d-p-q-r-tst-2.R -- replacing dgamma() w/ dgamma.R()
## PR#17577 - dgamma(x, shape)  for shape < 1 (=> +Inf at x=0) and very small x
stopifnot(exprs = {
    all.equal(dgamma.R(2^-1027, shape = .99 , log=TRUE), 7.1127667376, tol=1e-10)
    all.equal(dgamma.R(2^-1031, shape = 1e-2, log=TRUE), 702.8889158,  tol=1e-10)
    all.equal(dgamma.R(2^-1048, shape = 1e-7, log=TRUE), 710.30007699, tol=1e-10)
    all.equal(dgamma.R(2^-1048, shape = 1e-7, scale = 1e-315, log=TRUE),
              709.96858768, tol=1e-10)
})
## R's dgamma() gave all Inf in R <= 3.6.1 [and still there in 32-bit Windows !]

[Package DPQ version 0.5-8 Index]