From ripley at stats.ox.ac.uk  Tue Nov  8 08:44:41 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 8 Nov 2005 07:44:41 +0000 (GMT)
Subject: [Rd] dgamma error condition?
In-Reply-To: <436B78AF.9010602@zoo.ufl.edu>
References: <436B78AF.9010602@zoo.ufl.edu>
Message-ID: <Pine.LNX.4.61.0511080736390.14096@gannet.stats>

On Fri, 4 Nov 2005, Ben Bolker wrote:

>
>   There's an apparent inconsistency between the
> behavior of d(pqr)gamma and other distribution
> functions for "bad" parameter values.  Specifically,
> most distributions give NaN and a warning for bad
> parameters (e.g. probabilities <0 or >1).  In contrast,
> d(pqr)gamma actually gives an error and stops when shape<0.
> I don't see why it has to be this way -- the internal
> C code is set up to detect shape<0 (or scale<0) and
> return NaN and a warning, and none of the other
> distribution functions in that bit of the code have
> similar behavior.
>
>   It would seem more consistent (and would be more
> convenient for me -- the error-instead-of-warning
> is making me have to jump through additional hoops)
> if dgamma just returned NaN and a warning.
>
>    Any thoughts?

No one has come up with any, so let us remove the errors in R-devel.

Note that rgamma is not protected at C level: try rgamma(10, -2), or 
(worse) rgamma(10, -20)  after removing the stop() call.

-- 
Brian D. Ripley,                  ripley at 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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] dgamma error condition?
Prof Brian Ripley