From ripley@stats.ox.ac.uk  Thu Sep  6 10:21:58 2001
From: ripley@stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu, 6 Sep 2001 10:21:58 +0100 (BST)
Subject: [Rd] RFC: d/p/q/rgamma
In-Reply-To: <15255.12463.584218.976655@mithrandir.hornik.net>
Message-ID: <Pine.GSO.4.31.0109061013290.4287-100000@toucan.stats>

On Thu, 6 Sep 2001, Kurt Hornik wrote:

> >>>>> Prof Brian Ripley writes:
>
> > 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?
>
> One could find out by unpackaging all CRAN packages and grepping for
> usages of *gamma in the code.

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

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] RFC: d/p/q/rgamma
Prof Brian Ripley