
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))

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]]

