Learn R Programming

robfilter (version 4.1.5)

robreg.filter: Robust Regression Filters for Univariate Time Series

Description

Procedures for robust (online) extraction of low frequency components (the signal) from a univariate time series by applying robust regression techniques to moving time windows.

Usage

robreg.filter(y, width, method = "all", h = floor(width/2)+1,   
                 minNonNAs = 5, online = FALSE, extrapolate = TRUE)

Value

robreg.filter returns an object of class robreg.filter. An object of class robreg.filter is a list containing the following components:

level

a data frame containing the signal level extracted by the filter(s) specified in method.

slope

a data frame containing the corresponding slope within each time window.

In addition, the original input time series is returned as list member y, and the settings used for the analysis are returned as the list members width, method, h, minNonNAs, online and extrapolate.

Application of the function plot to an object of class robreg.filter returns a plot showing the original time series with the filtered output.

Arguments

y

a numeric vector or (univariate) time series object.

width

a positive integer defining the window width used for fitting.
If online=FALSE (see below) this needs to be an odd integer.

method

a (vector of) character string(s) containing the method(s) to be used for robust approximation of the signal within one time window. It is possible to specify any combination of the values:

"LMS"

Least Median of Squares regression

"LQD"

Least Quartile Difference regression

"LTS"

Least Trimmed Squares regression

"MED"

Median

"RM"

Repeated Median regression

"all"

all of the above (default)

Using dr.filter, lms.filter, lqd.filter, lts.filter, med.filter or rm.filter forces "DR", "LMS", "LQD", "LTS", "MED" or "RM" respectively.
Currently, only method="MED" and method="RM" (med.filter / rm.filter) can handle missing values in the input time series. For the other regression filters missing values have to be replaced before the analysis.

h

a positive integer defining the trimming quantile for LTS regression.

minNonNAs

a positive integer defining the minimum number of non-missing observations within one window which is required for a ‘sensible’ estimation. Currently, this option only has an effect for the two methods "MED" and /or "RM" (see method).

online

a logical indicating whether the current level estimate is evaluated at the most recent time within each time window (TRUE) or centred within each window (FALSE). Setting online=FALSE requires the width to be odd. Default is online=FALSE.

extrapolate

a logical indicating whether the level estimations should be extrapolated to the edges of the time series.
If online=FALSE the extrapolation consists of the fitted values within the first half of the first window and the last half of the last window; if online=TRUE the extrapolation consists of the fitted values within the first time window.

Author

C++ code: Thorsten Bernholt and Robin Nunkesser
Port to R: Roland Fried and Karen Schettlinger

Details

robreg.filter is suitable for extracting low frequency components (the signal) from a time series which may be contaminated with outliers and can contain level shifts. For this, robust regression methods are applied to a moving window, and the signal level is estimated by the fitted value either at the end of each time window for online signal extraction without time delay (online=TRUE) or in the centre of each time window (online=FALSE).

References

Davies, P.L., Fried, R., Gather, U. (2004) Robust Signal Extraction for On-Line Monitoring Data, Journal of Statistical Planning and Inference 122, 65-78.
(earlier version: http://hdl.handle.net/2003/5043)

Gather, U., Schettlinger, K., Fried, R. (2006) Online Signal Extraction by Robust Linear Regression, Computational Statistics 21(1), 33-51.
(earlier version: http://hdl.handle.net/2003/5305)

Schettlinger, K., Fried, R., Gather, U. (2006) Robust Filters for Intensive Care Monitoring: Beyond the Running Median, Biomedizinische Technik 51(2), 49-56.

See Also

wrm.filter, robust.filter, dw.filter, hybrid.filter.

Examples

Run this code
# Generate random time series:
y <- cumsum(runif(500)) - .5*(1:500)
# Add jumps:
y[200:500] <- y[200:500] + 5
y[400:500] <- y[400:500] - 7
# Add noise:
n <- sample(1:500, 30)
y[n] <- y[n] + rnorm(30)

# Filtering with all methods:
y.rr <- robreg.filter(y, width=31, method=c("RM", "LMS", "LTS", "DR", "LQD"))
# Plot:
plot(y.rr)

# Delayed filtering with RM and LMS filter:
y2.rr <- robreg.filter(y,width=31,method=c("RM","LMS"))
plot(y2.rr)

# Online filtering with RM filter:
y3.rr <- rm.filter(y,width=41,online=TRUE)
plot(y3.rr)

Run the code above in your browser using DataLab