% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pairwise.adonis2.R
\name{pairwise.adonis2}
\alias{pairwise.adonis2}
\title{Pairwise multilevel comparison using adonis accepting strata}
\usage{
pairwise.adonis2(x, data, strata = NULL, nperm = 999, ...)
}
\arguments{
\item{x}{Model formula. The LHS is either community matrix or dissimilarity matrix (eg. from vegdist or dist)
See adonis() for details. The RHS are factors that nmust be column names of a data.frame specified with argument data.}

\item{data}{The data frame of indipendent varibles having as column names the factors specified in formula.}

\item{strata}{String. The name of the column with factors to be used as strata.}

\item{nperm}{The number of permutations.}

\item{...}{Any other parameter passed to adonis}
}
\value{
List. Elements are the summary returned by adonis for each unique pairwise combination of factors.
}
\description{
This is a wrapper function for multilevel pairwise comparison
using adonis() from package 'vegan'. The function accepts interaction between factors and strata.
}
\examples{
data(iris)
pairwise.adonis2(iris[,1:4]~Species,data=iris)

#For strata (blocks), Jari Oksanen recommends in the help of adonis2 to define the
#permutation matrix outside the adonis2 call
#In this example I have adapted the adonis2 example to have 3 factors in NO3

dat <- expand.grid(rep=gl(2,1), NO3=factor(c(0,10,30)),field=gl(3,1) )
Agropyron <- with(dat, as.numeric(field) + as.numeric(NO3)+2) +rnorm(18)/2
Schizachyrium <- with(dat, as.numeric(field) - as.numeric(NO3)+2) +rnorm(18)/2
Y <- data.frame(Agropyron, Schizachyrium)
perm <- how(nperm = 199)
setBlocks(perm) <- with(dat, field)
adonis2(Y ~ NO3, data = dat, permutations = perm)


# pairwise comparison
pairwise.adonis2(Y ~ NO3, data = dat, strata = 'field')
#notice the apostrophes in strata = 'field' !

#this will give same results a doing adonis2 pairwise one by one

#for factors '0' and '10'
dat2 <- dat[dat$NO3 \%in\% c('0','10'),]
Y2 <- Y[dat$NO3 \%in\% c('0','10'),]
setBlocks(perm) <- with(dat2, field)
adonis2(Y2 ~ NO3, data = dat2, permutations = perm)
# and so on...

}
\author{
Pedro Martinez Arbizu
}
