PERMANOVA通过组合水平进行对比

时间:2016-02-11 13:56:43

标签: r vegan two-way compare-contrast

我开始使用adonis函数通过组合级别创建PERMANOVA对比的脚本,但似乎没有使用级别矩阵与创建的adonis对象的组合,我的代码是:

require(vegan)
require(doBy)
require(wzRfun)
require(multcomp)

数据集

data(mite)
A = c(rep(c(0), 30), rep(c(1), 30))
B = rep(c(rep(c(0), 15), rep(c(1), 15)), 2) 

创建数据框

A <- as.factor(A)
B <- as.factor(B)
species <- mite[1:60,]

具有Jaccard指数的PERMANOVA

man.com<-adonis(species ~ A * B, method = "jaccard",permutations=999)
man.com

双向PERMANOVA对比

相互作用

A_B<- interaction(A, B)
levels(A_B)
do.call(rbind, strsplit(levels(A_B), "\\."))


g0 <- adonis(species ~ A * B, method = "jaccard",permutations=999)
g1 <- adonis(species ~ A_B, method = "jaccard",permutations=999)

M <- LSmatrix(g0, effect=c("A","B"))

平均估计

data.frame(g0=M%*%coef(g0), g1=coef(g1))

级别组合

str(M)
grid <- attr(M, "grid")

治疗水平之间的对比矩阵

B <- "b"
A <- "a"
spl <- interaction(grid[,2])
i <- 1:nrow(grid)
l <- split(i, f=spl)
contr <- lapply(l,
                function(row){
                    ## Contrast matrix parwise
                    a <- apc(M[row,], lev=levels(d[,2]))
                    rownames(a) <- paste(spl[row[1]],
                                         rownames(a), sep="/")
                    return(a)
                })
contr <- do.call(rbind, contr)
contr

Constrasts

summary(glht(g0, linfct=contr),
        test=adjusted(type="fdr"))

请有人帮助我,

提前致谢,

0 个答案:

没有答案