[BioC] makeContrasts in limma

He, Yiwen (NIH/CIT) heyiwen at mail.nih.gov
Tue Jun 7 00:22:11 CEST 2005


Hi, 
In limma, what is the best way to automatically generate a contrast matrix
with all possible pairs? For example, if I have 4 groups, is there a way to
generate the matrix with 6 columns each corresponding to a pair-wise
comparison, other than having to specify the 6 expressions explicitly when
calling makeContrasts?

I tried to first create a vector with those expressions and use that in
makeContrasts:

> pair<-c()
> ind<-1
> for (i in 2:numg){
+ for (j in i:numg) {
+ pair[ind] <- paste(groupname[j], "-", groupname[(j-i+1)])
+ ind<- ind+1}}
> pair
[1] "GroupB - GroupA" "GroupC - GroupB" "GroupC - GroupA"

> makeContrasts(pair, levels=design)
       pair             
GroupA "GroupB - GroupA"
GroupB "GroupC - GroupB"
GroupC "GroupC - GroupA"

A related problem: I noticed that expressions have to be separated by comma.
However, even when I tried:

> makeContrasts(pair[1], levels=design)
       pair[1]          
GroupA "GroupB - GroupA"
GroupB "GroupB - GroupA"
GroupC "GroupB - GroupA"

Compare to the result by doing:
> pair[1]
[1] "GroupB - GroupA"
> makeContrasts("GroupB - GroupA", levels=design)
       GroupB - GroupA
GroupA              -1
GroupB               1
GroupC               0

The help page says:
"...: expressions, or character strings which can be parsed to expressions"

But my string doesn't seem to be converted.

Any suggestions? Will it be more convenient to use if the ... argument is a
vector of expressions or something similar?

Thank you, Yiwen
NIH/CIT



More information about the Bioconductor mailing list