limma - contrast.fit returns coefficients without names
1
0
Entering edit mode
wewolski ▴ 10
@wewolski-8499
Last seen 2.3 years ago
Zurich

I have the following code:

fit <- lmFit(intmat , designMatrix)

tmpfit <- fit[,-1]

lmfit.cont <- contrasts.fit(fit[,-1], cont[-1,2])

lmfitebayes <- eBayes(lmfit.cont)​

topTable(lmfitebayes, coef=name, number=Inf)

Which fails when executing topTable sometimes. Thats because contrast.fit in some cases prefers not to give a name to the coefficients (see below). It does not give the name if only a single contrast is being computed. If I than want to execute topTable and specify the name of the contrast "A - B" although usually it works.  Still, it would be nice to have the name because: being explicit somehow is more explicit than implicit, and being consistent is more consistent compared to having names once and not having them other times. 

 

> head(lmfit.cont$coefficients)
                 [,1]
A0A075B6P5 -0.6597603
A0A075B6S5 -0.3231210
A0A087WSY6 -0.1133279
A0A0B4J1V0 -0.1568641
A0A0B4J1V6  0.3889539
A0A0B4J2D9 -1.6330590

limma • 2.5k views
ADD COMMENT
2
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 3 hours ago
The city by the bay

Reading ?contrasts.fit should tell you that the contrast matrix should be... a matrix. cont[-1,2] is a vector, which means that the column names are dropped; so any names you have in your original contrast matrix are lost. This may be contributing to your errors, though it's hard to tell because you don't provide an actual reproducible example that other people can run. For example, the code below works well for me:

# setup
intMat <- matrix(rnorm(6000), ncol=6)
groups <- rep(LETTERS[1:3], each=2)
designMatrix <- model.matrix(~0 + groups)
cont <- cbind(AvsB=c(1,-1,0), BvsC=c(0,1,-1))

# limma
library(limma)
fit <- lmFit(intMat, designMatrix)
lmfit.cont <- contrasts.fit(fit[,-1], cont[-1,2,drop=FALSE])
lmfitebayes <- eBayes(lmfit.cont)
topTable(lmfitebayes, coef="BvsC", number=Inf)
ADD COMMENT
0
Entering edit mode

Thank you!

[ ] default behaviour strikes again!

"Omitting drop = FALSE when subsetting matrices and data frames is one of the most common sources of programming errors. (It will work for your test cases, but then someone will pass in a single column data frame and it will fail in an unexpected and unclear way.) " http://adv-r.had.co.nz/Subsetting.html

 

 

ADD REPLY

Login before adding your answer.

Traffic: 691 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6