hampel | R Documentation |
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.
hampel(x, n = 3, k = 1.4826, replace = FALSE)
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. |
The new vector with outliers replaced and a list of indices where the outliers were.
data(iris) library(makilab) iris$Sepal.Length[20] <- 99 # creating an outlier hampal(iris$Sepal.Length)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.