I'm working with bacteria pyrosequencing data and I'm doing the statistical analysis with R. I have 21 samples and 7 different treatments. I loaded my data into R phyloseq obtaining:
> psR
phyloseq-class experiment-level object
otu_table() OTU Table: [ 7498 taxa and 21 samples ]
sample_data() Sample Data: [ 21 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 7498 taxa by 6 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 7498 tips and 7497 internal nodes ]
Since I found that there are statistically significant differences between the treaments (with the adonis function), I wanted to know which OTUs have a different abundance in the different treatments. To do that I used the function dunn.test (with Kruskal-Wallis test incorporated), swapping first the rows and the columns in the OTU table in order to apply the test:
swap_otu_table <- t(otu_table(psR))
treatment <- c('A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D', 'E', 'E', 'E', 'F', 'F', 'F', 'G', 'G', 'G')
swap_otu_tableDF <- as.data.frame(swap_otu_table)
ncol(swap_otu_tableDF)
[1] 7498
lapply(swap_otu_tableDF[1:7498], function(x) kruskal.test(x ~ treatment, data=swap_otu_tableDF))
The output of this recursive function is quite difficult to read, especially for all 7498 OTUs.
Is there some way to apply a Kruskal-Wallis + Dunn's test in a recursive way that gives a table as an output, preferably in order of significance, and with not only the OTU code but also the taxonomic identification contained in tax_table(psR)?
Thank you very much!
Lidia