How to make contrast table to combine two conditions/treatments against another one (in a multi groups experiments
1
0
Entering edit mode
xyliu00 ▴ 20
@xyliu00-8370
Last seen 9.3 years ago
United States

Hi,

Novice users here, with both R in general and bioconductor/limma in particular.

I can perform Affy array data analysis following the tutorials. But I have something too complex for me.

The data set I am working on has multiple groups or treatments. The lab wants to compare between those treatments, which is easy to do. It is also requested to combine groups to a larger one and comparing to another group. 

For example, I have A, B, C, D four groups. A is the control, B, C, D are different treatments or treated for different period time. It is easy for me to make contrast table to compare B, C, D to A separately. 

Now, if B and C are samples treated with the same reagent, but for different period of time, and I need to compare B+C vs A; also C and D have some thing in common, and I need to make a comparison C+D vs B.

How do make the design and contrast matrix to do all of those. Can I include all of these in one matrix, or I need to make multiple matrix?

Sorry for lacking of better description. I am not familiar with all the right terminology. R is quite different for me, coming from more formal programming languages.

Thanks a lot! 

limma design and contrast matrix • 9.8k views
ADD COMMENT
5
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 2 hours ago
The city by the bay

Let's say we have a grouping vector for your samples, like below:

grouping <- c("A", "A", "B", "B", "C", "C", "D", "D")

We use this to construct a design matrix for our experiment:

grouping <- factor(grouping)
design <- model.matrix(~0 + grouping)
colnames(design) <- levels(grouping)

Now, to recapitulate your easy comparisons - if we want to compare between any two groups, say, A and B, we can do something like this (and feed it to contrasts.fit as described in the user's guide):

con <- makeContrasts(A - B, levels=design)

For each gene, the above contrast will test whether the average log-expression for samples of group A is equal to that of group B. For a more complex comparison between, say, B + C against A, we can do something like this:

con.2 <- makeContrasts(A - (B+C)/2, levels=design)

This will test for whether the log-expression of group A is equal to the average of groups B and C. As you can see, the same design matrix is used, so construction of a separate matrix is not necessary. Keep in mind, though, that DE genes from con.2 are not guaranteed to be DE in both A - B and A - C comparisons. Consider a gene that is strongly DE between A and B, yet not DE between A and C. This gene will still be able reject the null in con.2, as the log-expression in A will be different from the average of B and C.

ADD COMMENT
0
Entering edit mode

hi @ Aaron Lun, actually I have done the same thing you suggest here but I am getting an error.

My codes are:

 

> samples <- c(eset1$characteristics, eset$characteristics)
 

> samples <- as.factor(samples)

>samples

>design <- model.matrix(~0 + samples)

>colnames(design) <- c( "TUMOR", "NORMAL")

>design

>levels(samples)

>library(limma)

>fit <- lmFit(filteredEset, design)

>contrast.matrix <- makeContrasts("TUMOR-NORMAL", levels = "samples")

 

Error:  Error in eval(expr, envir, enclos) : object 'TUMOR' not found

ADD REPLY
0
Entering edit mode

A cursory inspection of the user's guide would reveal the correct call:

makeContrasts(TUMOR - NORMAL, levels=design)
ADD REPLY
0
Entering edit mode

als not working

same error.

 

ADD REPLY
0
Entering edit mode

Are you sure you're running the code correctly? Here's an example that works on my machine:

samples <- factor(rep(c("TUMOR", "NORMAL"), each=3))
design <- model.matrix(~0 + samples)
colnames(design) <- levels(samples)
con <- makeContrasts(TUMOR - NORMAL, levels=design)
ADD REPLY

Login before adding your answer.

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