# 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 <- estimateSizeFactors(dds)
dat = counts(dds, normalized = TRUE)
idx = rowMeans(dat) > 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.

library("corpcor")
pcSds <- s$$d pcSds[1] <- 0 svdexp <- s$$u %*% diag(pcSds) %*% t(s\$v)