text: user2005: 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.  
  
  user48: 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 <- corpcor::fast.svd(t(scale(t(dat), center = TRUE, scale = TRUE)))
  pcSds <- s$d
  pcSds[1] <- 0
  svdexp <- s$u %*% diag(pcSds) %*% t(s$v)
  colnames(svdexp) <- 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. 
  
original_text: 2005: <p>I ran <code>SVA</code> to remove batch effects for my <code>bulk RNAseq</code> experiments, but now I need to somehow correct my data matrix in order to run <code>pca</code>, <code>mds</code>. I am using <code>DESeq2</code> for the analysis. Here is the code that I got now:</p>
  
  <pre><code>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<span class="math-container">$SV1 = svseq$</span>sv[,1]
  design(dds_sva) = ~ SV1 + Group
  dds_sva = DESeq(dds_sva)
  </code></pre>
  
  <p>So, I am wondering now, how to use <code>svseq</code> object to plot, say, the corrected version of <code>MDS plot</code>.  </p>
   48: <p>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 <a href="http://llrs.github.io/IEO/IEO_report.html#removing_batch_effect_with_svd" rel="nofollow noreferrer">here</a> is an example how to do it:</p>
  
  <pre><code>library("corpcor")
  s &lt;- corpcor::fast.svd(t(scale(t(dat), center = TRUE, scale = TRUE)))
  pcSds &lt;- s<span class="math-container">$d
  pcSds[1] &lt;- 0
  svdexp &lt;- s$</span>u %*% diag(pcSds) %*% t(s$v)
  colnames(svdexp) &lt;- colnames(dat)
  </code></pre>
  
  <p>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. </p>
  