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

Joshua Wiley jwiley.psych at gmail.com
Thu Mar 10 19:05:36 CET 2011


Hi Maja,

Values that are theoretically the same may not be exactly identical
when using floating point arithmetic.  Please read this FAQ page:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

If you need to test that they are "equal", you may add a tolerance
(say, for example, are they equal within 1e-8)

Cheers,

Josh

On Thu, Mar 10, 2011 at 7:18 AM, maiya <maja.zaloznik at gmail.com> wrote:
> Hi there!
> I'm not sure I can create a minimal example of my problem, so I'm linking to
> a minimal .RData file that has only two objects: obs and exp, each is a 6x9
> matrix.  http://dl.dropbox.com/u/10364753/test.RData link to dropbox file
> (I hope this is acceptable mailing list etiquette!)
>
> Here's what happens:
>> obs[1, 1]
> [1] 118
>> exp[1, 1]
> [1] 118
>> obs[1, 1]-exp[1, 1]
> [1] 2.842171e-14
>
> Problem is, both obs and exp should be identical. They are the result of a
> saturated loglinear model, and I've run the same code across about 400
> tables, all of which result in sum(obs-exp)=0, except for this one. I can't
> figure it out?
>
> Anyway, I need help understanding why 118 and 118 are not really the same. I
> appreciate some may be wary of downloading my .Rdata file (I'm on ubuntu if
> that's any consolation), but I don't know how else to ask this quesiton!
>
> Thanks!
>
> Maja Z.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/identical-values-not-so-identical-newbie-help-please-tp3346078p3346078.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list