Body: <p>I have data that looks like this: 3 column SNPs their gene based on Annovar and a p-value for every SNP. What I would like is to aggregate the p values for every gene.</p>
  <pre class="lang-r prettyprint-override"><code>snps &lt;- data.frame(
    snp_id = c(&quot;rs1&quot;, &quot;rs2&quot;, &quot;rs3&quot;, &quot;rs4&quot;, &quot;rs5&quot;, &quot;rs6&quot;, &quot;rs7&quot;, &quot;rs8&quot;),
    gene = c(&quot;gene1&quot;, &quot;gene1&quot;, &quot;gene1&quot;, &quot;gene1&quot;, &quot;gene2&quot;, &quot;gene2&quot;, &quot;gene2&quot;, &quot;gene2&quot;),
    pvalue = c(0.7703884, 0.9648540, 0.9648540, 0.9648540, 0.54, 0.03, 0.03, 0.8)
  )
  </code></pre>
  <p>what I need to do is :</p>
  <ol>
  <li>For each gene, sort the p-values in ascending order.</li>
  <li>For each p-value in the sorted list, multiply it by the number of SNPs in that gene.</li>
  <li>Divide the result from step 2 by the rank of the p-value in the sorted list (i.e., its index in the list).</li>
  <li>Take the minimum value from step 3 as the new p-value for that gene.</li>
  <li>Adjust the p-values using the false discovery rate (FDR) correction method.</li>
  </ol>
  <p>This is the formula for each gene :combined p-value <span class="math-container">$\min(n p_{(i)}/i)$</span> where <span class="math-container">$p_{(1)}, …, p_{(n)}$</span> are the ordered p-values.</p>
  <p>I tried this code  with the usage of <code>simes.test</code> package in R:</p>
  <pre class="lang-r prettyprint-override"><code>library(mppa)
  
  x=c(0.77,0.964,0.964,0.964)
  simes.test(x)
  </code></pre>
  <p>The answer is 1.285. This is the source code of the <code>simes.test</code> function:</p>
  <pre class="lang-r prettyprint-override"><code>function (x, returnstat = FALSE) 
  {
      r = rank(x)
      T = min(length(x) * x/r)
      if (returnstat) 
          c(T, T)
      else T
  }
  </code></pre>
  <p>How is it possible for the pvalue to be larger then 1? What is the problem? I would be happy if you could share your knowledge in this situation.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-03-20T19:18:08.440Z
Comments.Text: What is a p-value for an SNP?
Comments.UserDisplayName: Ram RS
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-03-23T18:36:56.590Z
Comments.Text: It can happen it seems. detailed discussion of this topic can be found here http://stat.wharton.upenn.edu/~steele/Courses/956/ResourceDetails/MultipleComparision/Writght92.pdf
Comments.UserDisplayName: stefanH
Tags: <r><p-values>
Title: Simes method in R
ThreadText: # Simes method in R
  
  (Asked by: username_0 on 2023-03-20)
  
  I have data that looks like this: 3 column SNPs their gene based on Annovar and a p-value for every SNP. What I would like is to aggregate the p values for every gene.
  
  ```r
  snps <- data.frame(
    snp_id = c("rs1", "rs2", "rs3", "rs4", "rs5", "rs6", "rs7", "rs8"),
    gene = c("gene1", "gene1", "gene1", "gene1", "gene2", "gene2", "gene2", "gene2"),
    pvalue = c(0.7703884, 0.9648540, 0.9648540, 0.9648540, 0.54, 0.03, 0.03, 0.8)
  )
  
  ```
  
  what I need to do is :
  
  1. For each gene, sort the p-values in ascending order.
  2. For each p-value in the sorted list, multiply it by the number of SNPs in that gene.
  3. Divide the result from step 2 by the rank of the p-value in the sorted list (i.e., its index in the list).
  4. Take the minimum value from step 3 as the new p-value for that gene.
  5. Adjust the p-values using the false discovery rate (FDR) correction method.
  
  This is the formula for each gene :combined p-value $\min(n p\_{(i)}/i)$ where $p\_{(1)}, …, p\_{(n)}$ are the ordered p-values.
  
  I tried this code with the usage of `simes.test` package in R:
  
  ```r
  library(mppa)
  
  x=c(0.77,0.964,0.964,0.964)
  simes.test(x)
  
  ```
  
  The answer is 1.285. This is the source code of the `simes.test` function:
  
  ```r
  function (x, returnstat = FALSE) 
  {
      r = rank(x)
      T = min(length(x) * x/r)
      if (returnstat) 
          c(T, T)
      else T
  }
  
  ```
  
  How is it possible for the pvalue to be larger then 1? What is the problem? I would be happy if you could share your knowledge in this situation.
  
  **Tags:** r, p-values
  
  > **Comments:**
  > **username_1**: What is a p-value for an SNP?  
  > **username_2**: It can happen it seems. detailed discussion of this topic can be found here http://stat.wharton.upenn.edu/~steele/Courses/956/ResourceDetails/MultipleComparision/Writght92.pdf  
  
  ---
  
  ## 0 answers
  
  