Bug 16138 - Wishlist: add tolerance parameter to wilcox.test() and rank() for determining ties
Summary: Wishlist: add tolerance parameter to wilcox.test() and rank() for determining...
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R 3.1.2
Hardware: Other OS X Mavericks
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2015-01-06 21:02 UTC by eaglek2011
Modified: 2015-01-07 09:48 UTC (History)
1 user (show)

See Also:

example program (1.53 KB, text/plain)
2015-01-06 21:02 UTC, eaglek2011

Note You need to log in before you can comment on or make changes to this bug.
Description eaglek2011 2015-01-06 21:02:49 UTC
Created attachment 1716 [details]
example program

It is well known that floating point math can impact results in R.  Bug report 15058 raised this point for the wilcox.test and rank functions.  The report was closed without change to code.  The enclosed example shows that significantly different results occur from calls to these routines with two sets of inputs that are conceptually equivalent except for roundoff issues.  The result is substantially different reported probabilities from wilcox.test(), and quite different rankings from rank().

While not strictly a bug, the code could (easily) be improved by allowing the user to set a tolerance (relative or absolute) below which values would be deemed to be ties.
Comment 1 Martin Maechler 2015-01-07 09:48:23 UTC
Changing  rank()  seems very wrong to me. ties are there when values are equal, in line with duplicated(), unique(), etc. The user can always use

 rank(signif(x, digits), *)   instead of  rank(x, *)

or with much more flexibility, using  signif2() instead of signif(),

     signif2 <- function(x, bits) { f <- 2^bits; round(f*x)/f }

Allowing to specify a tolerance for  wilcox.test() does make much more sense --
as the user cannot easily workaround in the two sample case --
and I would consider accepting patches (against R-devel aka "R trunk")