Good day all, My first posting to this list. It looked like the best place to post this question. When running the wilcox.test(), I noticed that the output values change if you change the ordering of the levels (example below which includes a t.test for comparison). I think this has something to do with the change in ranking order, but this doesn't make much sense as I would expect the ranking in this case to remain constant as there are no ties. So my questions are: a) is this correct (i.e. not a bug)?, and b) if it is, then which values should I report? x <- cbind(data.frame((c(rep("A",50),rep("B",50)))),runif(100)) colnames(x) <- c("a","b") wilcox.test(b~a,data=x) t.test(b~a,data=x) x$a <- relevel(x$a,ref="B") wilcox.test(b~a,data=x) t.test(b~a,data=x) Thank you in advance for your time, Regards, Alastair [[alternative HTML version deleted]]
The short answer is whichever version you want since they are the same. Look at the t-test results, they are also different. In one t is positive and in the other it is negative. That is just a result of whether the smaller mean is subtracted from the larger mean or vice versa. The same is happening with Wilcoxon (see http://en.wikipedia.org/wiki/Mann-Whitney-Wilcoxon_test ) for the specific equations. ------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alastair Potts Sent: Thursday, July 18, 2013 4:18 AM To: r-help at r-project.org Subject: [R] Orders of levels affecting wilcox.test() output Good day all, My first posting to this list. It looked like the best place to post this question. When running the wilcox.test(), I noticed that the output values change if you change the ordering of the levels (example below which includes a t.test for comparison). I think this has something to do with the change in ranking order, but this doesn't make much sense as I would expect the ranking in this case to remain constant as there are no ties. So my questions are: a) is this correct (i.e. not a bug)?, and b) if it is, then which values should I report? x <- cbind(data.frame((c(rep("A",50),rep("B",50)))),runif(100)) colnames(x) <- c("a","b") wilcox.test(b~a,data=x) t.test(b~a,data=x) x$a <- relevel(x$a,ref="B") wilcox.test(b~a,data=x) t.test(b~a,data=x) Thank you in advance for your time, Regards, Alastair [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org 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.
The p-value and inference is the same, the only difference that I see is the value of the W statistic. The definition of the W statistic (as discussed in the Note section on the help page) is based on the sum of the ranks in the **First** group, so if you change which group is first then you should expect the W statistic to change. As long as the inference does not change, why worry about it? On Thu, Jul 18, 2013 at 3:18 AM, Alastair Potts <potts.a@gmail.com> wrote:> Good day all, > > My first posting to this list. It looked like the best place to post this > question. > > When running the wilcox.test(), I noticed that the output values change if > you change the ordering of the levels (example below which includes a > t.test for comparison). I think this has something to do with the change in > ranking order, but this doesn't make much sense as I would expect the > ranking in this case to remain constant as there are no ties. So my > questions are: a) is this correct (i.e. not a bug)?, and b) if it is, then > which values should I report? > > > x <- cbind(data.frame((c(rep("A",50),rep("B",50)))),runif(100)) > colnames(x) <- c("a","b") > wilcox.test(b~a,data=x) > t.test(b~a,data=x) > x$a <- relevel(x$a,ref="B") > wilcox.test(b~a,data=x) > t.test(b~a,data=x) > > Thank you in advance for your time, > Regards, > Alastair > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]