R/renormalize_bmdk.R

Defines functions renormalize_bmdk

Documented in renormalize_bmdk

#' Renormalize the BMDK features data
#'
#' After outliers are removed, renormalize the features data and store the
#' new max value of each feature.
#'
#' @param dat a list containing 4 elements: case, a list of case/control statuses;
#'        feat, a matrix of normalized feature data; maxfeat, a list of max features
#'        from each column in feat; minfeat, a list of min features for each feature
#' @return List containing 4 elements (case, feat, maxfeat, minfeat)
#'        renormalized after outliers are removed

renormalize_bmdk <- function(dat)
{
  # After removing outliers, unnormalize dat
  dat$feat <- t(t(dat$feat) * (dat$maxfeat - dat$minfeat) + dat$minfeat)
  
  # Reevaluate the max feature of each column
  dat$maxfeat <- apply(dat$feat, 2, max)
  
  # Reevaluate the min feature of each column
  dat$minfeat <- apply(dat$feat, 2, min)
  
  # Renormalize dat
  dat$feat <- apply(dat$feat, 2,
                    function(.x){(.x - min(.x, na.rm = TRUE)) /
                        (max(.x, na.rm = TRUE) - min(.x, na.rm = TRUE))})
  
  return(dat)
}
abcsFrederick/BMDK documentation built on Aug. 9, 2021, 2:19 p.m.