I have trouble figuring out how to set up contrasts for a linear model with interaction terms.
In the following example, how do I construct contrasts so that I test for the differences of species A - tissue 1 Vs the mean of everything else (rows 1 and 2 from the matrix should be the topmost ranked)?
I know it can be done through the design matrix, but am wondering whether it is possible to do it using a contrast matrix.
library(limma)
set.seed(10)
d = matrix(rnorm(80, 3), ncol=8)
n=100
d[1:2,1:2] = d[1:2,1:2] + n/2
d[3:4,3:4] = d[3:4,3:4] + n/2
d[3:4,5:6] = d[3:4,5:6] + n
d[7:8,7:8] = d[7:8,7:8] + n
d[9:10,1:4] = d[9:10,1:4] + n
d = log2(d)
dat = data.frame(species=rep(c('A','B'), each=4),
tissue=rep(rep(c('T1','T2'),each=2), times=2))
colnames(d) = with(dat, paste(species, tissue, sep='.'))
design = model.matrix(~0 + species + tissue + species:tissue , data = dat)
colnames(design) = sub(':','.',colnames(design))
fit = lmFit(d, design)
cont.mat = ?
fit2 =
fit = eBayes(contrasts.fit(fit,cont.mat))res=topTable(fit2, sort.by="p")
This question is a crosspost from other stacks, but nobody has still answered.
Tnx!
Edit: after a note, I added log2(d)
Dear Aaron,
Thank you so much for your explanation!
I added the log2 transformation into the data.
Dear Aaron,
Thank you so much for your explanation!
I added the log2 transformation into the data.
You also need to run
eBayes
onfit2
after runningcontrasts.fit
.