Error in ppois function (PR#161)
On Fri, 9 Apr 1999 mh.smith@auckland.ac.nz wrote:
Full_Name: Murray H Smith Version: 0.63.3 OS: Windows NT Submission from: (NULL) (130.216.5.57) The ppois function is displaced by -0.5. Try:
ppois(-0.5,1)
[1] 0.3678794
ppois(-0.51,1)
[1] 0
ppois(0,1)
[1] 0.3678794
The problem is in
?ppois
The Poisson Distribution
dpois(x, lambda)
ppois(q, lambda)
qpois(p, lambda)
rpois(n, lambda)
Arguments:
x: vector of (positive) quantiles.
p: vector of probabilities.
n: number of random values to return.
lambda: vector of positive means.
where q is undefined! It should only be defined for integers. Similarly, x
should only be integers.
It seems better to make ppois defined as the CDF for all q. The code had
x = floor(x + 0.5);
and that should be something like floor(x + 1e-7).
I've fixed this for 0.64.1, and dpois now warns on non-integer x and,
correctly, gives 0. (Yes, I know S does not warn, but that is taking
silence too far I think.)
and
par(mfrow=c(2,1)) x<-seq(-1,5,0.01) plot(x,ppois(x,1),type="s",ylab="F(x)",main="Poisson CDF?") plot(x,pbinom(x,100,0.01),type="s",ylab="F(x)",main="Binomial CDF")
Thank you for the nice example, now on the help page. You did not try pnbinom, which is much more wrong:
pnbinom(1, 3, 0.5)
[1] 0.3125
pnbinom(1.1, 3, 0.5)
[1] 0.3320067
pnbinom(1.5, 3, 0.5)
[1] 0.4089029
Brian D. Ripley, ripley@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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._