Retrieving p adj values โ€‹โ€‹from TukeyHSD test

With a dummy dataset:

Species Var1 Var2 Var3 a 1 2 3 a 4 5 6 b 7 8 9 b 10 11 12 

I have several types and about 50 variables (Var50). I would like to perform a unidirectional Anova for a pairing variable of grouping (Species) for each response variable and get an output of frequencies that are statistically significant at 95% CI, for example. I started writing a function to do it like this:

 data<-read.table("example.txt", header=T, sep="\t") function(y){ for(y in 2:50) anova.r<-aov(y~Species, data = data) result<-TukeyHSD(anova.r, conf.level = 0.95) f.result ## I cannot figure out how to extract the "p adj" from the results f.result<-sum(prob.result>=0.05) write.table(f.result, file = "anova95.csv", sep = ",", col.names = FALSE, append=TRUE) } 

Ultimately, I would like the final table (dummy answers) to look like

  Var1 Var2 Var3......Var50 Frequency at 95% CI 106 200 45 246 

I know that I can use [[]] to access the data in the Tukey test results. I tried using tukey.results[[1]][,1] until tukey.results[[1]][,3] no avail. tukey.results[[1]] returns all columns from the Tukey test.

Also, I think I might have to use cbind somewhere in the function to get the data in the corresponding columns. Or I thought it would be possible to use the apply command, but I donโ€™t know how to keep the grouping variable constant when the response variable changes at each iteration.

Any suggestions would be greatly appreciated.

+4
source share
2 answers

Try this if you are also looking for variables:

 summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) kk<-TukeyHSD(fm1, "tension", ordered = TRUE) kk$tension result<-data.frame( kk$tension) result["p.adj"] p.adj MH 0.447421021 LH 0.001121788 LM 0.033626219 
+2
source

The answer did not work on my system. Here is my solution starting with Metrics code.

  summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) kk<-TukeyHSD(fm1, "tension", ordered = TRUE) kk<-kk$tension #strips off some headers in kk kk<-as.data.frame(kk) #converts to data frame kk<-kk$'p adj' #selects relevant output print(kk) #to check answer 
+2
source

Source: https://habr.com/ru/post/1501533/


All Articles