[Rd] lambda==0 in dpois() (PR#459)

bolker@zoo.ufl.edu bolker@zoo.ufl.edu
Fri, 25 Feb 2000 20:27:13 +0100 (MET)


  The nice new log=TRUE option in dpois appears to mess up the
case where lambda=0 (I was trying to calculate the likelihood
of a saturated model).  Because the behavior is now always to
calculate the probability in terms of exp(log(prob)), there's
a test for lambda<=0 which really needs to be only lambda<0.

  dpois(0:5,0)

ought to give

 1 0 0 0 0 

but gives NaNs instead.

  Here's a patch to src/nmath/dpois.c that appears to work (although it could ? be more
elegant).


*** dpois.c.orig	Fri Feb 25 13:53:06 2000
--- dpois.c	Fri Feb 25 14:16:19 2000
***************
*** 35,41 ****
  	warning("non-integer x = %f", x);
  	return R_D__0;
      }
!     if(lambda <= 0.0) ML_ERR_return_NAN;
  
      if (x < 0)
  	return R_D__0;
--- 35,51 ----
  	warning("non-integer x = %f", x);
  	return R_D__0;
      }
!     if(lambda < 0.0) ML_ERR_return_NAN;
!     if(lambda==0.0) {
!        if (give_log) {
!           if (x==0) return 0.0;
!           else ML_ERR_return_NAN;
!        }
!        else {
!           if (x==0) return 1.0;
!           else return 0.0;
!        }
!     }
  
      if (x < 0)
  	return R_D__0;


--please do not edit the information below--

Version:
 platform = i686-unknown-linux
 arch = i686
 os = linux
 system = i686, linux
 status = 
 major = 0
 minor = 99.0
 year = 2000
 month = February
 day = 7
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base

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