[R] How to apply the Wilcoxon test to a hole table at once?

Steven McKinney smckinney at bccrc.ca
Sat Oct 24 06:04:26 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Iurie Malai
> Sent: Friday, October 23, 2009 10:46 AM
> To: r-help at r-project.org
> Subject: [R] How to apply the Wilcoxon test to a hole table at once?
> 
> 
> Hi,
> 
> I have a data set:
> 
> > Dataset
>      X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17
> 1 user1  m 22 19 28 24 12 18  9   7   4   5   4   7   5   7   9
> 2 user2  f 25 19 23 18 18 15  6   8   6   6   7  10   7   7   7
> 3 user3  f 28 21 24 18 15 12 10   6   7   9   5  10   5   9   5
> 4 user4  f 26 19 26 21 12 18  6   6   5   1   3   8   6   5   6
> 5 user5  m 21 22 26 18  9  6  4   6   1   7   2   4   4   6   4
> 6 user6  m 24  8 25 12 18 12  7   8   4   1   4   6   7   5   6
> ...............................................................
> 71 user71  m 18  4 10  6  3  6  9   5  10   8   4   5   6   5   5
> 
> I can apply the Wilcoxon test on each column one by one, but how to do
> this
> on the hole table at once?
> 
> > wilcox.test(X3 ~ X2, alternative="two.sided", data=Dataset)
> 
> 	Wilcoxon rank sum test with continuity correction
> 
> data:  X3 by X2
> W = 439, p-value = 0.1291
> alternative hypothesis: true location shift is not equal to 0
> 
> >

Here's one way to do it (using airquality dataset)

> lapply(airquality[1:4], function(x) wilcox.test(x ~ Month, alternative="two.sided", data=airquality, subset = Month <= 6))
$Ozone

        Wilcoxon rank sum test with continuity correction

data:  x by Month 
W = 82, p-value = 0.1925
alternative hypothesis: true location shift is not equal to 0 


$Solar.R

        Wilcoxon rank sum test with continuity correction

data:  x by Month 
W = 391.5, p-value = 0.8354
alternative hypothesis: true location shift is not equal to 0 


$Wind

        Wilcoxon rank sum test with continuity correction

data:  x by Month 
W = 566, p-value = 0.1461
alternative hypothesis: true location shift is not equal to 0 


$Temp

        Wilcoxon rank sum test with continuity correction

data:  x by Month 
W = 78, p-value = 2.400e-08
alternative hypothesis: true location shift is not equal to 0 


Warning messages:
1: In wilcox.test.default(x = c(41L, 36L, 12L, 18L, 28L, 23L, 19L,  :
  cannot compute exact p-value with ties
2: In wilcox.test.default(x = c(190L, 118L, 149L, 313L, 299L, 99L,  :
  cannot compute exact p-value with ties
3: In wilcox.test.default(x = c(7.4, 8, 12.6, 11.5, 14.3, 14.9, 8.6,  :
  cannot compute exact p-value with ties
4: In wilcox.test.default(x = c(67L, 72L, 74L, 62L, 56L, 66L, 65L,  :
  cannot compute exact p-value with ties
 
# Sanity check:
> wilcox.test(Temp ~ Month, alternative="two.sided", data=airquality, subset = Month <= 6)

        Wilcoxon rank sum test with continuity correction

data:  Temp by Month 
W = 78, p-value = 2.400e-08
alternative hypothesis: true location shift is not equal to 0 

Warning message:
In wilcox.test.default(x = c(67L, 72L, 74L, 62L, 56L, 66L, 65L,  :
  cannot compute exact p-value with ties
>
# Same as lapply loop result


HTH

Steven McKinney
Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre





> 
> I researched on this, but I can't find a solution.
> I would really appreciate any help.
> 
> P.S. Excuse my lack of terminology :).
> 
> Iurie Malai
> Moldova Pedagogical State University
> --
> View this message in context: http://www.nabble.com/How-to-apply-the-
> Wilcoxon-test-to-a-hole-table-at-once--tp26030572p26030572.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.




More information about the R-help mailing list