vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
449 stars 96 forks source link

adonis test - empty rows and missing values with method="bray" #396

Closed adrianacravo closed 2 years ago

adrianacravo commented 3 years ago

Hello everyone,

I'm stuck at a problem with the adonis function and have no idea how to move forward, after trying some possibilities. First, I have a phyloseq object, which is an object with an abundance component (abundance of OTUs across samples), a metadata file and the taxonomy file for the OTUs.

I'm trying to run an adonis test to see if the abundance of OTUs differs among the species id and the load of a pathogen. That's how my object looks like: phyloseq-class experiment-level object otu_table() OTU Table: [ 123 taxa and 551 samples ] sample_data() Sample Data: [ 551 samples by 27 sample variables ] tax_table() Taxonomy Table: [ 123 taxa by 7 taxonomic ranks ]

So, to perform the permanova, I did: comp_16S <- transform(pruned16Sabund, "compositional") #transformed my data to compositional abund_16S <- abundances(comp_16S) #extracted the abundance of my OTUs meta_16S <- meta(comp_16S) #the table where species id and pathogen load are

However, when I run adonis_spp16S <- adonis(t(abund_16S) ~ species, data = meta_16S, permutations=9999, method = "bray", I get the error message: Warning messages: 1: In vegdist(lhs, method = method, ...) : you have empty rows: their dissimilarities may be meaningless in method “bray” 2: In vegdist(lhs, method = method, ...) : missing values in results

I've already tried to increase the abundance threshold from 0.0005 to 0.001, in case the low abundant OTUs were causing the problem and still got the same issue. I also tried to remove rows or columns that were empty, but no empty rows/ columns were found

comp_16Srem <- remove_empty(abund_16S, which = "rows", quiet = FALSE) #no empty rows to remove comp_16Srem <- remove_empty(abund_16S, which = "cols", quiet = FALSE) #no empty columns to remove

Just in case, I also transformed my character into factor: meta_16S$species <- as.factor(meta_16S$species), but nothing changed. I've done adonis test with my phyloseq objects many times and never had this issue. It is normal to have many zeros in an abundance table for microorganisms, so I don't know how to fix this at the moment. Does someone know a way out?

As a background info, that's my filtering step where I select the threshold of abundance that will be considered for my data: min = 0.001 for16S = taxa_sums(prunedSet16S) #original phyloseq object used for the filtering keep16S = (forl16S / sum(forl16S)) > min pruned16Sabund = prune_taxa(keep16S, prunedSet16S)

Any help is appreciated! Thanks a lot,

Adriana

jarioksa commented 3 years ago

Obviously you have empty rows in your data. With "empty" I mean rows which have no species but are all zeros. You should remove them. I don't know where you get the function remove_empty (there is no such function in standard R), but the one I have seen in an add-on package does not remove such all-zero rows or columns, but it removes only those where all items are missing values (NA).

There is no way to calculate a Bray-Curtis dissimilarity between two non-existent communities, but you get NaN ("not a number").