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

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Mar 10 20:23:36 CET 2011


Maja,

Isn't modern technology wonderful?  With computers we are able to do calculations that we could never do by hand, and we get to complain about the results not being exact. :-)  

More comments below

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of maiya
> Sent: Thursday, March 10, 2011 10:34 AM
> To: r-help at r-project.org
> Subject: Re: [R] identical values not so identical? newbie help please!
> 
> 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?

No, there is no easy way.  

> 
> 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! And out of 2000 3D tables, about 60 of which should have no
> error, only 10 actually show an error of zero, and in the rest this
> same
> thing happens in a few layers.

It could be a function of the order in which calculations occur, or the fact that results of calculations can be represented exactly sometimes and not others.


> 
> OK, this is a bit messy for a real question. I mean I can just round
> down
> all the errors that are under 1e-8 or something, but I'd much rather
> this
> not happen in the first place?

The only way to prevent this is to use infinite precision calculations.  I don’t pretend to be an expert in numerical analysis, but is the accumulation of a small number of errors, each on the order of 10^-14, going to affect your absolute error appreciably?  (I know we all prefer exact.)

> 
> Thanks again to the two posters for bothering with me!
> 
> Maja.
> 

Maybe someone else will have more encouraging advice.  Good luck.

Dan
 
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204




More information about the R-help mailing list