R/impurity.R

Defines functions impurity

#' Compute the impurity of a given vector
#'
#' @param Y Outcome data
#'
#' @importFrom DescTools Entropy
#'
#' @keywords internal
#' @noRd
impurity <- function(Y){

  if (Y$type=="numeric"){
    if (length(Y$Y)==1){
      return(0)
    }
    return(var(Y$Y))
  }

  if (Y$type=="factor"){
    return(Entropy(table(Y$Y)))
  }

}

Try the DynForest package in your browser

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

DynForest documentation built on Oct. 23, 2024, 5:06 p.m.