# Re: [R] identical values not so identical? newbie help please!

From: Petr Savicky <savicky_at_praha1.ff.cuni.cz>
Date: Thu, 10 Mar 2011 21:01:38 +0100

On Thu, Mar 10, 2011 at 10:34:21AM -0800, maiya wrote:
> Thanks Josh and Dan!
>
> I did figure it had something to do with the machine epsilon...
>
> But so what do I do now? I'm calculating the total absolute error over
> thousands of tables e.g.:
> tae<-sum(abs(obs-exp))
> Is there any easy way to I keep these ignorable errors from showing up?
>
> And furthermore, why does this happen only sometimes? The two (2D) tables I
> attached are actually just one 'layer' in a 3D table. And only 2 out of
> about 400 layers had this happen, all the other ones are identical -
> perfectly!

Hi.

Two numbers cannot differ by an amount less than machine epsilon. If the difference of two numbers is smaller, then they are exactly equal. So, if a computation has very low error, then it shows up only sometimes. A simple example is

i <- 6:55
i/100*100 - i

```   [1]  0.000000e+00  8.881784e-16  0.000000e+00  0.000000e+00  0.000000e+00
[6]  0.000000e+00  0.000000e+00  0.000000e+00  1.776357e-15  0.000000e+00
[11]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[16]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[21]  0.000000e+00  0.000000e+00  3.552714e-15 -3.552714e-15  0.000000e+00
[26]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[31]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[36]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[41]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[46]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  7.105427e-15

```

The "machine epsilon" is a relative quantity depending on the number, so the errors here are different from what you observed. The numbers in your tables "obs" and "exp" differ by 1 or 2 units in the order of the least significant bit. This is hard to avoid unless you can work only with integers.

Hope this helps.

Petr Savicky.

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 10 Mar 2011 - 20:03:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Mar 2011 - 22:10:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.