R/huber.R

Defines functions `huber`

`huber` <-
function(input, co = -1.345, shape = c('full','lower','upper'))
{
	input <- unlist(input);
	len <- length(input);
  shape <- match.arg(shape)
	input <- (input - mean(input))/sd(input)
	change <- switch(shape,
		full = which(abs(input) > abs(co)),
		lower = which(input <= co),
		upper = which(input >= abs(co))
	)
  	if (length(change)<1) input <- rep(1,len) ;
    input[change] <- abs(co)/abs(input[change])
  	input[-change] <- 1
	return(input)
}

Try the DIME package in your browser

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

DIME documentation built on May 9, 2022, 5:05 p.m.