[R-sig-Geo] [R-sig-eco] Two-way contrasts with adonis()
ASANTOS
alexandresantosbr at yahoo.com.br
Thu Mar 10 13:24:02 CET 2016
Hi Sven,
Thank you other time, but I improve my code for multiple
comparisons with adonis() function and I have other problems in my code,
because the function don't read my comparisons object contr2(list), in
my code:
#1st factor
treat <- gl(4, 15, labels = paste("t", 1:4, sep="")); treat
#Variables
set.sed(124)
sp <- cbind(c(rnorm(10, 5, 0.25), rnorm(50, 2.5, 0.25)), rnorm(60,
2.5, 0.25),
c(rnorm(10, 12, 0.25), rnorm(50, 2.5, 0.25)), rnorm(60,
2.5, 0.25))
colnames(sp) <- c("sp1", "sp2", "sp3", "sp4")
head(sp))
#create a design matrix of the contrasts for "treat"
Treat_Imp<-model.matrix(~treat-1)
require(vegan)
fullModel <- adonis(sp ~ treat, method = "euclidean", permutations = 9999)
fullModel
#Comparisons
TI <- model.matrix(~ treat-1)
head(TI)
f <- length(levels(treat))
comb <- t(combn(1:f, 2))
n <- nrow(comb)
contr2 <- NULL
for (x in 1:n) {
i <- comb[x, 1]
j <- comb[x, 2]
tmp <- list(TI[,i] - TI[,j]); names(tmp) <- paste0("TI",i, "_", j)
contr2 <- c(contr2, tmp)
}
contr2
adonis(sp ~ contr2[1]+contr2[2]+contr2[3]+contr2[4]+contr2[5]+contr2[6],
method = "euclidean", permutations = 9999)
#
Thanks
--
======================================================================
Alexandre dos Santos
Proteção Florestal
IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
Campus Cáceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial
Cáceres - MT CEP: 78.200-000
Fone: (+55) 65 8132-8112 (TIM) (+55) 65 9686-6970 (VIVO)
alexandre.santos at cas.ifmt.edu.br
Lattes: http://lattes.cnpq.br/1360403201088680
OrcID: orcid.org/0000-0001-8232-6722
Researchgate: https://www.researchgate.net/profile/Alexandre_Santos10
LinkedIn: https://br.linkedin.com/in/alexandre-dos-santos-87961635
======================================================================
Em 09/03/2016 10:23, microbiomics escreveu:
> Hi Alexandre,
>
> On 09.03.2016 12:34, ASANTOS wrote:
> [the code above is OK]
>
>> #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]
>>
>
> 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
>
More information about the R-sig-Geo
mailing list