Answers.Body: <p>You can use <code>contrast = c(0.5, 0.5, -0.5, -0.5)</code>, which means "the average of the first two coefficients minus the average of the second two.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-25T11:28:14.030Z
Answers.LastActivityDate: 2019-12-25T11:28:14.030Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I have sample information (sampleinfo) in this format:</p>
  
  <pre><code>SampleID    condition   type
  MP_1    A_1 Paired-End
  MP_2    A_1 Paired-End
  MP_3    A_1 Paired-End
  MN_1    A_2 Paired-End
  MN_2    A_2 Paired-End
  MN_3    A_2 Paired-End
  WP_1    B_1 Paired-End
  WP_2    B_1 Paired-End
  WP_3    B_1 Paired-End
  WN_1    B_2 Paired-End
  WN_2    B_2 Paired-End
  WN_3    B_2 Paired-End
  </code></pre>
  
  <p>I want to compare A_1 with A_2, B_1 with B_2 ans also want to compare (A_1+A_2) with (B_1+B_2).</p>
  
  <p>This is how I used DESeqDataSetFromMatrix</p>
  
  <pre><code>ddsMat &lt;- DESeqDataSetFromMatrix(countData = seqdata[,rownames(sampleinfo)], colData =  sampleinfo, design = ~ condition)
  ddsMat &lt;- DESeq(ddsMat)
  
  res.05_FC0&lt;-results(ddsMat,contrast = c("condition","A_1","A_2"),alpha=0.05,lfcThreshold = 0)
  res.05_FC0&lt;-results(ddsMat,contrast = c("condition","B_1","B_2"),alpha=0.05,lfcThreshold = 0)
  </code></pre>
  
  <p>How can I compare (A_1+A_2) with (B_1+B_2) using the contrast argument in results function?</p>
  
  <p>Of course I can make a new sampleinfo table, but I want to use the same sampleinfo as above. I tried to read about numeric contrast, but I am unable to use it correctly.</p>
  
Tags: <deseq2>
Title: Comparing factor levels in deseq2
ThreadText: # Comparing factor levels in deseq2
  
  (Asked by: username_0 on 2019-12-20)
  
  I have sample information (sampleinfo) in this format:
  
  ```
  SampleID    condition   type
  MP_1    A_1 Paired-End
  MP_2    A_1 Paired-End
  MP_3    A_1 Paired-End
  MN_1    A_2 Paired-End
  MN_2    A_2 Paired-End
  MN_3    A_2 Paired-End
  WP_1    B_1 Paired-End
  WP_2    B_1 Paired-End
  WP_3    B_1 Paired-End
  WN_1    B_2 Paired-End
  WN_2    B_2 Paired-End
  WN_3    B_2 Paired-End
  
  ```
  
  I want to compare A\_1 with A\_2, B\_1 with B\_2 ans also want to compare (A\_1+A\_2) with (B\_1+B\_2).
  
  This is how I used DESeqDataSetFromMatrix
  
  ```
  ddsMat <- DESeqDataSetFromMatrix(countData = seqdata[,rownames(sampleinfo)], colData =  sampleinfo, design = ~ condition)
  ddsMat <- DESeq(ddsMat)
  
  res.05_FC0<-results(ddsMat,contrast = c("condition","A_1","A_2"),alpha=0.05,lfcThreshold = 0)
  res.05_FC0<-results(ddsMat,contrast = c("condition","B_1","B_2"),alpha=0.05,lfcThreshold = 0)
  
  ```
  
  How can I compare (A\_1+A\_2) with (B\_1+B\_2) using the contrast argument in results function?
  
  Of course I can make a new sampleinfo table, but I want to use the same sampleinfo as above. I tried to read about numeric contrast, but I am unable to use it correctly.
  
  **Tags:** deseq2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-12-25. Score: 1
  
  You can use `contrast = c(0.5, 0.5, -0.5, -0.5)`, which means "the average of the first two coefficients minus the average of the second two.
  
  
  ---
  
  