Learn R Programming

robfilter (version 4.1.5)

hybrid.filter: Robust Hybrid Filtering Methods for Univariate Time Series

Description

Procedures for robust extraction of low frequency components (the signal) from a univariate time series based on a moving window technique using the median of several one-sided half-window estimates (subfilters) in each step.

Usage

hybrid.filter(y, width, method = "all", minNonNAs=3, extrapolate = TRUE)

Value

hybrid.filter returns an object of class hybrid.filter. An object of class hybrid.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 (possibly) containing RM, RM.left, RM.right, LS.left and LS.right: the slope estimated by Repeated Median regression in the whole window (for method="RM") or in the left and right window half (for any method in "PRMH", "CRMH", "PRMMH" and "CRMMH") or the least squares slope estimated from the left and right window half (for any method in "PRFMH" or "CFMH").
Only those slopes are returned which are required by the filters specified in method. If only location-based filters are applied (i.e. "MED", "MEAN", "FMH", "MH" and /or "MMH") NULL is returned for the slope.

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 and extrapolate.

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

Arguments

y

a numeric vector or (univariate) time series object.

width

an odd positive integer (\(\geq 3\)) defining the window width used for fitting.

method

a (vector of) character string(s) containing the method(s) to be used for the estimation of the signal level.
It is possible to specify any combination of "MED", "RM", "MEAN", FMH, "PFMH", "CFMH", "MH", "PRMH", "CRMH", "MMH", "PRMMH", "CRMMH", and "all" (for all of the above). Default is method="all". For a detailed description see the section ‘Methods’ below.

minNonNAs

a positive integer defining the minimum number of non-missing observations within each window (half) which is required for a ‘sensible’ estimation. Default: if a window (half) contains less than minNonNAs = 3 observations an NA is returned (for that subfilter).

extrapolate

a logical indicating whether the level estimations should be extrapolated to the edges of the time series. The extrapolation extends the first estimated value to the first time in the first window and the last estimated value to the last time in the last time window. Default is extrapolate=TRUE.

Methods

The following methods are available as method for signal extraction.

Filters applying only one location or regression estimate to the whole window of length width and taking the location (in the centre of the time window) as final signal level estimate:

MED

ordinary running median filter.

MEAN

ordinary moving average filter.

RM

ordinary repeated median filter.
Applies repeated median regression to each time window.

Filters applying several subfilters within one window, taking the median of the values listed below as the final signal level estimate:

FMH

FIR median hybrid filter.
Uses half-window averages and the central observation.

PFMH

predictive FMH filter.
Uses half-window least squares regression and the central observation.

CFMH

combined FMH filter.
Uses half-window averages, half-window least squares regression, and the central observation.

MH

median hybrid filter.
Uses half-window medians and the central observation.

PRMH

predictive repeated median hybrid filter.
Uses half-window repeated median regression and the central observation.

CRMH

combined repeated median hybrid filter.
Uses half-window medians, half-window repeated median regression, and the central observation.

MMH

median/median hybrid filter.
Uses half-window medians and the median of all observations in the window.

PRMMH

predictive repeated median/median filter.
Uses half-window repeated median regression and the median of all observations in the window.

CRMMH

combined repeated median/median filter.
Uses half-window medians, half-window repeated median regression, and the median of all observations in the window.

Author

Roland Fried and Karen Schettlinger

Details

hybrid.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 or local extremes. For this, moving window techniques are applied.

Within each time window several subfilters are applied to half-windows (left and right of the centre); the final signal level in the centre of the time window is then estimated by the median of the subfilter outputs.

For the subfilters, both, location-based and regression-based method are available, the former applying means or medians and the idea of a locally constant signal value, the latter using ordinary least squares (LS) regression or Siegel's (1982) repeated median (RM) and the idea of an underlying locally linear trend.

The methods should be chosen based on an a-priori guess of the underlying signal and the data quality. Location based methods (MED, MEAN, FMH, MH, MMH) are recommended in case of a locally (piecewise) constant signal. Regression based and predictive approaches (RM, PFMH, PRMH, PRMMH) in case of locally linear monotone trends. The combined filters (CFMH, CRMH, CRMMH) can be seen as a compromise, but are computationally somewhat more expensive and may be inferior to the predictive filters during steep trends.

The approaches based on the median and RM are robust alternatives to the (in Gaussian samples) more efficient mean and least squares methods. The hybrid filters preserve shifts and local extremes much better than MED, MEAN or RM for the price of decreased robustness and / or Gaussian efficiency.

References

Fried, R., Bernholt, T., Gather, U. (2006) Repeated Median and Hybrid Filters, Computational Statistics & Data Analysis 50, 2313-2338.
(earlier version: http://hdl.handle.net/2003/4866)

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

robreg.filter, robust.filter, dw.filter, wrm.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.hy <- hybrid.filter(y, width=31)
# Plot:
plot(y.hy)

# Filtering with running median and PRMH only:
y2.hy <- hybrid.filter(y, width=31, method=c("MED","PRMH"))
plot(y2.hy)

Run the code above in your browser using DataLab