Inconsistencies in wilcox.test
Your second issue seems like a more or less unavoidable floating-point computation issue. The paired test operates by computing differences between corresponding values of x and y. It's not impossible to try to detect "almost-ties" (by testing for differences less than, say, sqrt(.Machine$double.eps)), but it's delicate and somewhat subjective/problem-dependent. Example: options(digits=20)
unique(c(4,3,2)-c(3,2,1))
[1] 1
unique(c(0.4,0.3,0.2)-c(0.3,0.2,0.1))
[1] 0.100000000000000033307 0.099999999999999977796 0.100000000000000005551
On 2019-12-07 1:55 p.m., Karolis Koncevi?ius wrote:
Hello,
Writing to share some things I've found about wilcox.test() that seem a
a bit inconsistent.
1. Inf values are not removed if paired=TRUE
# returns different results (Inf is removed):
wilcox.test(c(1,2,3,4), c(0,9,8,7))
wilcox.test(c(1,2,3,4), c(0,9,8,Inf))
# returns the same result (Inf is left as value with highest rank):
wilcox.test(c(1,2,3,4), c(0,9,8,7), paired=TRUE)
wilcox.test(c(1,2,3,4), c(0,9,8,Inf), paired=TRUE)
2. tolerance issues with paired=TRUE.
wilcox.test(c(4, 3, 2), c(3, 2, 1), paired=TRUE)
# ...
# Warning:? cannot compute exact p-value with ties
wilcox.test(c(0.4,0.3,0.2), c(0.3,0.2,0.1), paired=TRUE)
# ...
# no warning
3. Always 'x observations are missing' when paired=TRUE
wilcox.test(c(1,2), c(NA_integer_,NA_integer_), paired=TRUE)
# ...
# Error:? not enough (finite) 'x' observations
4. No indication if normal approximation was used:
# different numbers, but same "method" name
wilcox.test(rnorm(10), exact=FALSE, correct=FALSE)
wilcox.test(rnorm(10), exact=TRUE, correct=FALSE)
From all of these I am pretty sure the 1st one is likely unintended,
so attaching a small patch to adjust it. Can also try patching others if
consensus is reached that the behavioiur has to be modified.
Kind regards,
Karolis Koncevi?ius.
---
Index: wilcox.test.R
===================================================================
--- wilcox.test.R? (revision 77540)
+++ wilcox.test.R? (working copy)
@@ -42,7 +42,7 @@
???????? if(paired) {
???????????? if(length(x) != length(y))
???????????????? stop("'x' and 'y' must have the same length")
-??????????? OK <- complete.cases(x, y)
+??????????? OK <- is.finite(x) & is.finite(y)
???????????? x <- x[OK] - y[OK]
???????????? y <- NULL
???????? }
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel