On Fri, 21 Apr 2017, Tripoli Massimiliano wrote:

Dear R users,
Why the result of Wilcoxon sum rank test by R is different from sas

https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_npar1way_sect022.htm

The code is next:

sampleA <- c(1.94, 1.94, 2.92, 2.92, 2.92, 2.92, 3.27, 3.27, 3.27, 3.27,
       3.7, 3.7, 3.74)

sampleB <- c(3.27, 3.27, 3.27, 3.7, 3.7, 3.74)
wilcox.test(A,B,paired = F)

There are different ways how to compute or approximate the asymptotic or exact conditional distribution of the test statistic:

SAS reports an asymptotic normal approximation (apparently without continuity correction along with an asymptotic t approximation and the exact conditional distribution.

Base R's stats::wilcox.test can either report the exact conditional distribution (but only if there are no ties) or the asymptotic normal distribution (with or without continuity correction). In small samples the default is to use the former but a warning is issued when there are ties (as in your case).

Furthermore, coin::wilcox_test can report either the asymptotic normal distribution (without continuity correction) or the exact conditional distribution (even in the presence of ties).

Thus:

## collect data in data.frame
d <- data.frame(
  y = c(sampleA, sampleB),
  x = factor(rep(0:1, c(length(sampleA), length(sampleB))))
)

## asymptotic normal distribution without continuity correction
## (p = 0.0764)
stats::wilcox.test(y ~ x, data = d, exact = FALSE, correct = FALSE)
coin::wilcox_test(y ~ x, data = d, distribution = "asymptotic")

## exact conditional distribution (p = 0.1054)
coin::wilcox_test(y ~ x, data = d, distribution = "exact")

These match SAS's results. The default result of stats::wilcox.test is different as explained by the warning issued.

hth,
Z

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to