[Rd] behavior of r* and d* functions at boundaries (PR#1218)

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 18 Dec 2001 14:51:04 +0100


>>>>> "Ben" == Ben Bolker <bolker@zoo.ufl.edu> writes:

    Ben>   (Sent this to r-help back in October, got no
    Ben> comments, forgot to re-submit it as a bug report.)

    Ben> There are a few inconsistencies, at least, in some of
    Ben> the functions that generate random deviates from
    Ben> particular distributions (I think they're bugs because
    Ben> they're inconvenient, but maybe someone can make an
    Ben> argument for the current behavior). If people think
    Ben> these are really bugs I can submit them, together or
    Ben> separately.

    Ben> 1. rlnorm(n,mean,sd) gives NaN for sd=0, rather than
    Ben> always returning the mean. This is inconsistent with
    Ben> rnorm(), which returns the mean.

    Ben> 2. rnbinom(n,prob,size) gives NaN when prob=1; always
    Ben> returning 0 would be reasonable, and consistent with
    Ben> the output of dnbinom(). [This is equivalent to
    Ben> rnbinom(n,mu=0,size) in the new parameterization.]

these two above are fixed for 1.4

    Ben> 3. rgamma(n,shape,scale) happily returns 0 when shape=0
    Ben> or scale=0. However, dgamma(x,shape=0) [and
    Ben> pgamma(x,shape=0)] gives NaN. This behavior is actually
    Ben> convenient for me, but I could make an argument for
    Ben> returning a warning in this case.

    Ben>   In general, I don't know what (e.g.)
    Ben> dnorm(m,mean=m,sd=0) should return: NaN (as at present)
    Ben> or Inf?

    Ben> I guess it depends how fussy you're being and how
    Ben> you're taking limits.

My approach would be to always return the limit if it's well
defined (as here).  
For any random variate X, when Var(X) = 0, r<dist>()  should
return E(X) (if that is defined) I think.  
This would mean that rgamma() is fine and dnorm() could be
improved.  
dgamma(0,shape=0) should give Inf as well and pgamma(0,shape=0) |-> 1.
The fact that pnorm(mu, mu, sd = 0) currently gives NaN instead
of 1 is a bug IMO.

Another line of reasoning could be that "shape=0" (or less
clearly "sd = 0") are not allowed (as per ?rgamma), and giving
NaN would reflect this.  I'm not share this view
but leave all this for after release.

    Ben>   The fixes seem straightforward.
(yes, at least for 1) and 2))

Thank you, Ben, for reporting these!

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._