[R] Kruskal.test() on lists

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Aug 21 22:57:31 CEST 2008


Altaweel, Mark R. wrote:
> Hi,
>
> I am trying to do a kruskal wallis test on two lists, fVisited and cSN:
>
> fVisited[[1]]
> [1] 0.17097623 0.30376141 0.17577266 0.14951855 0.03959753 0.08096217 0.05744888 0.02196257....
> ....
>
> cSN[[1]]
> [1] 0.08557303 0.36477791 0.19601252 0.12981040 0.05351320 0.10385542 0.03539577 0.03106175....
>
>
> So if I just want to do a test on just one of the entries this is simple enough:
>
> kruskal.test(fVisited[[1]],cSN[[1]])
>
> 	Kruskal-Wallis rank sum test
>
> data:  fVisited[[1]] and cSN[[1]] 
> Kruskal-Wallis chi-squared = 7, df = 7, p-value = 0.4289
>
> However, if I try to do it over the entire list I get a problem.  I wanted to do a test comparing each pair of distributions, so I thought something such as:  kT<-sapply(fVisited,function(.df){sapply(cSN,functions(.vecs){kruskal.test(.df,.vecs)})}
> But that produces this:
>
> Error in kruskal.test.default(.df, .vecs) : 
>   'x' and 'g' must have the same length
>
>
> However, the values do have the same length. Can anyone see what I am doing wrong here?
>
>   
Not immediately (assuming that "functions" is just a copy-paste error). 
How about putting
print(.df); print(.vec)
just before the call to kruskal.test?

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list