R/medianDifferenceSelection.R

setGeneric("medianDifferenceSelection", function(expression, ...)
{standardGeneric("medianDifferenceSelection")})

setMethod("medianDifferenceSelection", "matrix", 
          function(expression, classes, ...)
          {
            features <- rownames(expression)
            groupsTable <- data.frame(class = classes, row.names = colnames(expression))
            exprSet <- ExpressionSet(expression, AnnotatedDataFrame(groupsTable))
            if(length(features) > 0) featureNames(exprSet) <- features  
            medianDifferenceSelection(ExpressionSet(expression, AnnotatedDataFrame(groupsTable)), ...)
          })

setMethod("medianDifferenceSelection", "ExpressionSet", 
          function(expression, datasetName, trainParams, predictParams, resubstituteParams, selectionName = "Difference of Group Medians", verbose = 3)
          {
            if(verbose == 3)
              message("Calculating differences of group medians.")
            exprMatrix <- exprs(expression)
            classes <- pData(expression)[, "class"]
            classExprMatrix <- exprMatrix[, classes == levels(classes)[1]]
            otherClassExprMatrix <- exprMatrix[, classes == levels(classes)[2]]
            medianAbsoluteDifferences <- abs(apply(classExprMatrix, 1, median) - apply(classExprMatrix, 2, median))
            orderedFeatures <- order(medianAbsoluteDifferences, decreasing = TRUE)
            
            .pickRows(expression, datasetName, trainParams, predictParams, resubstituteParams, orderedFeatures, selectionName, verbose)
          })

Try the ClassifyR package in your browser

Any scripts or data that you put into this service are public.

ClassifyR documentation built on Nov. 17, 2017, 1:42 p.m.