[R] rgamma with negative shape and scale parameters works?
Martin Maechler
maechler at stat.math.ethz.ch
Thu Apr 20 17:37:06 CEST 2000
>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:
PD> Faheem Mitha <faheem at email.unc.edu> writes:
>> This is a possibly silly question, but the rgamma function takes the
>> shape and scale arguments and simulates gamma rvs corresponding to
>> those values, right? But the shape and scale parameters have to be
>> positive, right? However, rgamma quite happily returns to me values
>> for negative values of shape and scale, and in some cases returns
>> negative values eg.
>>
>> > rgamma(1, 1, -1)
>> [1] -1.011081
>> > rgamma(1, -1, -1)
>> [1] -1.710464
>> > rgamma(1, -1, 1)
>> [1] 2.058639
PD> Most likely, it is a bug(let). Calculating dgamma(rgamma(... with the
PD> same parameters give NaN.
Not so with Splus (5.1 Solaris); dgamma() there "works" as well
--- only with negative "scale" however; "shape" is required to be "> 0"...
In S+, it partially works (sometimes; I have seen dgamma() < 0 !) to use a
negative "scale" ("rate" in S-plus):
I found that R and S are quite incompatible for the gamma
distribution, we have "scale" where S has "rate", and
rate = 1/scale
It seems that one can work with a negative rate/"scale" parameter
("scale" then being even more a misnomer...)
and I vaguely remember something in the back of my mind
where someone even *requested* this ... any ring?
(anyone less lazy and care to look in Johnson & Kotz or ...) ?
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list