Logic Error (PR#8677)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Logic Error (PR#8677)

mkdavis
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))

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Logic Error (PR#8677)

Jan de Leeuw
 > 0.2==(1-0.8)
[1] FALSE

On Mar 12, 2006, at 15:39 , [hidden email] 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))
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

===
Jan de Leeuw; Distinguished Professor and Chair, UCLA Department of  
Statistics;
Editor: Journal of Multivariate Analysis, Journal of Statistical  
Software
US mail: 8125 Math Sciences Bldg, Box 951554, Los Angeles, CA 90095-1554
phone (310)-825-9550;  fax (310)-206-5658;  email: [hidden email]
.mac: jdeleeuw ++++++  aim: deleeuwjan ++++++ skype: j_deleeuw
homepages: http://gifi.stat.ucla.edu ++++++ http://www.cuddyvalley.org
   
------------------------------------------------------------------------
-------------------------
           No matter where you go, there you are. --- Buckaroo Banzai
                    http://gifi.stat.ucla.edu/sounds/nomatter.au

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Logic Error (PR#8677)

Duncan Murdoch
In reply to this post by mkdavis
On 3/12/2006 6:39 PM, [hidden email] 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Logic Error (PR#8677)

Janusz Kawczak
However, mean(x)==0.2 returns TRUE
Also, mean(x)>=(1-0.8) returns TRUE ;)

So, it's not just the approximation calculus.

On Sun, 12 Mar 2006, Duncan Murdoch wrote:

> On 3/12/2006 6:39 PM, [hidden email] 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Logic Error (PR#8677)

Duncan Murdoch
On 3/12/2006 7:08 PM, Janusz Kawczak wrote:
> However, mean(x)==0.2 returns TRUE
> Also, mean(x)>=(1-0.8) returns TRUE ;)
>
> So, it's not just the approximation calculus.

I don't get your point.  On my computer,

 > 1-0.8 < 0.2
[1] TRUE

which is consistent with what I wrote below and what you write above.
mean(x) comes out to the same approximation as the constant 0.2 uses,
but 1-0.8 doesn't, it comes out smaller.

Duncan Murdoch

>
> On Sun, 12 Mar 2006, Duncan Murdoch wrote:
>
>> On 3/12/2006 6:39 PM, [hidden email] 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
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel