R/topcvfNB.R

topcvfNB <- function(k, listFeatureChoices, mismatchTuning, mismatchTesting){

    ## Error checking parameters
    if(round(k) != k && k > 0){
        stop("k must be a positive integer.")
    }

    ## Aggregate mismatch scores for all folds in tuning/testing datasets
    sumMismatchTuning  <- Reduce("+", mismatchTuning)
    sumMismatchTesting <- Reduce("+", mismatchTesting)
    listFeatureChoices <- cbind(c(1:nrow(listFeatureChoices)),
                                listFeatureChoices,
                                sumMismatchTuning,
                                sumMismatchTesting)

    ## Subset top k combinations
    topK <- sort(sumMismatchTuning)[1:k]
    bestCombos <- which(sumMismatchTuning %in% topK)
    if(length(bestCombos) > k){
        bestCombos <- bestCombos[1:k]
    }

    return(bestCombos)
}
jchitpin/blistR documentation built on July 8, 2019, 6:29 p.m.