0

我尝试在 PERMANOVA 中用 4 个因素创建超过三个独立的对比,但没有成功。我需要在我的 contr2df 对象中使用所有可能的因子水平成对组合。有什么办法可以使这成为可能?在我的代码中:

#1st factor
treat <- gl(4, 15, labels = paste("t", 1:4, sep="")); treat 

#Variables
set.seed(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 <- nlevels(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


contr2df <- as.data.frame(contr2)

adonis(
     sp ~ ., data = contr2df,
     method = "euclidean",
     permutations = 9999)
# 

谢谢,

亚历山大

4

0 回答 0