[R] More on ties with rank()

Thomas Lumley tlumley at u.washington.edu
Tue May 7 21:46:50 CEST 2002


On Tue, 7 May 2002, arcriswell wrote:

> I am grateful to Prof. Ripley for his explanation. Indeed, rounding explains
> it all.
>
> I take the difference between two vectors and call it "z"
>
> method.a <- c(6.3, 6.3, 3.5, 5.1, 5.5, 7.7, 6.3, 2.8, 3.4, 5.7, 5.6, 6.2,
> 6.6,
>                        7.7, 7.4, 5.6, 6.3, 8.4, 5.6, 4.8, 4.3, 4.2, 3.3,
> 3.8, 5.7, 4.1)
>
> method.b <- c(5.2, 6.6, 2.3, 4.4, 4.1, 6.4, 5.4, 2.3, 3.2, 5.2, 4.9, 6.1,
> 6.3,
>                        7.4, 7.4, 4.9, 5.4, 8.4, 5.1, 4.4, 4.3, 4.1, 2.2,
> 4.0, 5.8, 4.0)
>
> z <- sort(abs(method.a - method.b))
>
<snip>
>
> But it strikes me as odd, that such an innocent calculation could lead to
> such a significant miscalculation based on rounding error.
>

Not odd at all. Any result that depends on floating point equality is
going to be sensitive.

Floating point numbers are reliably equal only when the same result is
computed by the same arithmetical steps (and sometimes not even then).

If you know your data are really discrete then you should round them
before ranking, if they aren't really discrete you shouldn't expect tied
values to behave consistently

	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list