text: user1283: I wish to adapt the r language function fgseaL, https://github.com/ctlab/fgsea , to perform rapidGSEA, https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-016-1244-x , computation of inter-class  deviation per gene and the subsequent gene rank sorting operation on 9 different phenotype labels as illustrated in the diagram immediately below:
  
  I thought of applying the R-language rank() function on the Expression Data Matrix D. If that is not correct, what sequence of R language commands should we
  apply to the Expression Data Matrix D to calculate a key value sorted deviation measure  across 8 labeled human leukemia groups and a healthy labeled normal control group prior to running fgseaL? 
  I show below how fgseaL finds the correlation matrix between the R language variable , mat, which corresponds to the Expression Data Matrix D and the R language variable , labels , which is a vector of gene phenotype labels
      tmatSc <- scale(t(mat))
      labelsSc <- scale(labels)[, 1]
  
      minSize <- max(minSize, 1)
  
      pathwaysFiltered <- lapply(pathways, function(p) { as.vector(na.omit(fmatch(p, rownames(mat)))) })
      pathwaysSizes <- sapply(pathwaysFiltered, length)
  
      toKeep <- which(minSize <= pathwaysSizes & pathwaysSizes <= maxSize)
      m <- length(toKeep)
  
      if (m == 0) {
          return(data.table(pathway=character(),
                            pval=numeric(),
                            padj=numeric(),
                            ES=numeric(),
                            NES=numeric(),
                            nMoreExtreme=numeric(),
                            size=integer(),
                            leadingEdge=list()))
      }
  
      pathwaysFiltered <- pathwaysFiltered[toKeep]
      pathwaysSizes <- pathwaysSizes[toKeep]
  
      corRanks <- var(tmatSc, labelsSc)[,1]
      ranksOrder <- order(corRanks, decreasing=T)
      ranksOrderInv <- invPerm(ranksOrder)
      stats <- corRanks[ranksOrder]
  
      pathwaysReordered <- lapply(pathwaysFiltered, function(x) ranksOrderInv[x])
  
      gseaStatRes <- do.call(rbind,
                             lapply(pathwaysReordered, calcGseaStat,
                                    stats=stats,
                                    returnLeadingEdge=TRUE))
  
  I found a problem with the algorithm shown immediately below.
  correcttest <- data.frame(names = row.names(normal))
  correcttest <- cbind(correcttest3, normal)
  correcttest <- cbind(correcttest3, ALL3m)
  rownames(correcttest) <- correcttest$names
  correcttest$names <- NULL
  correctlabelnormal <- rep(0:0, 73)
  correctlabelALL3m <- rep(1:1, 122)
  correctlabel <- as.vector(c(correctlabelnormal,correctlabelALL3m))
  s <- apply(correcttest, 1, function(x) coef(lm(x~correctlabel))[2])
  o <- rank(s)
  o <- max(o) - o + 1
  res <- fgseaL(df,o,correctlabel,nperm = 2000,minSize = 1, maxSize=50000)
  empty data table (0 rows) of 8 columns:   pathway,pval,padj,ES,NES,nMoreExtreme,size
  
  I found the binary phenotype labeled group fgseaL test results below looked satisfactory.    
  correcttest <- data.frame(names = row.names(normal))
  correcttest <- cbind(correcttest3, normal)
  correcttest <- cbind(correcttest3, ALL3m)
  rownames(correcttest) <- correcttest$names
  correcttest$names <- NULL
  correctlabelnormal <- rep(0:0, 73)
  correctlabelALL3m <- rep(1:1, 122)
  correctlabel <- as.vector(c(correctlabelnormal,correctlabelALL3m))
  fgseaL(df,correcttest,correctlabel,nperm = 2000,minSize = 1, maxSize=50000)
         pathway        pval        padj         ES       NES nMoreExtreme  size
  1: Gene.Symbol 0.003940887 0.003940887 -0.2460126 -1.180009            3 45714
                                   leadingEdge
  1: AKIRIN2,LRRC20,HSPA5,HSPA5,DTWD2,ZFYVE28,
  
  Thank you for your consideration.
  
  user77: You rank the fit coefficient rather than the original score matrix. So, given a score matrix, D:
  D = matrix(c(22,20,9,8,46,22,18,10,3,18,3,29,2,1,5,45,43,47,17,5,14,44,21,36), byrow=T, ncol=6)
  cl = c(0,0,0,1,1,1)
  s = apply(m, 1, function(x) coef(lm(x~cl))[2]) # [1]
  o = rank(s)
  o = max(o) - o + 1 # [2]
  
  o is then the rank of each row.
  [1] This fits each row as a linear model of cl and extracts the cl coefficient.
  [2] This converts the ranking to be the same as shown in the figure. I don't know if this is important, but I would assume so given how GSEA methods tend to work.
  
  user1283: I finally found another answer to my question. Please read this great article in May 12 2017 BioMed Central (BMC) Bioinformatics article titled Ranking metrics in gene set enrichment analysis: do they matter?.
  Also, please read this blog , Diving into Genetics and Genomics: Gene Set Enrichment Analysis (GSEA) explained.
  After reading these two articles, my choice for the best rapidGSEA local ranking measure is Minimum Significant Difference (i.e., MSD), because it has the best overall false positive rate (i.e., FPR) for larger sample sizes.
  Finally, it is important to realize that fgseaL's phenotype labeling can hypothetically be emulated by GSEA with either one of it's sixteen possible ranking metrics or a custom ranking metric.
  
