R/scale_robust.R

Defines functions scale_robust

Documented in scale_robust

#' Scaling robust against outliers
#' @param x vector of values
#' @param trunc percentile of values not to take into account for calculating scaling-pameters
#' @return scaled vector of values
#' @export
scale_robust <- function(x, trunc = .05){
  N <- length(x)
  x_normal <- sort(x)[round(trunc * N) : round((1 - trunc) * N)]
  x.robustscaled <- (x - mean(x_normal)) / sd(x_normal)
  # if no variance, return NAs
  if(sd(x_normal) == 0) return(rep(NA, N))
  return(x.robustscaled)
}
td-berlin/anomalizer documentation built on Feb. 21, 2020, 2:03 a.m.