hampel: Hampel Filter for outlier removal

View source: R/RcppExports.R

hampelR Documentation

Hampel Filter for outlier removal

Description

Smoothes a series by removing outliers. Outliers are detected by being more than a standard deviations from the median absolute deviation. Non-outliers aren't affected. The a parameter scales the standard deviations to have the CDF of a normal distribution.

Usage

hampel(x, window_size, a = 3, k = 1.4826, recentre = TRUE, miss = "single")

Arguments

x

Input time-series as a vector.

window_size

Window size as an integer

a

Threshold number of standard deviations from the median absolute deviation to classify outliers as.

k

Tuning parameter to convert standard deviations to a normal CDF.

recentre

Whether to recentre the window around the middle point in the window so as to avoid adding lag. I.e. for an odd window_length y[i] = mean(x[(i - floor(window_length/2)) : (i + floor(window_length/2))]) For an even window length the output is located more closely to earlier points, i.e. y[i] = mean(x[(i - window_length/2 + 1) : (i + window_length/2)])

miss

How to handle missing values. 'single' only returns NA for y[i] if x[i] = NA. 'all' returns NA for y[i] if any value in the window is missing, and 'none' omits NAs from the window, so will only return NA for y[i] if all windowed values are also NA.

Value

A filtered time-series the same length as x.


stulacy/filters documentation built on March 19, 2022, 7:25 a.m.