Skip to content

RFC: d/p/q/rgamma

4 messages · Brian Ripley, Kurt Hornik, Thomas Lumley

#
dgamma and friends in S are documented as

dgamma(x, shape, rate=1)
pgamma(q, shape, rate=1)
qgamma(p, shape, rate=1)
rgamma(n, shape, rate=1)


whereas R has

dgamma(x, shape, scale=1, log = FALSE)
pgamma(q, shape, scale=1, lower.tail = TRUE, log.p = FALSE)
qgamma(p, shape, scale=1, lower.tail = TRUE, log.p = FALSE)
rgamma(n, shape, scale=1)

Note the use of rate vs scale.  Indeed, as both S and R use `rate' for
exponential this seems somewhat strange, and the only such inconsistency I
can find.

I propose that we add a `rate' argument to d/p/q/rgamma as an alternative
to `scale', which is easily done.   The question is where?

I think we have a trap here for most users, who will happily copy

dgamma(x, 17, 0.3)

from their S-PLUS example sheet, and get the wrong answer. My preference
would be to have

dgamma(x, shape, rate, scale=1, log = FALSE)

etc.  That would break existing R code using positional matching.
Question: is there any?

The only really safe alternative is add `rate' as the last parameter.
#
One could find out by unpackaging all CRAN packages and grepping for
usages of *gamma in the code.

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 6 Sep 2001, Kurt Hornik wrote:

            
Only in public code, not for example in people's lecture notes.

There's only one use in the packages we have installed (almost all), of
rgamma(n, r) in sm.  Had that used a third arg, I am sure I would never
have spotted it when porting.

BTW, I think the cleanest approach is

dgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE)

Brian
#
On Thu, 6 Sep 2001, Prof Brian Ripley wrote:

            
Yes, I think this is better

	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._