[R-sig-eco] adonis and contrasts

Jari Oksanen jari.oksanen at oulu.fi
Mon Apr 26 15:41:39 CEST 2010


On 26/04/10 13:42 PM, "Christine Griffiths"
<Christine.Griffiths at bristol.ac.uk> wrote:

> Dear All,
> 
> I have done pairwise comparisons of species compositions between three
> treatments (1 v 2, 1 v 3, and 2 v 3) which were replicated 6 times (i.e. 6
> blocks). To avoid multiple testing I have decided to use contrasts instead
> (treatments 1 v 2 + 3, and 2 v 3). Oksanen (2009) mentions that this can be
> done, but when I have tried to incorporate the contrasts, either it doesn't
> run or the output suggests that the contrast has not been addressed.
> 
> Below is an example of the model I ran before wanting to add a contrast:
> 
> m1<-adonis(dat~Treatment,data=datenv,strata=datenv[,"Block"],permutation=1000,
> method="bray")
> 
> How do I add the following contrasts into the above model?
> treatment<-as.factor(Treatment)
> contrasts(treatment)<-cbind(c(-2,1,1),c(0,-1,1))
> contrasts(treatment)
> 
> [,1] [,2]
> 1.Control   -2    0
> 2.Radiata    1   -1
> 3.Aldabra    1    1
> 
> If this is not possible, is it acceptable to sum the species presence in
> the grouped treatments (2 + 3) and divide by 2, then combine this data to
> that of treatment 1 to form a matrix? However, as I would not be able to do
> more than one contrast, then I don't really overcome the problem of
> multiple testing.
> 
Christince,

Everything is possible in R --- though not always easy.

This really is a problem in adonis(). The crux of the problem is adonis()
handles contrasts in non-standard way: it sets contrasts in function call
with arguments "contr.ordered" and "contr.unordered". Hank Stevens (the
adonis author) preferred sum contrasts which are not the standard in R, and
he wanted to have an easy way to use those within adonis() without mucking
around with global options. The price is that some of your specific options
may be difficult to handle. You need a name of a contrast setting function
as the argument. Writing up your contrast functions may not be quite easy.
However, the following ad hoc function seems to work for this very specific
case:

contr.mine <- function(...) cbind(c(-2,1,1), c(0,-1,1))
adonis(dat~Treatment,data=datenv,strata=datenv[,"Block"],permutation=1000,
method="bray", contr.unordered = "contr.mine")

In this case you must make a new contrast function for each case (and check
that they really are meaningful and correct contrasts).

Another alternative is to make explicit model matrices for these variables,
since adonis() does not re-set contrasts if the argument is a matrix which
already has a "contrast" attribute (from the help of ?contrasts: " The
argument Œcontrasts¹ is ignored if Œx¹ has a matrixŒcontrasts¹ attribute
set.") So the following should work:

## From your example
treatment<-as.factor(Treatment)
contrasts(treatment)<-cbind(c(-2,1,1),c(0,-1,1))
## New line
treatment <- model.matrix(~ treatment)[,-1]
## Your code with treatment model.matrix without the (Intercept)
m1<-adonis(dat~treatment,strata=datenv[,"Block"],permutation=1000,
method="bray")

BTW, I recommend you use 999 permutations instead of 1000.

It may be that we should have a talk about adonis() contrasts with Hank
Stevens.

Cheers, Jari



More information about the R-sig-ecology mailing list