View source: R/hybrid.filter.R
hybrid.filter | R Documentation |
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.
hybrid.filter(y, width, method = "all", minNonNAs=3, extrapolate = TRUE)
y |
a numeric vector or (univariate) time series object. |
width |
an odd positive integer ( |
method |
a (vector of) character string(s) containing the method(s) to be used for the estimation
of the signal level. |
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 |
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
|
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.
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 |
slope |
a data frame (possibly) containing |
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.
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.
Missing values are treated by omitting them and thus by
reducing the corresponding window width.
The hybrid.filter
function only offers filters for signal
extraction delayed by (width
+1)/2 time units, in contrast
to other filters available from the robfilter
package
which also offer online time series analysis without time delay.
Roland Fried and Karen Schettlinger
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.
robreg.filter
, robust.filter
, dw.filter
, wrm.filter
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.