I need your help with this please. I would like to design a limma model to analyze some RNA seq data. I have got four sample groups (A,B,C,D) and am particular interested in lets say group B. I am interested in a sort of intercept model, in which B is compared to all other groups each one time as an intercept. For example:
If I design an intercept model like this:
modelMatrix <- model.matrix(~ groups, data = samples)
B is different from the intercept A, while C is not different to intercept A AND while D is not different to intercept A. Graphical output for a gene would look like this (I hope that makes sense.., star is significant difference to intercept (). Underscore is the average gene expression of that group, here upregulated compared to intercept):
_____________
B_*
(A)_ C_ D_
_____________
Numerical output:
(A) B C D
0 1 0 0
_____________
Then I could write the respective contrasts with this model, but I would also like to know which genes are DE when C would be intercept and D would be intercept. Like this here:
C is different from the intercept A, while D is not different to intercept A AND while B is not different to intercept A.
D is different from the intercept A, while B is not different to intercept A AND while C is not different to intercept A.
_____________
B_*
(A)_ C_ D_
_____________
(A) B C D
0 1 0 0
_____________
_____________
B_*
A_ (C)_ D_
_____________
A B (C) D
0 1 0 0
_____________
_____________
B_*
A_ C_ (D)_
_____________
A B C (D)
0 1 0 0
_____________
If I design my model with group B as the intercept then I get the following, which I dont want.
samples$groups <- factor(samples$groups,
levels = c("B", "A", "C", "D"))
modelMatrix <- model.matrix(~ groups, data = samples)
_____________
A_*
(B)_ C_ D_
_____________
(B) A C D
0 1 0 0
_____________
_____________
C_*
(B)_ A_ D_
_____________
(B) A C D
0 0 1 0
_____________
_____________
D_*
(B)_ A_ C_
_____________
(B) A C D
0 0 0 1
_____________
When I write a model without intercept and fit a contrast like this one: design <- model.matrix(~0 + group, data = samples)
cont.matrix <- makeContrasts(B.vs.A = B - A, B.vs.C = B - C, B.vs.D = B - D, levels=design)
cont.matrix
I get the same thing as the model with B as intercept, which I also dont want.
How do I have to write the contrasts please so that I can compare the uniquely DE genes from B compared to each of the other groups? I could write the respective factors three times and then refit the model, like this:
samples$groups <- factor(samples$groups,
levels = c("A", "B", "C", "D"))
modelMatrix1 <- model.matrix(~ groups, data = samples)
#
samples$groups <- factor(samples$groups,
levels = c("C", "B", "A", "D"))
modelMatrix2 <- model.matrix(~ groups, data = samples)
#
samples$groups <- factor(samples$groups,
levels = c("D", "B", "C", "A"))
modelMatrix3 <- model.matrix(~ groups, data = samples)
But I am pretty sure that I dont have to write three models with three different intercepts and only take one comparison from each. Cant figure it out at the moment how to write the contrasts with the different intercepts/references.
Many thanks for your input!
contrasts.fit
is preferable to refitting, as the latter does a lot of redundant work. In theory, the two methods are identical, but read theNote:
in?contrasts.fit
for the small practical differences.