original_text: 1283: <p>I wish to adapt the r language function fgseaL, <a href="https://github.com/ctlab/fgsea" rel="noreferrer">https://github.com/ctlab/fgsea</a> , to perform rapidGSEA, <a href="https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-016-1244-x" rel="noreferrer">https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-016-1244-x</a> , computation of inter-class  deviation per gene and the subsequent gene rank sorting operation on 9 different phenotype labels as illustrated in the diagram immediately below:</p>
  
  <p><a href="https://i.stack.imgur.com/kXvmr.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/kXvmr.gif" alt="enter image description here"></a></p>
  
  <p>I thought of applying the R-language rank() function on the Expression Data Matrix D. If that is not correct, what sequence of R language commands should we
  apply to the Expression Data Matrix D to calculate a key value sorted deviation measure  across 8 labeled human leukemia groups and a healthy labeled normal control group prior to running fgseaL? </p>
  
  <p>I show below how fgseaL finds the correlation matrix between the R language variable , mat, which corresponds to the Expression Data Matrix D and the R language variable , labels , which is a vector of gene phenotype labels</p>
  
  <pre><code>    tmatSc &lt;- scale(t(mat))
      labelsSc &lt;- scale(labels)[, 1]
  
      minSize &lt;- max(minSize, 1)
  
      pathwaysFiltered &lt;- lapply(pathways, function(p) { as.vector(na.omit(fmatch(p, rownames(mat)))) })
      pathwaysSizes &lt;- sapply(pathwaysFiltered, length)
  
      toKeep &lt;- which(minSize &lt;= pathwaysSizes &amp; pathwaysSizes &lt;= maxSize)
      m &lt;- length(toKeep)
  
      if (m == 0) {
          return(data.table(pathway=character(),
                            pval=numeric(),
                            padj=numeric(),
                            ES=numeric(),
                            NES=numeric(),
                            nMoreExtreme=numeric(),
                            size=integer(),
                            leadingEdge=list()))
      }
  
      pathwaysFiltered &lt;- pathwaysFiltered[toKeep]
      pathwaysSizes &lt;- pathwaysSizes[toKeep]
  
      corRanks &lt;- var(tmatSc, labelsSc)[,1]
      ranksOrder &lt;- order(corRanks, decreasing=T)
      ranksOrderInv &lt;- invPerm(ranksOrder)
      stats &lt;- corRanks[ranksOrder]
  
      pathwaysReordered &lt;- lapply(pathwaysFiltered, function(x) ranksOrderInv[x])
  
      gseaStatRes &lt;- do.call(rbind,
                             lapply(pathwaysReordered, calcGseaStat,
                                    stats=stats,
                                    returnLeadingEdge=TRUE))
  
  I found a problem with the algorithm shown immediately below.
  correcttest &lt;- data.frame(names = row.names(normal))
  correcttest &lt;- cbind(correcttest3, normal)
  correcttest &lt;- cbind(correcttest3, ALL3m)
  rownames(correcttest) &lt;- correcttest$names
  correcttest$names &lt;- NULL
  correctlabelnormal &lt;- rep(0:0, 73)
  correctlabelALL3m &lt;- rep(1:1, 122)
  correctlabel &lt;- as.vector(c(correctlabelnormal,correctlabelALL3m))
  s &lt;- apply(correcttest, 1, function(x) coef(lm(x~correctlabel))[2])
  o &lt;- rank(s)
  o &lt;- max(o) - o + 1
  res &lt;- fgseaL(df,o,correctlabel,nperm = 2000,minSize = 1, maxSize=50000)
  empty data table (0 rows) of 8 columns:   pathway,pval,padj,ES,NES,nMoreExtreme,size
  
  I found the binary phenotype labeled group fgseaL test results below looked satisfactory.    
  correcttest &lt;- data.frame(names = row.names(normal))
  correcttest &lt;- cbind(correcttest3, normal)
  correcttest &lt;- cbind(correcttest3, ALL3m)
  rownames(correcttest) &lt;- correcttest$names
  correcttest$names &lt;- NULL
  correctlabelnormal &lt;- rep(0:0, 73)
  correctlabelALL3m &lt;- rep(1:1, 122)
  correctlabel &lt;- as.vector(c(correctlabelnormal,correctlabelALL3m))
  fgseaL(df,correcttest,correctlabel,nperm = 2000,minSize = 1, maxSize=50000)
         pathway        pval        padj         ES       NES nMoreExtreme  size
  1: Gene.Symbol 0.003940887 0.003940887 -0.2460126 -1.180009            3 45714
                                   leadingEdge
  1: AKIRIN2,LRRC20,HSPA5,HSPA5,DTWD2,ZFYVE28,
  </code></pre>
  
  <p>Thank you for your consideration.</p>
   77: <p>You rank the fit coefficient rather than the original score matrix. So, given a score matrix, <code>D</code>:</p>
  
  <pre class="lang-r prettyprint-override"><code>D = matrix(c(22,20,9,8,46,22,18,10,3,18,3,29,2,1,5,45,43,47,17,5,14,44,21,36), byrow=T, ncol=6)
  cl = c(0,0,0,1,1,1)
  s = apply(m, 1, function(x) coef(lm(x~cl))[2]) # [1]
  o = rank(s)
  o = max(o) - o + 1 # [2]
  </code></pre>
  
  <p><code>o</code> is then the rank of each row.</p>
  
  <p>[1] This fits each row as a linear model of <code>cl</code> and extracts the <code>cl</code> coefficient.</p>
  
  <p>[2] This converts the ranking to be the same as shown in the figure. I don't know if this is important, but I would assume so given how GSEA methods tend to work.</p>
   1283: <p>I finally found another answer to my question. Please read this great article in May 12 2017 BioMed Central (BMC) Bioinformatics article titled <a href="https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-017-1674-0" rel="nofollow noreferrer">Ranking metrics in gene set enrichment analysis: do they matter?</a>.</p>
  
  <p>Also, please read this blog , <a href="http://crazyhottommy.blogspot.com/2016/08/gene-set-enrichment-analysis-gsea.html" rel="nofollow noreferrer">Diving into Genetics and Genomics: Gene Set Enrichment Analysis (GSEA) explained</a>.</p>
  
  <p>After reading these two articles, my choice for the best rapidGSEA local ranking measure is Minimum Significant Difference (i.e., MSD), because it has the best overall false positive rate (i.e., FPR) for larger sample sizes.</p>
  
  <p>Finally, it is important to realize that fgseaL's phenotype labeling can hypothetically be emulated by GSEA with either one of it's sixteen possible ranking metrics or a custom ranking metric.</p>
  