Answers.Body: <ol>
  <li>Yes, though thankfully Your 2018 PreD samples will help you resolve this.</li>
  <li>Simply add the batch effect to the design (<code>~Batch + Treatment</code>) and DESeq2 (or edgeR or Limma) will handle this for you.</li>
  </ol>
  
  <p>You do not need SVA or RUV, thankfully, since you quite cleverly sequenced one group in both batches.</p>
  
  <p>To clarify, your coldata will be something like:</p>
  
  <pre><code>Group    Time    Batch
  A        Pre     A
  A        Pre     A
  A        Pre     A
  A        Post    B
  A        Post    B
  A        Post    B
  ...
  D        Pre     A
  D        Pre     A
  D        Pre     A
  D        Pre     B
  D        Pre     B
  D        Pre     B
  </code></pre>
  
  <p>And the design is actually <code>~Batch + Group + Time</code>. You can probably add an interaction term in if you then modify the model matrix manually to ensure it's full rank.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-28T09:28:17.600Z
Answers.Text: Thanks. PreA vs PostA, involve no "PreD" at all. How should I address it? "PreD" is a sample name, not like a factor like `as.factor(c("2017", "2018"))`.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-28T09:32:56.347Z
Answers.Text: You're really interested in the `A:Post` interaction. If you phrase it and think of it that way the model matrix is easier to construct (see my update to get you started).
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-28T09:19:59.287Z
Answers.LastActivityDate: 2018-11-28T09:31:30.483Z
Answers.LastEditDate: 2018-11-28T09:31:30.483Z
Answers.UserDisplayName: Devon Ryan
Body: <p>Let's say I have an RNA-Seq experiment, where I'm interested in the significantly differentiated genes between pre-treatment and post-treatment conditions. "rep" == biological replicate.</p>
  
  <pre><code>Sample PreA (3 reps **all** in 2017) vs Sample PostA (3 reps **all** in 2018) 
  Sample PreB (3 reps **all** in 2017) vs Sample PostB (3 reps **all** in 2018) 
  Sample PreC (3 reps **all** in 2017) vs Sample PostC (3 reps **all** in 2018) 
  </code></pre>
  
  <p>I also have a sample:</p>
  
  <pre><code>Sample PreD (3 reps all in 2017) and Sample PreD (3 reps again in 2018)
  </code></pre>
  
  <p>It is safe to assume the samples in sequenced in 2017 were done differently to 2018.</p>
  
  <p><strong>Q1:</strong> Is there problem with batch effects in my study? When I do a test, there should't be any way to split variation from batch effects and biological variation?</p>
  
  <p><strong>Q2:</strong> If Q1 is correct. How should I reduce batch effects?</p>
  
  <ul>
  <li>Can I add a batch factor to my model in DESeq2/edgeR?</li>
  <li>Should I use my <code>PreD</code> control samples to derive normalisation factor as in RUV? (assume PreD as a negative control)</li>
  <li>Should I use <code>sva</code> package?</li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>Devon suggested for adding a batch variable, but how? That's how I'm doing (ignoring batch effects):</p>
  
  <pre><code>dds &lt;- DESeqDataSetFromTximport(txi, data, ~Sample)
  </code></pre>
  
  <p><code>data</code> holds a data frame with a <code>Sample</code> column. <code>Sample</code> would be "PreA" and "PostA" in the first test. Very simple.</p>
  
  <p>I couldn't add <code>Date</code> to it, like:</p>
  
  <pre><code>dds &lt;- DESeqDataSetFromTximport(txi, data, ~Date + Sample)
  </code></pre>
  
  <p>because the code crashed complaining of the 2017/2018 problem discussed above. I'm not sure how I should add <code>PreD</code> to the design.</p>
  
Tags: <rna-seq><bioconductor><batch-effects>
Title: How should I address batch effects in my experiment?
ThreadText: # How should I address batch effects in my experiment?
  
  (Asked by: username_0 on 2018-11-28)
  
  Let's say I have an RNA-Seq experiment, where I'm interested in the significantly differentiated genes between pre-treatment and post-treatment conditions. "rep" == biological replicate.
  
  ```
  Sample PreA (3 reps **all** in 2017) vs Sample PostA (3 reps **all** in 2018) 
  Sample PreB (3 reps **all** in 2017) vs Sample PostB (3 reps **all** in 2018) 
  Sample PreC (3 reps **all** in 2017) vs Sample PostC (3 reps **all** in 2018) 
  
  ```
  
  I also have a sample:
  
  ```
  Sample PreD (3 reps all in 2017) and Sample PreD (3 reps again in 2018)
  
  ```
  
  It is safe to assume the samples in sequenced in 2017 were done differently to 2018.
  
  **Q1:** Is there problem with batch effects in my study? When I do a test, there should't be any way to split variation from batch effects and biological variation?
  
  **Q2:** If Q1 is correct. How should I reduce batch effects?
  
  * Can I add a batch factor to my model in DESeq2/edgeR?
  * Should I use my `PreD` control samples to derive normalisation factor as in RUV? (assume PreD as a negative control)
  * Should I use `sva` package?
  
  **EDIT**
  
  username_1 suggested for adding a batch variable, but how? That's how I'm doing (ignoring batch effects):
  
  ```
  dds <- DESeqDataSetFromTximport(txi, data, ~Sample)
  
  ```
  
  `data` holds a data frame with a `Sample` column. `Sample` would be "PreA" and "PostA" in the first test. Very simple.
  
  I couldn't add `Date` to it, like:
  
  ```
  dds <- DESeqDataSetFromTximport(txi, data, ~Date + Sample)
  
  ```
  
  because the code crashed complaining of the 2017/2018 problem discussed above. I'm not sure how I should add `PreD` to the design.
  
  **Tags:** rna-seq, bioconductor, batch-effects
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-28. Score: 4
  
  1. Yes, though thankfully Your 2018 PreD samples will help you resolve this.
  2. Simply add the batch effect to the design (`~Batch + Treatment`) and DESeq2 (or edgeR or Limma) will handle this for you.
  
  You do not need SVA or RUV, thankfully, since you quite cleverly sequenced one group in both batches.
  
  To clarify, your coldata will be something like:
  
  ```
  Group    Time    Batch
  A        Pre     A
  A        Pre     A
  A        Pre     A
  A        Post    B
  A        Post    B
  A        Post    B
  ...
  D        Pre     A
  D        Pre     A
  D        Pre     A
  D        Pre     B
  D        Pre     B
  D        Pre     B
  
  ```
  
  And the design is actually `~Batch + Group + Time`. You can probably add an interaction term in if you then modify the model matrix manually to ensure it's full rank.
  
  > **Comments:**
  > **username_0**: Thanks. PreA vs PostA, involve no "PreD" at all. How should I address it? "PreD" is a sample name, not like a factor like `as.factor(c("2017", "2018"))`.  
  > **username_1**: You're really interested in the `A:Post` interaction. If you phrase it and think of it that way the model matrix is easier to construct (see my update to get you started).  
  
  ---
  
  