1

I am trying to do a kruskal wallis test on the following datasets:

e<-c(0.0018, 0.0021, 0.0028, 0.0029, 0.0044, 0.0045, 0.0074, 0.00325140981291511,0.00325140981291511, 0.00325140981291511, 0.0079, 0.001978252063446,0.00684016798870973, 0.00384959728634123, 0.0093, 0.011, 0.014, 0.022, 0.083, 0.48, 0.49, 1.2)

f<-c(0.0145458371613749, 0.0355067948032862, 0.0654819408270916, 0.107370481645772, 0.165362828209794, 0.0654819408270916, 0.253, 0.344, 0.42, 1.3, 2.7, 3.14, 3.93, 4.48, 5.48, 17)

When I run the kruskal test with this code kruskal.test(e,f), I get this error:

Error in kruskal.test.default(e, f) : 
  'x' and 'g' must have the same length
llrs
  • 3,308
  • 35
  • 68
John
  • 11
  • 1
  • 3

1 Answers1

1

As explained in ?kruskal.test, your second argument has to be a factor indicating the groups. So:

# Combine the data in a single vector
x <- c(e,f)
# create a group indicator
groups <- rep(c(1,2), 
              times = c(length(e), length(f))
              )
# profit
kruskal.test(x, groups)

#   Kruskal-Wallis rank sum test
# 
# data:  x and groups
# Kruskal-Wallis chi-squared = 18.136, df = 1, p-value = 2.057e-05
Joris Meys
  • 106,551
  • 31
  • 221
  • 263