Question: EdgeR and contrasts: How to compare with a group not in the model
1
gravatar for 13530213
7 weeks ago by
1353021310
1353021310 wrote:

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.

ADD COMMENTlink modified 6 weeks ago • written 7 weeks ago by 1353021310
3
gravatar for h.mon
7 weeks ago by
h.mon31k
Brazil
h.mon31k wrote:

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 COMMENTlink written 7 weeks ago by h.mon31k

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 REPLYlink written 6 weeks ago by 1353021310

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 REPLYlink written 6 weeks ago by h.mon31k

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 REPLYlink written 6 weeks ago by 1353021310
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1737 users visited in the last hour