I perform several wilcoxon-tests for subcategories of my dataset. R performs these tests but displays one big output for each test. I would prefer to have one output for instance in form of a table summarizing all 14 wilcoxon-tests in a tidy manner (name of analized subset, value of test statistic, p-value, outcome e.g. alternative hyothesis:...)
I already tried many tips that I found online but since I am not very much familiar with R I can not analyze the problems, it simply did not work and a friend told me: "stackoverflow is your friend. Ask for help!". Can you help me further?
Best, Roman
This is the code I perform to get my output:
strFlaecheNames<-c(df_summary$Flaeche)
varResult<-array(vector("list",10000),1000)
for(i in 1:14){
varResult[i]<-wilcox.test(df1$y,data=df1,subset(df1$y, df1$x == strFlaecheNames[i]))
print((wilcox.test(df1$y,data=df1,subset(df1$y, df1$x == strFlaecheNames[i]))))
}
One of my 14 outputs looks like this:
Wilcoxon rank sum test with continuity correction
data: df1$y and subset(df1$y, df1$x == strFlaecheNames[i])
W = 1170300, p-value = 4.888e-13
alternative hypothesis: true location shift is not equal to 0
Here is a code sample, I also have it in form of reprex but I kind of fail to post it but since the code works I guess it is ok to post it?:
ed_exp2 <- structure(list(x = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("Area1", "Area10", "Area11",
"Area12", "Area13", "Area14", "Area2", "Area3", "Area4", "Area5",
"Area6", "Area7", "Area8", "Area9"), class = "factor"), y = c(0L,
0L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 2L, 1L,
2L, 0L, 1L, 0L, -2L, 2L, 0L, 2L, 1L, 2L, 2L, -2L, 0L, 0L)), .Names = c("x",
"y"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 169L, 170L, 171L, 172L,
173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L), class = "data.frame")
#load libraries
library("stats")
library("dplyr")
library("ggpubr")
library("tidyverse")
library("reprex")
strAreaNames<-c("Area1","Area2")
##required size of memory for output unclear - therefore "10000),1000)"
varResult<-array(vector("list",10000),1000)
#run wilcox.test
for(i in 1:2){
varResult[i]<-wilcox.test(ed_exp2$y,data=ed_exp2,subset(ed_exp2$y, ed_exp2$x == strAreaNames[i]))
print((wilcox.test(ed_exp2$y,data=ed_exp2,subset(ed_exp2$y, ed_exp2$x == strAreaNames[i]))))
}