[BioC] removeBatchEffect problem

James W. MacDonald jmacdon at med.umich.edu
Thu Oct 20 15:33:01 CEST 2011


Hi John,

On 10/20/2011 6:42 AM, John Coulthard wrote:
> Hi
>
> I'm having troubles with the removeBatchEffect function.  It seems that whatever I put in as the 'design' I get the same result out of removeBatchEffect(); Perhaps I'm not using the right syntax for the 'design'?
>
> Below is each line of the function run individually and the output from the line using 'design' with various inputs; Always the same output?!
>
> My design is 4x2x2; 4 tissues(T) x 2 subgroups(S) x 2 days(D) and the col order in e.qn is...
> T1S1D1, T1S2D1, T1S1D2, T1S2D2, T2S1D1, T2S2D1, T2S1D2, T2S2D2, T3S1D1, T3S2D1, T3S1D2, T3S2D2, T4S1D1, T4S2D1, T4S1D2, T4S2D2,
>
> And it's the day(D) effect I'm trying to remove.
>
>
> Can anyone point me to the right way to run this.
>
> Many thanks
> John
>
> the command I started with...
> e.qn_batch_removed<-removeBatchEffect(e.qn,c(1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2),design=matrix(c(1,2,1,2,3,4,3,4,5,6,5,6,7,8,7,8),16,1))

That isn't the correct design matrix. What you most likely want is

design <- model.matrix(~factor(c(1,2,1,2,3,4,3,4,5,6,5,6,7,8,7,8) ))

Best,

Jim


> then line by line...
>> removeBatchEffect
> function (x, batch, design = matrix(1, ncol(x), 1))
> {
>      x<- as.matrix(x)
>      batch<- as.factor(batch)
>      contrasts(batch)<- contr.sum(levels(batch))
>      X<- model.matrix(~batch)[, -1, drop = FALSE]
>      X<- qr.resid(qr(design), X)
>      qrX<- qr(X)
>      t(qr.resid(qrX, t(x)))
> }
> <environment: namespace:limma>
>
>
>> x<- as.matrix(e.qn)
>> batch<- as.factor(c(1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2))
>> contrasts(batch)<- contr.sum(levels(batch))
>> X<- model.matrix(~batch)[, -1, drop = FALSE]
>> qr.resid(qr(matrix(c(1,2,1,2,3,4,3,4,5,6,5,6,7,8,7,8),16,1)), X)
>     batch1
> 1       1
> 2       1
> 3      -1
> 4      -1
> 5       1
> 6       1
> 7      -1
> 8      -1
> 9       1
> 10      1
> 11     -1
> 12     -1
> 13      1
> 14      1
> 15     -1
> 16     -1
>> qr.resid(qr(matrix(c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2),16,1)), X)
>     batch1
> 1       1
> 2       1
> 3      -1
> 4      -1
> 5       1
> 6       1
> 7      -1
> 8      -1
> 9       1
> 10      1
> 11     -1
> 12     -1
> 13      1
> 14      1
> 15     -1
> 16     -1
>> qr.resid(qr(matrix(1,16,1)), X)
>     batch1
> 1       1
> 2       1
> 3      -1
> 4      -1
> 5       1
> 6       1
> 7      -1
> 8      -1
> 9       1
> 10      1
> 11     -1
> 12     -1
> 13      1
> 14      1
> 15     -1
> 16     -1
>
>   		 	   		
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
James W. MacDonald, M.S.
Biostatistician
Douglas Lab
University of Michigan
Department of Human Genetics
5912 Buhl
1241 E. Catherine St.
Ann Arbor MI 48109-5618
734-615-7826

**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues 



More information about the Bioconductor mailing list