hybrid.filter(y, width, method = "all", minNonNAs=3, extrapolate = TRUE)
hybrid.filter
returns an object of class hybrid.filter
.
An object of class hybrid.filter
is a list containing the
following components:method
.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
.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.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.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)
Run the code above in your browser using DataLab