0

I am having trouble with coding a Kruskal-Wallis test in R. I tried to find how does it work but could not find any answers. I have a dataset with 89 columns and I have to compare each column with a group of others.

For example, I have the data of various extensometers and other instruments at those 89 columns, but I need to compare the extensometers with each other. Since Kruskal-Wallis is a test for three or more groups, can I do that with my dataset, should I vectorize it, make a list or do I have to compare it 1 by 1?

I am trying to make this loop for the 1 by 1 way:

i=3
j=3
while(i <= 8){
  if(j==i)
    j=j+1
  else 
    l1<- paste0("X__", i)
    l2<- paste0("X__", j)
    L1 <- as.factor(l1)
    L2 <- as.factor(l2)
    kruskal.test(L1~L2, data = dados)
    i = i+1
}

And getting the error that all observations are in the same group.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 3
    What does `dados` look like? When you do `as.factor(l1)` you are literally doing `as.factor(paste0("X__", i))` which is just going to be a single character value. You cannot using basic strings in formulas. Maybe see the `?reformulate` command to build a formula with strings that you can pass to `kruskal.test` – MrFlick Apr 17 '19 at 18:59
  • 2
    Can you provide a [mcve] of your dataset so that we can reproduce your problem. Also, it sounds like you're not sure how best to perform the test: we can help with programming issues, but if you have a statistical question, you'll get much better answers on [stats.se] – divibisan Apr 17 '19 at 18:59

0 Answers0