From iuc@r @ending from fedor@project@org  Tue Dec  4 11:27:36 2018
From: iuc@r @ending from fedor@project@org (=?UTF-8?Q?I=C3=B1aki_Ucar?=)
Date: Tue, 4 Dec 2018 11:27:36 +0100
Subject: [Rd] Bug report: Function ppois(0:20,
 lambda=0.9) does not generate a non-decreasing result.
In-Reply-To: <f49f51f.a07fd.16774649817.Coremail.qweytr1@mail.ustc.edu.cn>
References: <f49f51f.a07fd.16774649817.Coremail.qweytr1@mail.ustc.edu.cn>
Message-ID: <CALEXWq1WFLzQBgm8oF1myry25DZEyEA_jT3kFEnLYP55-06QKg@mail.gmail.com>

On Tue, 4 Dec 2018 at 11:12, <qweytr1 at mail.ustc.edu.cn> wrote:
>
> function ppois is a function calculate the CDF of Poisson distribution, it should generate a non-decreasing result, but what I got is:
>
> > any(diff(ppois(0:19,lambda=0.9))<0)
> [1] TRUE
>
> Actually,
>
> > ppois(19,lambda=0.9)<ppois(18,lambda=0.9)
> [1] TRUE
>
> Which could not be TRUE.

This is just another manifestation of

0.1 * 3 > 0.3
#> [1] TRUE

This discussion returns to this list from time to time. TLDR; this is
not an R issue, but an unavoidable floating point issue. Solution:
work with log-probabilities instead.

any(diff(ppois(0:40, lambda=0.9, log.p=TRUE))<0)
#> [1] FALSE

I?aki



[Rd] Bug report: Function ppois(0:20, lambda=0.9) does not generate a non-decreasing result.
=?UTF-8?Q?I=C3=B1aki_Ucar?=