Entering edit mode
Djie Tjwan Thung
▴
90
@djie-tjwan-thung-5053
Last seen 10.2 years ago
Dear list and authors of SVA / ComBat,
I might have stumbled upon a little bug in the ComBat function:
ComBat(dat, batch, mod, numCovs=NULL,
par.prior=TRUE,prior.plots=FALSE)
mod should contain a model matrix for variables for outcome of
interest and
other covariates besides batch, including numerical covariates.
However it seems that all numerical covariates should be in the last
columns of the model matrix and all categorical covariates in the
first
columns of the model matrix.
For example:
mod <- model.matrix(~as.factor(pheno$gender) + pheno$age) #using this
mod
variable as argument to ComBat works
modSwitch <- model.matrix(~pheno$age + as.factor(pheno$gender)) #using
this
modSwitch variable as argument to ComBat doesn't work:
Error in solve.default(t(design) %*% design) :
system is computationally singular: reciprocal condition number =
4.60793e-21
I've had a look into the package source files and I think the
design.mat
function contains the problem, regarding this code:
#In this code ncov is number of categorical covariates and mod[,-tmp]
is a
matrix without batch column and without intercept
if(ncov>0){
for (j in 1:ncov){
tmp1 <- as.factor(as.matrix(mod[,-tmp])[,j])
design <- build.design(tmp1,des=design)
}
}
So I guess by looping from 1 till the number of categorical
covariates, you
assume these categorical variables should be at the beginning of the
model
matrix.
Could someone verify this? I'd be willing to give some example data
when
needed.
Maybe the documentation for the ComBat function could be updated by
clearly
stating this or the function could be improved?
Regards,
Djie Thung
Bioinformatics Intern - Dept. of Human Genetics UMC Utrecht
[[alternative HTML version deleted]]