Answers.Body: <p>If your strain and batch are confounded, (like you did all of strain one on one day, and all of strain two on another), then there is no clever way to fix that.  Just use one column, and inform whomever designed the experiment that you can't separate batch effect from strain difference.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-22T22:39:24.693Z
Answers.LastActivityDate: 2018-10-22T23:25:35.040Z
Answers.LastEditDate: 2018-10-22T23:25:35.040Z
Answers.UserDisplayName: swbarnes2
Answers.Body: <p>Provide rank sufficient design to <code>DESeqDataSetFromMatrix</code> and then use your custom model matrix in <code>DESeq</code>. In essence:</p>
  
  <pre><code>dds = DESeqDataSetFromMatric(counts, s2c, design=~batch)
  design &lt;- model.matrix(~strain+batch, s2c)
  design = design[, -9]
  DESeq(dds, full=design)
  </code></pre>
  
  <p>See <a href="https://support.bioconductor.org/p/64480/" rel="nofollow noreferrer">this thread</a> on the bioconductor site for details.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-24T17:32:11.120Z
Answers.LastActivityDate: 2017-08-24T17:32:11.120Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I'm trying to run a differential gene expression analysis using DESeq2, with counts coming from kallisto. I have imported them using tximport and I'm creating the <code>DESeqDataSet</code> (dds) using the <code>DESeqDataSetFromMatrix</code> function.</p>
  
  <pre><code>&gt; dds &lt;- DESeqDataSetFromMatrix(counts,
                                  samples,
                                  ~ strain + batch)
  </code></pre>
  
  <p>And I get the following error, expected given my experimental design:</p>
  
  <pre><code>Error in checkFullRank(modelMatrix) :
    the model matrix is not full rank, so the model cannot be fit as specified.
    One or more variables or interaction terms in the design formula are linear
    combinations of the others and must be removed.
  </code></pre>
  
  <p>Now, I know that I can just remove one column from the design matrix to make it work, but is there a way to supply my own design matrix to DESeq2? The following code raises an error:</p>
  
  <pre><code>&gt; design &lt;- model.matrix(~strain+batch, s2c)
  &gt; design = design[, -9] # removing a column to avoid full-rank
  &gt; dds &lt;- DESeqDataSetFromMatrix(counts, s2c, design=design)
  converting counts to integer mode
  Error: $ operator is invalid for atomic vectors
  </code></pre>
  
  <p>Is there a way to provide my own <code>model.matrix</code>?</p>
  
  <p>p.s. the modified model works in sleuth, but I would like to use DESeq2 for this particular analysis.</p>
  
Tags: <rna-seq><deseq2>
Title: Is it possible to create a DESeqDataSet with a user-provided design matrix?
ThreadText: # Is it possible to create a DESeqDataSet with a user-provided design matrix?
  
  (Asked by: username_0 on 2017-08-24)
  
  I'm trying to run a differential gene expression analysis using DESeq2, with counts coming from kallisto. I have imported them using tximport and I'm creating the `DESeqDataSet` (dds) using the `DESeqDataSetFromMatrix` function.
  
  ```
  > dds <- DESeqDataSetFromMatrix(counts,
                                  samples,
                                  ~ strain + batch)
  
  ```
  
  And I get the following error, expected given my experimental design:
  
  ```
  Error in checkFullRank(modelMatrix) :
    the model matrix is not full rank, so the model cannot be fit as specified.
    One or more variables or interaction terms in the design formula are linear
    combinations of the others and must be removed.
  
  ```
  
  Now, I know that I can just remove one column from the design matrix to make it work, but is there a way to supply my own design matrix to DESeq2? The following code raises an error:
  
  ```
  > design <- model.matrix(~strain+batch, s2c)
  > design = design[, -9] # removing a column to avoid full-rank
  > dds <- DESeqDataSetFromMatrix(counts, s2c, design=design)
  converting counts to integer mode
  Error: $ operator is invalid for atomic vectors
  
  ```
  
  Is there a way to provide my own `model.matrix`?
  
  p.s. the modified model works in sleuth, but I would like to use DESeq2 for this particular analysis.
  
  **Tags:** rna-seq, deseq2
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-08-24. Score: 4 | Accepted answer
  
  Provide rank sufficient design to `DESeqDataSetFromMatrix` and then use your custom model matrix in `DESeq`. In essence:
  
  ```
  dds = DESeqDataSetFromMatric(counts, s2c, design=~batch)
  design <- model.matrix(~strain+batch, s2c)
  design = design[, -9]
  DESeq(dds, full=design)
  
  ```
  
  See [this thread](https://support.bioconductor.org/p/64480/) on the bioconductor site for details.
  
  
  ---
  
  ### Answer by username_1 on 2018-10-22. Score: 1
  
  If your strain and batch are confounded, (like you did all of strain one on one day, and all of strain two on another), then there is no clever way to fix that. Just use one column, and inform whomever designed the experiment that you can't separate batch effect from strain difference.
  
  
  ---
  
  