[R-sig-eco] Running contrasts in adonis in R

Aaron Hogan hogieskier at gmail.com
Wed Jul 27 15:40:29 CEST 2016


Hi Lauren,

I had found this function that does pairwise contrasts for an adonis object
in R.  Credit goes to Pedro Martinez Arbizu on ReseachGate
https://www.researchgate.net/post/How_can_I_do_PerMANOVA_pairwise_contrasts_in_R

Cheers, Aaron


pairwise.adonis <- function(x,factors, sim.method = 'bray', p.adjust.m
='bonferroni')
{
library(vegan)
co = combn(unique(factors),2)
pairs = c()
F.Model =c()
R2 = c()
p.value = c()

for(elem in 1:ncol(co)){
ad = adonis(x[factors %in% c(co[1,elem],co[2,elem]),] ~ factors[factors
%in% c(co[1,elem],co[2,elem])] , method =sim.method);
pairs = c(pairs,paste(co[1,elem],'vs',co[2,elem]));
F.Model =c(F.Model,ad$aov.tab[1,4]);
R2 = c(R2,ad$aov.tab[1,5]);
p.value = c(p.value,ad$aov.tab[1,6])
}
p.adjusted = p.adjust(p.value,method=p.adjust.m)
pairw.res = data.frame(pairs,F.Model,R2,p.value,p.adjusted)
return(pairw.res)
}



Aaron Hogan
(970) 485-1412
hogieskier at gmail.com

On Tue, Jul 26, 2016 at 3:05 PM, Gurski, Lauren <lgurski at islander.tamucc.edu
> wrote:

> Hi,
>
>
> I am trying to run contrasts on my data using adonis in R. My data was
> collected across three islands (Big Island, Kauai, and Oahu) and on each
> island was collected from two microhabitats (Crevice, and Surface). I have
> reference and alternative alleles for each of these island:microhabitat
> combos. An example dataset is below:
>
>
> Island,Microhabitat,REF,ALT
>
> BI,crevice,1,0
>
> BI,crevice,1,0
>
> BI,crevice,1,0
>
> BI,crevice,0,1
>
> BI,surface,0,1
>
> BI,surface,0,1
>
> BI,surface,0,1
>
> BI,surface,1,0
>
> KA,crevice,1,0
>
> KA,crevice,1,0
>
> KA,crevice,1,0
>
> KA,crevice,1,0
>
> KA,crevice,1,0
>
> KA,surface,0,1
>
> KA,surface,0,1
>
> KA,surface,1,0
>
> KA,surface,1,0
>
> KA,surface,1,0
>
> KA,surface,1,0
>
> OA,crevice,1,0
>
> OA,crevice,1,0
>
> OA,crevice,1,0
>
> OA,crevice,1,0
>
> OA,surface,1,0
>
> OA,surface,1,0
>
> OA,surface,1,0
>
> OA,surface,1,0
>
> OA,surface,1,0
>
>
> I ran a two way permanova using adonis on my data with the following code:
>
>
> > alleleData<-myData[,c("REF","ALT")]
>
> > alleleData.env<-myData[,c("Pool", "Island","Microhabitat")]
>
> > int<-adonis(alleleData ~ Island + Microhabitat + Island*Microhabitat,
> data=alleleData.env, permutations=10000, method="canberra", strata=NULL)
>
>
> I now want to run different contrasts on my data but am having a hard time
> figuring out how to do it in adonis. I was wondering if there is a way to
> create my own contrasts to test specific questions using the contr.ordered
> or contr.unordered arguments? Some of the specific questions I'd like to
> test would be if there is a linear relationship across the islands (BI > KA
> > OA), or if there are differences on the just the surfaces of the rocks
> across the islands (BI_surface > KA_surface > OA_surface).
>
>
>
>
>
> Thanks for the help!
>
> Lauren
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list