How to get the corrected matrix after SVA batch effect correction I ran SVA to remove batch effects for my bulk RNAseq experiments, but now I need to somehow correct my data matrix in order to run pca, mds. I am using DESeq2 for the analysis. Here is the code that I got now:

dds &lt;- estimateSizeFactors(dds)
dat = counts(dds, normalized = TRUE)
idx = rowMeans(dat) &gt; 1
dat = dat[idx,]
mod = model.matrix(~Group, colData(dds))
mod0 = model.matrix(~1, colData(dds))

nsv = num.sv(dat, mod)
svseq = svaseq(dat, mod, mod0, n.sv = nsv)

dds_sva = dds
dds_sva$SV1 = svseq$sv[,1]
design(dds_sva) = ~ SV1 + Group
dds_sva = DESeq(dds_sva)


So, I am wondering now, how to use svseq object to plot, say, the corrected version of MDS plot.
If you want to plot the "corrected" expression, you will need to remove the variation introduced by these surrogate variables. Removing the expression affected can introduce some bias too and it is usually not recommended (despite comBat doing so). You should apply linear algebra, you can look at here is an example how to do it:

library("corpcor")
s &lt;- corpcor::fast.svd(t(scale(t(dat), center = TRUE, scale = TRUE)))
pcSds &lt;- s$d
pcSds[1] &lt;- 0
svdexp &lt;- s$u %*% diag(pcSds) %*% t(s$v)
colnames(svdexp) &lt;- colnames(dat)


But if your surrogate variables do have a big enough influence on your MDS plot to be observable (IMHO) there would be too much batch effect to work with the data.