Answers.Body: <p>If you want the values by group then subset <code>y</code> to contain the samples of interest and then feed that to <code>aveLogCPM()</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-22T12:53:18.537Z
Answers.Text: yes I took the matrix of only Tumor samples and genes with raw counts and applied aveLogCPM()
Answers.UserDisplayName: stack_learner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-22T12:30:23.773Z
Answers.LastActivityDate: 2018-06-22T12:30:23.773Z
Answers.UserDisplayName: Devon Ryan
Answers.Body: <p>This post on the Bioconductor mailing list explains the difference: <a href="https://support.bioconductor.org/p/100463/" rel="nofollow noreferrer">https://support.bioconductor.org/p/100463/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-05T12:05:49.573Z
Answers.Text: Thanks for your response. Could kindly provide a summary of the link here? Link answers are generally not encouraged.
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-12T09:43:52.077Z
Answers.Text: In short, Aaron Lun explains that the output of aveLogCPM is closer to
  `log2(rowMeans(cpm(y))` (where the log-transformation is done after the averaging), than to:
  `rowMeans(cpm(y, log=TRUE))`
Answers.UserDisplayName: jul635
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-05T08:07:19.447Z
Answers.LastActivityDate: 2023-09-05T08:07:19.447Z
Answers.UserDisplayName: jul635
Body: <p>Using edgeR for differential analysis between Tumor and Normal gave me differential expressed genes with logFC, logCPM, PValue and FDR. </p>
  
  <p>From the details of glmTreat function I see that logCPM is average log2-counts per million, the average taken over all libraries.</p>
  
  <p>The output table I got from glmTreat:</p>
  
  <pre><code>Geneid     logFC  unshrunk.logFC    logCPM  PValue       FDR
  Gene1   4.985298235 5.573931983 1.236660486 1.55E-54    1.87E-50
  Gene2   4.613438634 5.52126484  0.920343233 2.59E-53    1.56E-49
  Gene3   5.250601296 5.356432653 2.751294034 2.48E-50    9.95E-47
  Gene4   4.943049159 5.379741165 1.361393757 2.06E-45    6.19E-42
  Gene5   6.100121754 6.117580436 5.774385315 2.95E-43    7.11E-40
  Gene6   4.722697891 5.320461275 1.120685402 3.05E-42    6.11E-39
  Gene7   5.246129853 5.497012001 1.902992053 2.78E-40    4.78E-37
  Gene8   3.878773277 4.956636276 0.776208741 8.66E-39    1.30E-35
  Gene9   4.441752496 4.94930499  1.132652682 4.37E-38    5.83E-35
  </code></pre>
  
  <p>To calculate logCPM given in the above table manually I did like this:</p>
  
  <pre><code>logCPM &lt;- cpm(y, prior.count=2,  log=TRUE)
  </code></pre>
  
  <p>I got the logCPM values for all the genes. Then I calculated Average across all the samples for each gene. I got like below:</p>
  
  <pre><code>Geneid  Average
  Gene1   0.686560246
  Gene2   0.617115826
  Gene3   1.075975225
  Gene4   0.692050878
  Gene5   1.277556065
  Gene6   0.638358189
  Gene7   0.689323163
  Gene8   0.60700396
  Gene9   0.662115092
  </code></pre>
  
  <p>Why there is so difference? Where I'm doing wrong?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-22T11:15:18.873Z
Comments.Text: Did you also try `aveLogCPM(y, normalized.lib.sizes=TRUE, prior.count=2, dispersion=NULL, ...)`?
Comments.UserDisplayName: benn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-22T11:18:44.683Z
Comments.Text: `glmTreat()` literally uses `aveLogCPM` under the hood in fact.
Comments.UserDisplayName: Devon Ryan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-22T11:49:58.303Z
Comments.Text: @DevonRyan Yes you are right. thanks. It is calculated across all samples. I want to calculate aveLogCPM for each condition differently (Tumor and Normal separately) How to do that? Just taking the raw counts of Tumor condition and using aveLogCPM function on it is fine?
Comments.UserDisplayName: stack_learner
Tags: <r><rna-seq><bioconductor><rna><edger>
Title: How to calculate logCPM across all samples?
ThreadText: # How to calculate logCPM across all samples?
  
  (Asked by: username_0 on 2018-06-22)
  
  Using edgeR for differential analysis between Tumor and Normal gave me differential expressed genes with logFC, logCPM, PValue and FDR.
  
  From the details of glmTreat function I see that logCPM is average log2-counts per million, the average taken over all libraries.
  
  The output table I got from glmTreat:
  
  ```
  Geneid     logFC  unshrunk.logFC    logCPM  PValue       FDR
  Gene1   4.985298235 5.573931983 1.236660486 1.55E-54    1.87E-50
  Gene2   4.613438634 5.52126484  0.920343233 2.59E-53    1.56E-49
  Gene3   5.250601296 5.356432653 2.751294034 2.48E-50    9.95E-47
  Gene4   4.943049159 5.379741165 1.361393757 2.06E-45    6.19E-42
  Gene5   6.100121754 6.117580436 5.774385315 2.95E-43    7.11E-40
  Gene6   4.722697891 5.320461275 1.120685402 3.05E-42    6.11E-39
  Gene7   5.246129853 5.497012001 1.902992053 2.78E-40    4.78E-37
  Gene8   3.878773277 4.956636276 0.776208741 8.66E-39    1.30E-35
  Gene9   4.441752496 4.94930499  1.132652682 4.37E-38    5.83E-35
  
  ```
  
  To calculate logCPM given in the above table manually I did like this:
  
  ```
  logCPM <- cpm(y, prior.count=2,  log=TRUE)
  
  ```
  
  I got the logCPM values for all the genes. Then I calculated Average across all the samples for each gene. I got like below:
  
  ```
  Geneid  Average
  Gene1   0.686560246
  Gene2   0.617115826
  Gene3   1.075975225
  Gene4   0.692050878
  Gene5   1.277556065
  Gene6   0.638358189
  Gene7   0.689323163
  Gene8   0.60700396
  Gene9   0.662115092
  
  ```
  
  Why there is so difference? Where I'm doing wrong?
  
  **Tags:** r, rna-seq, bioconductor, rna, edger
  
  > **Comments:**
  > **username_1**: Did you also try `aveLogCPM(y, normalized.lib.sizes=TRUE, prior.count=2, dispersion=NULL, ...)`?  
  > **username_2**: `glmTreat()` literally uses `aveLogCPM` under the hood in fact.  
  > **username_0**: @username_2 Yes you are right. thanks. It is calculated across all samples. I want to calculate aveLogCPM for each condition differently (Tumor and Normal separately) How to do that? Just taking the raw counts of Tumor condition and using aveLogCPM function on it is fine?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-06-22. Score: 3
  
  If you want the values by group then subset `y` to contain the samples of interest and then feed that to `aveLogCPM()`.
  
  > **Comments:**
  > **username_0**: yes I took the matrix of only Tumor samples and genes with raw counts and applied aveLogCPM()  
  
  ---
  
  ### Answer by username_3 on 2023-09-05. Score: 0
  
  This post on the Bioconductor mailing list explains the difference: <https://support.bioconductor.org/p/100463/>
  
  > **Comments:**
  > **username_4**: Thanks for your response. Could kindly provide a summary of the link here? Link answers are generally not encouraged.  
  > **username_3**: In short, Aaron Lun explains that the output of aveLogCPM is closer to `log2(rowMeans(cpm(y))` (where the log-transformation is done after the averaging), than to: `rowMeans(cpm(y, log=TRUE))`  
  
  ---
  
  