R/calcEntropy.R

Defines functions calcEntropy

Documented in calcEntropy

calcEntropy <-
function(outList, classProbs, class, grLabels=paste("Group", 1:outList$Prior$H), printXtable=TRUE ) {
 
    entr <- numeric(outList$Prior$H+1)
    for (h in 1:outList$Prior$H) {
        entr[h] <- -sum(classProbs[,h]*log(classProbs[,h]))
    }
    entr[outList$Prior$H+1] <- -sum(classProbs*log(classProbs))

    entrTable <- cbind(entr, c(table(class), outList$N), entr/c(table(class), outList$N))

    dimnames(entrTable) <- list(c(grLabels, "total"), c("abs entr", "abs gr size", "rel entr"))
    
    if ( printXtable ) {
    
        print( xtable( entrTable, digits = c(0,2,0,2), caption="Contribution of each group to the total entropy (absolute and relative to group size -- based on ind post class probs)", 
                       label="tab:entropy"))
        
        cat("\n") 
    
    }
    
    return( invisible( entrTable ) )

}

Try the bayesMCClust package in your browser

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

bayesMCClust documentation built on May 29, 2017, 3:31 p.m.