[Rd] Accuracy (PR#13867)
savicky at cs.cas.cz
Tue Aug 4 20:27:44 CEST 2009
On Tue, Aug 04, 2009 at 04:25:09PM +0200, luethman at student.ethz.ch wrote:
> I created the following vectors:
> As these are probabilities, I calculated the remainder as
> There the values which ought to be 0.1 were lateron not recognised by p_3==0.1,
> but only if I used p_3 <= 0.1.
> The full calculation is actually bigger but the core issue remains: I used
> values input by hand, built a difference and it was wrong.
> I know that exactly the value 0.1 is one that can not be represented using
> binary rep. Maybe that's it, maybe not.
Yes, this is the problem. In this case, one can obtain a correct
result using round()
p1 <- c(0.2,0.2,0.2,0.2,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.1,
p2 <- c(0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.4,
p3 <- 1 - p1 - p2
round(p3, 2) == 0.1
#  FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE
#  TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE
#  TRUE FALSE FALSE TRUE
More information about the R-devel