[R] 2 sample wilcox.test != kruskal.test

Daniel Nordlund djnordlund at frontier.com
Wed Jan 11 20:57:13 CET 2012


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of syrvn
> Sent: Wednesday, January 11, 2012 2:36 AM
> To: r-help at r-project.org
> Subject: Re: [R] 2 sample wilcox.test != kruskal.test
> 
> Hi,
> 
> thanks for your answer. Unfortunately I cannot reproduce your results.
> 
> In my example the results still differ when I use your approach:
> 
> > x <- c(10,11,15,8,16,12,20)
> > y <- c(10,14,18,25,28,30,35)
> > f <- as.factor(c(rep("a",7), rep("b",7)))
> > d <- c(x,y)
> > kruskal.test(x,y)
> 
> 	Kruskal-Wallis rank sum test
> 
> data:  x and y
> Kruskal-Wallis chi-squared = 6, df = 6, p-value = 0.4232
> 
> > kruskal.test(x~y)
> 
> 	Kruskal-Wallis rank sum test
> 
> data:  x by y
> Kruskal-Wallis chi-squared = 6, df = 6, p-value = 0.4232
> 
> > kruskal.test(d~f)
> 
> 	Kruskal-Wallis rank sum test
> 
> data:  d by f
> Kruskal-Wallis chi-squared = 3.6816, df = 1, p-value = 0.05502
> 
> > kruskal.test(f~d)
> 
> 	Kruskal-Wallis rank sum test
> 
> data:  f by d
> Kruskal-Wallis chi-squared = 11.1429, df = 12, p-value = 0.5167
> 
> 
> I know the last kruskal.test(f~d) is not correct as the factor is always
> placed as the second bit but I still tried it that way just to be sure...
> 
> Cheers
> 
> 

You don't provide context, so I don't know what results you can't reproduce.  But you need to reread the help page for the kruskal.test and look at the examples give.  If x and y are the results for two independent groups, then the call to the kruskal.test should be either 

kruskal.test(list(x,y)) #or,
kruskal.test(d~f)


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA



More information about the R-help mailing list