Organizing multiples p-value in R (Kruskal.test)

Asked

Viewed 38 times

0

Using the code below, I created a data.frame() with 5 variables. This way, I can get the value of p using the variable 'table' and Kruskal.test().

> sample1 <- c(3, 3, 3, 2, 3)
> sample2 <- c(7, 7, 10, 6, 10)
> sample3 <- c(10, 13, 12, 14, 13)
> sample4 <- c(15, 20, 18, 20, 17)
> sample5 <- c(4, 5, 3, 3, 4)
>
> table <- data.frame(sample1, sample2, sample3, sample4, sample5)
> 
> kruskal.test(table$sample1, table$sample2)$p.value
[1] 0.1353353
> kruskal.test(table$sample1, table$sample3)$p.value
[1] 0.2614641
> kruskal.test(table$sample1, table$sample4)$p.value
[1] 0.6822703
> kruskal.test(table$sample1, table$sample5)$p.value
[1] 0.4723666

However, I would like to organize the result in a similar image to the one below by strictly using the 'table' variable.

inserir a descrição da imagem aqui

There is some package, command or alternative for this to happen. I’ve seen something similar to the use in color() function but I couldn’t find anything that applies here for now.

  • you can do it with 2 for. I don’t know a more elegant way to do it.

1 answer

0

I got the answer in the international version of the forum. Simply complement with the code below that the table will be generated...

pvals <- outer(table, table, function(x,y) {
  mapply(function(x,y) kruskal.test(x,y)$p.value, x,y)
})

diag(pvals) <- NA
pvals

Thanks a lot....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.