Skip to content

Two-way contrasts with adonis()

3 messages · ASANTOS, microbiomics

#
Thanks you very much Sven,

           But I try to make multiple comparisons and not with isolate 
factors and doesn't work. In my new code I have significant interaction, 
my example was:

#1st factor
treat <- gl(3, 20, labels = paste("t", 1:3, sep=""))
#2nd factor
imp <- rep(gl(2, 10, labels = c("yes", "no")), 3)


#create a design matrix of the contrasts for "treat" in "imp"
Treat_Imp<-model.matrix(~ imp:treat-1)


#Variables
sp1_1 = rnorm(10, 5, 0.25)
sp1_2 = rnorm(50, 2.5, 0.25)
sp1 = c(sp1_1,sp1_2)
sp2 = rnorm(60, 2.5, 0.25)
sp3_1 = rnorm(10, 12, 0.25)
sp3_2 = rnorm(50, 2.5, 0.25)
sp3 = c(sp3_1,sp3_2)
sp4 = rnorm(60, 2.5, 0.25)
sp<-cbind(sp1,sp2,sp3,sp4)

require(vegan)

fullModel <- adonis(sp ~ treat * imp, method = "euclidean")

fullModel

#Comparisons
impyes:treatt1_impno:treatt1<- Treat_Imp[, 1] - Treat_Imp[, 2]
impyes:treatt2_impno:treatt2<- Treat_Imp[, 2] - Treat_Imp[, 3]
impyes:treatt3_impno:treatt3<- Treat_Imp[, 3] - Treat_Imp[, 4]

adonis(sp ~ 
impyes:treatt1_impno:treatt1[as.logical(impyes:treatt1_impno:treatt1)]
+impyes:treatt2_impno:treatt2[as.logical(impyes:treatt2_impno:treatt2)]+
+impyes:treatt3_impno:treatt3[as.logical(impyes:treatt3_impno:treatt3)],method 
= "euclidean")
#
#
On 09.03.2016 12:34, ASANTOS wrote:
#
Hi Alexandre,
On 09.03.2016 12:34, ASANTOS wrote:
[the code above is OK]
First, variable names cannot contain ":", so you need to replace the 
colon with a period. Also, it looks like you mixed up column indices of 
Treat_Imp, so my suggestion is:

impyes.treatt1_impno.treatt1<- Treat_Imp[, 1] - Treat_Imp[, 2]
impyes.treatt2_impno.treatt2<- Treat_Imp[, 3] - Treat_Imp[, 4]
impyes.treatt3_impno.treatt3<- Treat_Imp[, 5] - Treat_Imp[, 6]




To simply make the code run as per your request, try this:

adonis(sp ~ impyes.treatt1_impno.treatt1
       + impyes.treatt2_impno.treatt2
       + impyes.treatt3_impno.treatt3,
       method = "euclidean")



One problem with this approach is that terms are added sequentially to 
the test, so "impyes.treatt1_impno.treatt1" is tested alone, while 
"impyes.treatt2_impno.treatt2" is tested in presence of 
"impyes.treatt1_impno.treatt1" and so on. Thus, your result depends on 
the input order of your terms, which might not be what you expect or 
even want.

A better alternative to the above code would thus involve function 
rda(), followed by its anova() method:


rdaModel <- rda(sp ~ impyes.treatt1_impno.treatt1
                + impyes.treatt2_impno.treatt2
                + impyes.treatt3_impno.treatt3)

anova(rdaModel, by = "terms")



Still, it looks like you are trying to construct a "Swiss Army knife" to 
do ANOVA and multiple pairwise tests at the same time. IMHO, you need to 
perform the pairwise comparisons one by one, each with its respective 
subset of data - and appropriate p-value adjustment for multiple testing.



Best,
Sven