Liviu Andronic
2011-Nov-24 12:44 UTC
[R] understanding all.equal() output: "Mean relative difference"
Dear all How should one parse all.equal() output? I'm specifically referring to the 'mean relative difference' messages. For example,> all.equal(pi, 355/113)[1] "Mean relative difference: 8.491368e-08" But I'm not sure how to understand these messages. When they're close to 0 (or 1xe-16), then it's intuitive. But when they're big,> all.equal(1, 4)[1] "Mean relative difference: 3"> all.equal(2, 4)[1] "Mean relative difference: 1"> all.equal(3, 4)[1] "Mean relative difference: 0.3333333" the messages start making much less sense. I tried Wikipedia [1], but the description is cryptic, as is the help page. Also, Fox and Weisberg (2011) don't explain this particular message. Regards Liviu [1] http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
Duncan Murdoch
2011-Nov-24 13:20 UTC
[R] understanding all.equal() output: "Mean relative difference"
On 11-11-24 7:44 AM, Liviu Andronic wrote:> Dear all > How should one parse all.equal() output? I'm specifically referring to > the 'mean relative difference' messages. For example, >> all.equal(pi, 355/113) > [1] "Mean relative difference: 8.491368e-08" > > But I'm not sure how to understand these messages. When they're close > to 0 (or 1xe-16), then it's intuitive. But when they're big, >> all.equal(1, 4) > [1] "Mean relative difference: 3" >> all.equal(2, 4) > [1] "Mean relative difference: 1" >> all.equal(3, 4) > [1] "Mean relative difference: 0.3333333"In the first case, the difference is 3, and 3/1 = 3. In the second case, the difference is 2, and 2/2 = 1. In the third case, the difference is 1, and 1/3 = 0.3333333. It's the difference relative to the first number. It says "mean" because the two arguments could both be vectors, in which case it would calculate a vector of differences first. You'll have to look at all.equal.numeric to see the exact way those are combined, but its something like mean(abs(x-y))/mean(abs(x)) Duncan Murdoch> > the messages start making much less sense. I tried Wikipedia [1], but > the description is cryptic, as is the help page. Also, Fox and > Weisberg (2011) don't explain this particular message. > > Regards > Liviu > > [1] http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference > >
S Ellison
2011-Nov-24 15:32 UTC
[R] understanding all.equal() output: "Mean relative difference"
The help page says that large differences are returned as relative difference. A look at the code shows that all.equal.numeric, the version used for a numeric first argument, uses the 'target', that is, the first parametter, as the scaling factor. Thus c(1,4) has a difference of 3, scaled by 1, giving 3 c(2,4) has a difference of 2, scaled by 2, giving 1 ... and so on. The other potentially useful part of the help page is the bit right at the beginning than says "Don't use 'all.equal' directly in 'if' expressions-either use 'isTRUE(all.equal(....))' or 'identical' if appropriate." which usually avoids the need to parse the result at all.> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Liviu Andronic > Sent: 24 November 2011 12:45 > To: r-help at r-project.org Help > Subject: [R] understanding all.equal() output: "Mean relative > difference" > > Dear all > How should one parse all.equal() output? I'm specifically > referring to the 'mean relative difference' messages. For example, > > all.equal(pi, 355/113) > [1] "Mean relative difference: 8.491368e-08" > > But I'm not sure how to understand these messages. When > they're close to 0 (or 1xe-16), then it's intuitive. But when > they're big, > > all.equal(1, 4) > [1] "Mean relative difference: 3" > > all.equal(2, 4) > [1] "Mean relative difference: 1" > > all.equal(3, 4) > [1] "Mean relative difference: 0.3333333" > > the messages start making much less sense. I tried Wikipedia > [1], but the description is cryptic, as is the help page. > Also, Fox and Weisberg (2011) don't explain this particular message. > > Regards > Liviu > > [1] > http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference > > > -- > Do you know how to read? > http://www.alienetworks.com/srtest.cfm > http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader > Do you know how to write? > http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail > > ______________________________________________ > 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. > *******************************************************************This email and any attachments are confidential. Any use...{{dropped:8}}