hampel: Applies a Hampel Filter to the provided data.

View source: R/hampel.R

hampelR Documentation

Applies a Hampel Filter to the provided data.

Description

The Hampel filter is an outlier detection function used in time series analysis that finds the median value of the input vector and the mean absolute deviation (MAD). Outliers are determined by being more than n MADs from the median. Typically this is applied as a sliding window.

Usage

hampel(x, n = 3, k = 1.4826, replace = FALSE)

Arguments

x

A vector of numerical data.

n

The number of MADs from the median to limit the data. Default is 3.

k

A scaling factor of the MAD. Default is for Gaussian data.

replace

A boolean to determine if outliers should be replaced by the median. If set to FALSE, outliers will be set to NA. Default is FALSE.

Value

The new vector with outliers replaced and a list of indices where the outliers were.

Examples

data(iris)
library(makilab)
iris$Sepal.Length[20] <- 99 # creating an outlier
hampal(iris$Sepal.Length)

jvandoorn/makilab documentation built on Oct. 8, 2022, 3:33 a.m.