Question: Creating a correct limma model with respect to contrast matrix and design matrix
0
12 months ago by
payam_delfani19800 wrote:

## Could anyone consider the example below and give me a feedback on that?

# Fit many adjusted statistics with limma. Here we adjust for the day effect (a surrogate for a batch effect):

##---------------------

#Covariate of interest:

Condition <- as.factor(pData(ExpressionSet$Condition) #Adjusting variable: Batch <- (pData(ExpressionSet)$Scan_date)

##---------------------

(design_adj <- model.matrix(~0+ Condition + as.factor(Batch))) ##Zero: do not include the intercept

##---------------------

# Fitting the model

##---------------------

# Making all contrasts

# Compute Contrasts from Linear Model Fit:

##---------------------

# call eBayes

##---------------------

# Write all results:

quote = FALSE, sep = "\t", row.names = TRUE,col.names=NA)

modified 12 months ago by Aaron Lun24k • written 12 months ago by payam_delfani19800
Answer: Creating a correct limma model with respect to contrast matrix and design matrix
3
12 months ago by
Aaron Lun24k
Cambridge, United Kingdom
Aaron Lun24k wrote:

I don't know where you got makeAllContrasts from, that's not a limma function. I assume that you're using the function from the EMA package, but I can't say that it's giving you what you want. I would do it manually:

# Making up an example design.
Cond <- gl(4, 4)
Batch <- factor(rep(1:4, 4))
design <- model.matrix(~0 + Cond + Batch)

# Making a contrast for each pairwise comparison.
cont.set <- list()
for (i in seq_len(nlevels(Cond))) {
for (j in seq_len(i-1L)) {
new.cont <- integer(ncol(design))
new.cont[i] <- 1
new.cont[j] <- -1
cont.set <- c(cont.set, list(new.cont))
}
}
cont.mat <- do.call(cbind, cont.set)


... and use that in contrasts.fit.

Dear Aaron,

I compared the approach you suggested here to that of the makeAllContrasts from EMA package, and can say that both method generate same outputs. However, the advantage of makeAllContrasts is that it creates the contrasts while keeping the original name of annotations.