# A factor with 5 levels
fact <- gl(5,10,labels=LETTERS[1:5])
# A matrix of contrasts with all possible pairwise comparisons
mat.cont(levels(fact))
# A matrix with only comparisons to level "A"
mat.cont(levels(fact),ref="A")
# A matrix with all pairwise comparisons between "A", "B" and "E"
mat.cont(levels(fact),restrict=c("A","B","E"))
# The same with levels "C" and "D" excluded
mat.cont(levels(fact),restrict=c("A","B","E"),exclude=TRUE)
# With an interaction between two factors
fact2 <- gl(2,25,labels=letters[1:2])
mat.cont(levels(fact:fact2))
# With an interaction between a factor and a covariate
covar <- runif(50,10,20)
lev <- paste("covar:fact",levels(fact),sep="")
mat.cont(lev)
Run the code above in your browser using DataLab