Entering edit mode
9.5 years ago
madkitty
▴
690
I have 6 batches (10 samples in each) from 6 arrays that we want to normalize for batch effect with Combat. When I run the script below, I encounter an error, any idea how to fix this?
I'm editing the current code with all modification and current error message that I get.
library(sva)
dat = read.csv("Combat_matrix_input.csv");
sif = read.csv("sif.csv");
batch = sif$Batch
head(batch)
[1] Batch1 Batch1 Batch1 Batch1 Batch1 Batch1
Levels: Batch1 Batch2 Batch3 Batch4 Batch5 Batch6
modcombat = model.matrix(~1, data=dat)
dat <- as.matrix(dat)
combat_edata = ComBat(dat=dat, batch=batch, mod=modcombat, par.prior=TRUE, prior.plots=FALSE)
Found 6 batches
Error in cbind(batchmod, mod) :
number of rows of matrices must match (see arg 2)
# Here I'm trying with batch as.vector
batch = as.vector(sif$Batch)
combat_edata = ComBat(dat=dat, batch=batch, mod=modcombat, par.prior=TRUE, prior.plots=FALSE)
Found 6 batches
Error in cbind(batchmod, mod) :
number of rows of matrices must match (see arg 2)
Here I display the output of column Batch
in sif
# I tried both batch as.vector as you guys recommended
batch = as.vector(sif$Batch)
batch = sif$Batch
# Both batch as.vector or regular variable return the error in combat before, and return the same head()
head(sif$Batch)
[1] Batch1 Batch1 Batch1 Batch1 Batch1 Batch1
Levels: Batch1 Batch2 Batch3 Batch4 Batch5 Batch6
Can you show us the output of
@andrew.j.skelton73: I updated the original post with the output of
head(sif$Batch)
. Thanks :)Will
as.vector(sif$Batch)
help?Just found my script. This was what I did with ComBat
I was trying to merge RNA Seq data with microarray.
mydata
is my microarray data andvsd
is my RNA-Seq data whereas data.input is the merge data frameThanks Sam, though in our case we only have genes in rows and samples in columns. The sample info file contains only array, sample_name and batch. Without any condition, how should I write mod? I don't understand what should go under
~as.factor()
@Sam: I tried that
Unfortunately the result is the same..
According to page 6 of the user manual,
The deviation of this code and yours is that instead of
data=pheno
, you usedata=dat
. If you look at my example script, you should note that thepheno
is the phenotype matrix. What I suspect is the data in the mod should contain the phenotype and the batch instead of the count table. try and see ifsolves the problem? That's just my guess though
Hi Sam, Thanks again for your answer. When replacing for data=sif in modcombat, I get another type of error (see below). The manual isn't useful at all .. I'm really desperate to find a solution :(
Can you show us how your
sif
looks like?Actually, I gave it another try, and indeed your suggestions worked well. Just for those wondering, the manual isn't clear, MOD should contain SAMPLE INFO FILE and COVARIATE information as a data.frame. Thanks Sam!
Good to know that it works