Body: <p>I am trying to calculate log2FoldChange in DESeq2 by hand because I am trying to reproduce my results and understand how DESeq2 works.</p>
  <p>What I want to know is:</p>
  <ol>
  <li>Are the counts first fitted to a negative binomial? If so, how can I get access to those values?</li>
  <li>Regarding log2FoldChanges, I read that the coefficents are the estimates for the log2 foldchanges for each sample group. However, these estimates do not account for the large dispersion we observe with low read counts. To avoid this, the log2 fold changes calculated by the model need to be adjusted.
  Why? Didn't we just fit the counts to a negative binomial, which should take into account the dispersion.</li>
  <li>Finally, how are the log2FoldChanges calculated? It's not possible to figure this out using the raw code because most of the real calculations call C scripts.</li>
  </ol>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-25T13:48:16.500Z
Comments.Text: Have you checked if the DESeq2 vignette answers your questions? https://www.bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/DESeq2.html
Comments.UserDisplayName: Niklas
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-08T13:06:52.400Z
Comments.Text: were you able to figure this out? I am trying to do something similar where I have plot showing the differential expression results for a single gene from the DESeq2 output. I plotted the marplot of the log2FoldChange and errors bars with lfcSE. In the barplot I want to include the gene expression ratios that were used in estimating the statistics. Was wondering if it is possible? Somewhat related to your question, but the difference is I am interested in the ratios of the log-counts
  Any thoughts or hints will be appreciated.
Comments.UserDisplayName: user1938965
Tags: <deseq2>
Title: how is log2foldchange calculated in DESeq2
ThreadText: # how is log2foldchange calculated in DESeq2
  
  (Asked by: username_0 on 2023-09-22)
  
  I am trying to calculate log2FoldChange in DESeq2 by hand because I am trying to reproduce my results and understand how DESeq2 works.
  
  What I want to know is:
  
  1. Are the counts first fitted to a negative binomial? If so, how can I get access to those values?
  2. Regarding log2FoldChanges, I read that the coefficents are the estimates for the log2 foldchanges for each sample group. However, these estimates do not account for the large dispersion we observe with low read counts. To avoid this, the log2 fold changes calculated by the model need to be adjusted.
     Why? Didn't we just fit the counts to a negative binomial, which should take into account the dispersion.
  3. Finally, how are the log2FoldChanges calculated? It's not possible to figure this out using the raw code because most of the real calculations call C scripts.
  
  **Tags:** deseq2
  
  > **Comments:**
  > **username_1**: Have you checked if the DESeq2 vignette answers your questions? https://www.bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/DESeq2.html  
  > **username_2**: were you able to figure this out? I am trying to do something similar where I have plot showing the differential expression results for a single gene from the DESeq2 output. I plotted the marplot of the log2FoldChange and errors bars with lfcSE. In the barplot I want to include the gene expression ratios that were used in estimating the statistics. Was wondering if it is possible? Somewhat related to your question, but the difference is I am interested in the ratios of the log-counts Any thoughts or hints will be appreciated.  
  
  ---
  
  ## 0 answers
  
  