joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
582 stars 187 forks source link

adonis using PERMANOVA #1046

Closed saifsikdar closed 5 years ago

saifsikdar commented 5 years ago

Hi @joey711

Thanks again for your previous help. Now, I am trying to do PERMANOVA using the "adonis" function to see if ASVs clustered separately for 3 different vendors (CR, JAX and TAC) has statistical significance. I tried multiple ways using phyloseq object, but I always get an error massage as mentioned at end of the code. Can you please help me to identify the problem here? Thank you!

my phyloseq object (ps_allvend_ctrl) output: phyloseq-class experiment-level object otu_table() OTU Table: [ 2097 taxa and 15 samples ] sample_data() Sample Data: [ 15 samples by 11 sample variables ] tax_table() Taxonomy Table: [ 2097 taxa by 7 taxonomic ranks ] phy_tree() Phylogenetic Tree: [ 2097 tips and 2095 internal nodes ]

code I used for coordination and PERMANOVA

ps.prop_allvend_ctrl <- transform_sample_counts(ps_allvend_ctrl, function(otu) {otu/sum(otu)}) set.seed(134) PCoA.wunifrac_allvend_ctrl <- ordinate(ps.prop_allvend_ctrl, method="PCoA", distance="wunifrac")

calculating bray curtis distance matrix

ps_allvend_ctrl_bray <- phyloseq::distance(ps.prop_allvend_ctrl, method = "bray")

making a data frame from the sample_data

sampledf <- data.frame(sample_data(ps_allvend_ctrl))

running adonis test

adonis(ps_allvend_ctrl ~ vendor, data = sampledf)

Output adonis(ps_allvend_ctrl ~ vendor, data = sampledf) Error in rowSums(x, na.rm = TRUE) : 'x' must be an array of at least two dimensions

---attachment contains the sanpshot of my sample_data sample_data

joey711 commented 5 years ago

Your final line needs to be changed to

adonis(ps_allvend_ctrl_bray ~ vendor, data = sampledf)

The left-hand side of the formula passed to adonis function needs to be a distance matrix of the samples (rows) in sampledf.