The joys of linear algebra :)
Is there a way to output a gene expression matrix corrected for batch (I know I can use ComBat) and surrogate variables from SVA? I would like to visualize the results of a limma differential expression however they are confounded and thus not amenable to visualization.
3 answers
If you have:
yas the gene expresion matrixmodas the model matrix you sent to sva (the full model)svsas svobj$sv where svobj is the output from the sva function
then you can use the function below to get a "cleaned" version of the matrix with the surrogate variables removed.
cleanY = function(y, mod, svs) {
X = cbind(mod, svs)
Hat = solve(t(X) %*% X) %*% t(X)
beta = (Hat %*% t(y))
rm(Hat)
gc()
P = ncol(mod)
return(y - t(as.matrix(X[,-c(1:P)]) %*% beta[-c(1:P),]))
}
I modified this from a post by Andrew Jaffe here.
It is not recommended that you perform differential expression analysis after data cleaning - the resulting degrees of freedom will be wrong. The best thing to do is include the svs as covariates in downstream linear models in limma etc. as adjustment models.
- Jeff (co-developer of sva)
Dear Jeff, is it correct to perform a Gene regulatory network (GRN) analysis after the data cleaning with the function mentioned before?
With Jeff's answer in mind, if you just want to remove the effect of batch variables for visualisation (e.g. heatmap, PCA), the limma function removeBatchEffect() can be used for that purpose.
Hello, could you be more clear? why just for visualization? are you saying that the Limma corrected dataset cannot be used for other purposes?
Take a look at ?limma::removeBatchEffect for details of other uses of the processed dataset. For differential expression it is better to use the original dataset and add batch as covariate, as indicated in @jtleek's answer.
Log in to answer this question.