[R] rgamma with negative shape and scale parameters works?

Setzer.Woodrow@epamail.epa.gov Setzer.Woodrow at epamail.epa.gov
Thu Apr 20 19:52:43 CEST 2000



Patil, Boswell, and Ratnaparkhi (dictionary and Classified bibliography of
Statistical Distributions in Scientific Work, Volume 2: Continuous Univariate
Models, International Co-operative Publishing House, Fairland, MD. 1984)
parametrize the gamma distribution as does R and they constrain both shape and
scale to be positive.

The entry in the Encyclopedia of Statistical Sciences for the Gamma Distribution
(by Lee Bain) uses the same parametrization, and also constrain shape and scale
to be positive.

(Sorry, someone made off with volume 1 of our Johnson and Kotz, "Continuous
Univariate Distributions").

R. Woodrow Setzer, Jr.                                                    Phone:
(919) 541-0128
Biostatistics and
Fax:  (919) 541-4002
Research Support Staff
NHEERL MD-55; US EPA; RTP, NC 27711


|--------+-------------------------->
|        |          maechler at stat.ma|
|        |          th.ethz.ch      |
|        |                          |
|        |          04/20/2000 11:37|
|        |          AM              |
|        |          Please respond  |
|        |          to maechler     |
|        |                          |
|--------+-------------------------->
  >----------------------------------------------------------|
  |                                                          |
  |       To:     r-help at stat.math.ethz.ch                   |
  |       cc:     faheem at email.unc.edu                       |
  |       Subject:     Re: [R] rgamma with negative shape and|
  |       scale parameters works?                            |
  >----------------------------------------------------------|






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



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