Answers.Body: <p>The help page for <code>removeBatchEffect()</code> explicitly states that it should not be used in conjunction with differential expression testing, so don't do that. You already have the batch effect included in your model, so you're already correcting for it when testing for differential expression. If your MDS plots suggest that samples are variably affected by the batch effect then look into the <code>combat()</code> function from the <code>sva</code> package.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-25T21:24:38.353Z
Answers.LastActivityDate: 2018-07-25T21:24:38.353Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I am using the R (using EdgeR) for the RNA Seq analysis, I had few batch effect samples like Control vs treatment. Could anyone tell me the best way to remove the batch effects.</p>
  
  <p>I have looked into the cluster dendrogram and MDS post (using EdgeR), the Control and Treatments are not grouping together, and their is differences in the different batch within Control and Treatment. </p>
  
  <p>I tried this syntax to remove the batch effects for the rest of the analysis to get the DE Genelist. I feel it didn't able to remove the batch effects from the rest of the analysis.</p>
  
  <pre class="lang-r prettyprint-override"><code># define the experiment
  Batch &lt;- factor(c(1,2,3,1,2,3))
  Treatment &lt;- factor(c(0,0,0,1,1,1))
  design_noI &lt;- model.matrix(~ 0 + Batch + Treatment)
  
  # define our DGEList
  San &lt;- DGEList(counts=x,genes=gene_info)
  
  A &lt;- aveLogCPM(San)
  y2 &lt;- San[A&gt;1,]
  y2 &lt;- calcNormFactors(y2)
  logCPM &lt;- cpm(y2, log=TRUE, prior.count=5)
  plotMDS(logCPM)
  logCPMR &lt;- removeBatchEffect(y2, Clutch = Clutch)
  plotMDS(logCPMR)
  </code></pre>
  
  <p>I can see the difference in MDS plot on removing the batch effects but I couldn't able to carry the same data flow into my rest of analysis.</p>
  
  <pre class="lang-r prettyprint-override"><code># filter the lowly expresed genes and normalize the data
  keep &lt;- rowSums(cpm(San/logCPMR)&gt;1) &gt;= 3
  keep2 &lt;- removeBatchEffect(keep, Batch)
  y_group &lt;- San/logCPMR[keep2, , keep2.lib.size=FALSE]
  y_group &lt;- calcNormFactors(San/logCPMR)
  </code></pre>
  
  <p>I have mention the <code>San/logCPMR</code>, as <code>San</code> take as data without remove the batch effects, whereas I think <code>logCPMR</code> as batch effected removed data frame.</p>
  
  <p>Any suggestion on this more useful to me.</p>
  
  <p>Please let me know, any other information needed to deal with this batch effects.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-25T20:48:04.757Z
Comments.Text: I am not sure if I understand exactly what you're asking (and what you are doing in  your code). You seem to deviate from edgeR manual for paired or batch effect analysis. Your first 3 lines of code seem okay to me, but then you should fit your data to the model, including your design with batch effect. See 3.4 of edgeR [manual](https://www.bioconductor.org/packages/devel/bioc/vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf). The removeBatchEffect results are only meant for clustering or visualization not the statistical analysis.
Comments.UserDisplayName: benn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-25T20:56:29.097Z
Comments.Text: Thanks b.nota, My point is ...when their is batch effects, shown in MDS plot or  Cluster Dendrogram, re-visualise it by removing batch effects in MDS plot, But could we take the same batch effect removed data for further data analysis to get the DE genelist. As if we don't remove the batch effects from the data, that effects on the final DE genelist, and I get the less number of DE genelist.
Comments.UserDisplayName: San
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-26T10:38:54.233Z
Comments.Text: No you cannot use removeBatchEffect results for DE analysis, follow the guidelines in manual and see answer of Devon.
Comments.UserDisplayName: benn
Tags: <r><rna-seq><edger><batch-effects>
Title: Batch Effects in RNA Seq Sample
ThreadText: # Batch Effects in RNA Seq Sample
  
  (Asked by: username_0 on 2018-07-25)
  
  I am using the R (using EdgeR) for the RNA Seq analysis, I had few batch effect samples like Control vs treatment. Could anyone tell me the best way to remove the batch effects.
  
  I have looked into the cluster dendrogram and MDS post (using EdgeR), the Control and Treatments are not grouping together, and their is differences in the different batch within Control and Treatment.
  
  I tried this syntax to remove the batch effects for the rest of the analysis to get the DE Genelist. I feel it didn't able to remove the batch effects from the rest of the analysis.
  
  ```r
  # define the experiment
  Batch <- factor(c(1,2,3,1,2,3))
  Treatment <- factor(c(0,0,0,1,1,1))
  design_noI <- model.matrix(~ 0 + Batch + Treatment)
  
  # define our DGEList
  San <- DGEList(counts=x,genes=gene_info)
  
  A <- aveLogCPM(San)
  y2 <- San[A>1,]
  y2 <- calcNormFactors(y2)
  logCPM <- cpm(y2, log=TRUE, prior.count=5)
  plotMDS(logCPM)
  logCPMR <- removeBatchEffect(y2, Clutch = Clutch)
  plotMDS(logCPMR)
  
  ```
  
  I can see the difference in MDS plot on removing the batch effects but I couldn't able to carry the same data flow into my rest of analysis.
  
  ```r
  # filter the lowly expresed genes and normalize the data
  keep <- rowSums(cpm(San/logCPMR)>1) >= 3
  keep2 <- removeBatchEffect(keep, Batch)
  y_group <- San/logCPMR[keep2, , keep2.lib.size=FALSE]
  y_group <- calcNormFactors(San/logCPMR)
  
  ```
  
  I have mention the `San/logCPMR`, as `San` take as data without remove the batch effects, whereas I think `logCPMR` as batch effected removed data frame.
  
  Any suggestion on this more useful to me.
  
  Please let me know, any other information needed to deal with this batch effects.
  
  **Tags:** r, rna-seq, edger, batch-effects
  
  > **Comments:**
  > **username_1**: I am not sure if I understand exactly what you're asking (and what you are doing in  your code). You seem to deviate from edgeR manual for paired or batch effect analysis. Your first 3 lines of code seem okay to me, but then you should fit your data to the model, including your design with batch effect. See 3.4 of edgeR [manual](https://www.bioconductor.org/packages/devel/bioc/vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf). The removeBatchEffect results are only meant for clustering or visualization not the statistical analysis.  
  > **username_0**: Thanks b.nota, My point is ...when their is batch effects, shown in MDS plot or  Cluster Dendrogram, re-visualise it by removing batch effects in MDS plot, But could we take the same batch effect removed data for further data analysis to get the DE genelist. As if we don't remove the batch effects from the data, that effects on the final DE genelist, and I get the less number of DE genelist.  
  > **username_1**: No you cannot use removeBatchEffect results for DE analysis, follow the guidelines in manual and see answer of username_2.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-07-25. Score: 3
  
  The help page for `removeBatchEffect()` explicitly states that it should not be used in conjunction with differential expression testing, so don't do that. You already have the batch effect included in your model, so you're already correcting for it when testing for differential expression. If your MDS plots suggest that samples are variably affected by the batch effect then look into the `combat()` function from the `sva` package.
  
  
  ---
  
  