4
votes

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

2

2 Answers

4
votes

This is really old but I was looking for this answer and figured I'd post in case anyone else stumbles on this later.

dunn.test has a build in option to have the output as a list. That's really all you need since you can turn that into a data.frame and sort by column.

Here's some sample code to do this:

table = dunn.test(X, g, list=TRUE)
table = cbind.data.frame(table$comparisons,table$Z,table$P.adjusted)
table[order(table$`table$P.adjusted`),]
0
votes

See the dunn.test package. Which has two different options for tabled output of Dunn's test following a Kruskal-Wallis test. As of 1.3.0 the package also includes an option to output the multiple comparisons as a list.