Leprechault
Leprechault

Reputation: 1823

PERMANOVA contrasts by combination of levels

I started to create a script for a PERMANOVA contrasts by combination of levels using adonis function, but doesn't seem to be working a combination of levels matrix with adonis object created, my code was:

Packages

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

Data set

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

Create data frame

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

PERMANOVA with Jaccard index

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

Two-Way PERMANOVA Contrasts

Interaction

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"))

Mean estimation

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

Combination of levels

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

Matrix of contrasts between levels of treatement

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"))

Could somebody please help me,

Thanks in advance,

Upvotes: 1

Views: 1050

Answers (0)

Related Questions