R/signalRank.R

Defines functions signalRank

Documented in signalRank

#' Sorting features based on effect size
#'
#' This function ranks features with biggest effect sizes to those with lowest effect sizes based on mean(condA) - mean(condB)
#' It returns data frame (df) where features are ordered by effect size
#' @param df A data frame 
#' @param cond A vector of 0s and 1s explaining which columns belong to the first (0) and second condition (1)
#' @export

signalRank <- function(df, cond){
  xy.out <- xyCal(cond)
  x <- xy.out$x
  y <- xy.out$y
  data1 <- as.matrix(df[,x])  ##data under condition1
  data2 <- as.matrix(df[,y])  ##data under condition2
  data1.ave=apply(data1,1,mean)
  data2.ave=apply(data2,1,mean)
  effectSize=data1.ave-data2.ave
  df<-cbind(df,effectSize)
  orderIndex <- order(df$effectSize)
  df<-df[orderIndex,]
  df
}
msxakk89/dat documentation built on Aug. 3, 2020, 6:39 p.m.