From murdoch at stats.uwo.ca  Mon Mar 13 00:48:23 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sun, 12 Mar 2006 18:48:23 -0500
Subject: [Rd] Logic Error (PR#8677)
In-Reply-To: <20060312233911.22F1329D71@slim.kubism.ku.dk>
References: <20060312233911.22F1329D71@slim.kubism.ku.dk>
Message-ID: <4414B347.4030700@stats.uwo.ca>

On 3/12/2006 6:39 PM, mkdavis at math.ucalgary.ca wrote:
> Full_Name: Matthew Davis
> Version: 2.2.0
> OS: OS X (10.4.5)
> Submission from: (NULL) (209.107.120.195)
> 
> 
> the mean of my sample x is 0.2, and when I check mean(x)<=0.2 I get a TRUE
> value, when I check mean(x)<=(1-0.8) I get a FALSE value.  (x <- c(0, 1, 0, 0,
> 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0))

Why make this so complicated?  The natural conclusion from that is that 
0.2 is not equal to (1-0.8), and indeed:

 > (1-0.8) == 0.2
[1] FALSE

The problem is that neither 0.2 nor 0.8 can be represented exactly, so 
when you do calculations using them you are doing approximations.  The 
approximation involving your mean is different than the one involving 
(1-0.8).  This is an FAQ,

7.31 Why doesn't R think these numbers are equal?

This is not a bug.

Duncan Murdoch



[Rd] Logic Error (PR#8677)
Duncan Murdoch