[R] - round() strange behaviour
Mark Wardle
mark at wardle.org
Sun Aug 5 10:05:00 CEST 2007
I use round() to prepare numbers for display in Sweave documents.
While I had appreciated the "round to even" issue before, I had not
given it much thought when automatically writing my output
functions/scripts/Sexprs...
On 04/08/07, Ted Harding <ted.harding at nessie.mcc.ac.uk> wrote:
> On 04-Aug-07 21:57:28, John Logsdon wrote:
> > I must admit I had never realised this so thanks to Monica for
> > raising it.
> >
> > Round-to-even is used for statistical reasons and there is some
> > point as it obviously reduces bias. But why should the decision
> > be to round to the nearest even number? rounding to the nearest
> > odd number would be equally valid. (signif(x,0) is the same as
> > round(). )
>
> A fair point! But see below.
>
> > There is a debate and sometimes you need symmetric rounding.
> > Perhaps there should be an option in round that defaults to
> > round-to-even for compatibility but includes the various other
> > rounding approaches as seen for example in
> > http://en.wikipedia.org/wiki/Rounding
>
> As wikipedia says: "Round-to-even is used rather than round-to-odd
> as the latter rule would prevent rounding to a result of zero."
>
> And there's also stochastic rounding -- toss a penny. But you wouldn't
> get the same answer next time.
>
> And I can recall -- man years ago -- being in an environment where
> the practice was to round alternately up and down. (These were
> engineers).
>
> John's comparisons between FORTRAN, octave and (implicitly) R
> are interesting.
>
> As a general reflection: any method of rounding involves throwing
> away some of the information in the data, and this will have
> consequences. So the question is: what consequences are you
> happiest with?
>
> One consequence of rounding to nearest even (or nearest odd) is
> that this can give the worst possible outcome in terms of
>
> (rounded X - rounded Y) compared with (unrounded X - unrounded Y).
>
> For example, rounding to even integer X =1.5 --> 2.0 and
> Y = 0.5 --> 0.0 gives
>
> X - Y = 1.0 , rounded X - rounded Y = 2.0
>
> whereas the difference is 1.0 if you always round up, or always down,
> and this is also exactly the difference between the unrounded values..
>
> Rounding to nearest odd would give X = 1.5 --> 1.0, Y = 0.5 --> 1.0
> thus difference 0.0 in this case, but again difference 2.0 for
> X = 2.5 --> 3.0, Y = 1.5 --> 1.0
>
> And alternate rounding would give either 2.0 or 0.0 depending
> on the phase of X and Y.
>
> Thus "always up" or "always down" means that the difference between
> rounded numbers is always the same as between the unrounded numbers
> which for other methods the differences can differ by 2.0.
> This may or may not matter, but it is something to think about
> when choosing a rounding method.
>
> > [...]
>
> Best wishes to all,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 04-Aug-07 Time: 23:53:50
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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 has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
--
Dr. Mark Wardle
Clinical research fellow and specialist registrar, Neurology
Cardiff, UK
More information about the R-help
mailing list