From gregor.gorjanc at bfro.uni-lj.si  Wed Dec 28 12:25:31 2005
From: gregor.gorjanc at bfro.uni-lj.si (Gregor Gorjanc)
Date: Wed, 28 Dec 2005 12:25:31 +0100
Subject: [Rd] NaN in R distribution functions
Message-ID: <43B2762B.20403@bfro.uni-lj.si>

Dear R developers,

I noticed that core R distribution functions return NaN, when parameter 
values are out of parameter space. I have looked in source code and 
found that warnings and return of NaN are done internally in C code. For 
dgamma.c the line 49 is:

     if (shape <= 0 || scale <= 0) ML_ERR_return_NAN;

OK. How should this be implemented if distribution functions are written 
directly in R? I came up with this

     if (any(shape <= 0)) {
         warning("shape must be positive")
         return(NaN)
     }

I think that it would be nice that returning NaN for undefined parameter 
values in distribution functions would also be documented in Writing R 
Extension.

-- 
Lep pozdrav / With regards,
     Gregor Gorjanc

----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si 

SI-1230 Domzale             tel: +386 (0)1 72 17 861
Slovenia, Europe            fax: +386 (0)1 72 17 888 

----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
  you have no certainty until you try." Sophocles ~ 450 B.C.



[Rd] NaN in R distribution functions
Gregor Gorjanc