[R] limma contrast matrix

Patrick Breheny patrick.breheny at uky.edu
Thu Aug 4 16:33:47 CEST 2011


On 08/04/2011 08:53 AM, Belmont, John W wrote:
> I am trying to correct for the effect of 2 covariates in a gene
> expression data set.
>
> design<-model.matrix(~0 + Factor + cov1 + cov2)
>
>
> QUESTION: How to set up the contrast matrix?
>
> The usual commands
>
> fit <- lmFit(selDataMatrix, design)
> cont.matrix <- makeContrasts(FacCont=Group1-Group2, levels=design)
> fit2 <- contrasts.fit(fit, cont.matrix)
>
> does not work because the original design matrix includes the
> covariates.
>
> I think I don't really understand how the contrast matrix works.

1) Unless you are sure you know what you're doing and have given this a 
lot of thought, I doubt you want to remove the intercept in this model.

2) A contrast specifies the coefficients of the linear combination of 
parameters that you wish to estimate/test.  If you don't know what this 
means, then I would advise learning more about regression or consulting 
a statistician before proceeding.

3) If the first two comments haven't scared you off, then you can 
specify contrasts via:

cont.matrix <- matrix(c(-1,1,0,0),ncol=1)

under the original parameterization, or

cont.matrix <- matrix(c(0,1,0,0),ncol=1)

if you take the advice of point 1) and put an intercept in your model.

-- 
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky



More information about the R-help mailing list