EdgeR and contrasts: How to compare with a group not in the model
1
1
Entering edit mode
3.8 years ago
13530213 ▴ 10

Hi all, I am struggling to make a contrast with EdgeR.

design <- model.matrix(~Gender + Age + Group, data = patient.table)

The (disease) Group is a factor with [Control, Mild, Severe]. I want to compare C-M. M-S and C-S. Thus s i

DGEL <- edgeR::DGEList(expressionData)
keep <- edgeR::filterByExpr(DGEL)
DGEL <- DGEL[keep, , keep.lib.sizes=FALSE]
DGEL <- edgeR::calcNormFactors(DGEL, method = "TMM")

DGEL <- edgeR::estimateDisp(DGEL, design)
fit  <- edgeR::glmQLFit(DGEL, design)

contrasts <- makeContrasts(c.vs.m  = GroupC - GroupM,
                           m.vs.s  = GroupM - GroupS,
                           c.vs.s  = GroupC - GroupS,
                           levels  = design)

However, there is no GroupC in the model matrix. There is only an Intercept, GroupM and GroupS. How can I compare anything against the control group on a full-rank design matrix.

I already searched in the user manual and here on the website, but could not find it. Also, I tried

design <- model.matrix(~Gender + Age + Group,
    data = patient.table,
    contrasts.arg = list(
      Group = contrasts(patient.table$Group, contrasts = FALSE)
    )
  )

But edgeR did not like that and informed me that the table was not of full rank. I am pretty sure this is something basic, but I just don't get it as a wet-lab worker.

rna-seq R model.matrix makeContrasts edgeR • 3.2k views
ADD COMMENT
3
Entering edit mode
3.8 years ago
h.mon 35k

Check edgeR Users Guide, chapter 3.3, on how to define the contrasts for such a complex design. For me, the approach that works better (as in, it is easier to understand) is the one described in section 3.3.1. Start by creating a composite group variable:

group <- factor( paste0( patient.table$Gender, paste0( patient.table$Age, patient.table$Group ) )

Then specify the design without an intercept, and create the contrasts of interest.

design <- model.matrix( ~0 + group )
colnames( design ) <- levels( group )
contrasts <- makeContrasts( GenderM_Age0_GroupC_vs_M = GenderMAge0GroupC - GenderMAge0GroupM,
# and so on for the other contrasts
                            levels=design)

To perform the tests:

fit <- glmQLFit( DGEL, design )
qlf <- glmQLFTest( fit, contrast = contrastss[ , "GenderM_Age0_GroupC_vs_M" ] )

This tests for GroupC vs GroupM differences within GenderM and Age0.

See Which is the best approach to get DEG across one condition, in a three-factor design experiment? for a recent similar post, you may find the answer there useful.

If you want more complex tests, such as any genes changing over all ages, read sections 3.3.3 and 3.3.4 from the guide.

ADD COMMENT
0
Entering edit mode

Hey @h.mon, thanks for the reply. Is it correct that if I only have GroupM and GroupS, that just filling in GroupM or GroupS would be a comparison of the group agains baseline (groupC) ?

ADD REPLY
0
Entering edit mode

No, not when you set the intercept to zero.

Even if the intercept isn't set to zero, one needs (I certainly need) to examine the design and contrasts carefully to understand which comparisons are being made.

ADD REPLY
0
Entering edit mode

Ok, so... Making a design and then comparing COEFs is probably the hardest thing in EdgeR or DE in general. Up to now. I changed my code slightly;

design <- model.matrix(~0 + Group + Gender + Age, data = master.table)

This makes it so that the design has all the groups that I want to compare. Then I use the makeContrasts and glmQLFTest functions to get the result I want (was also incorrect):

contrasts <- makeContrasts(c.vs.s = GroupS - GroupC, m.vs.s = GroupS - GroupM, c.vs.m  = GroupM- GroupC,  levels = design)
fit.hc.vs.seo <- glmQLFTest(fit, contrast = contrasts[,"c.vs.s"])
ADD REPLY

Login before adding your answer.

Traffic: 2601 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