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.
Nordlund, Dan (DSHS/RDA)
2011-Mar-10 18:02 UTC
[R] identical values not so identical? newbie help please!
> -----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 7:19 AM > To: r-help at r-project.org > Subject: [R] identical values not so identical? newbie help please! > > 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. >See the R FAQ 7.31 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
Joshua Wiley
2011-Mar-10 18:05 UTC
[R] identical values not so identical? newbie help please!
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/