dw.filter(y, outer.width, inner.width, method = "all",
scale = "MAD", d = 2,
minNonNAs = 5, online = FALSE, extrapolate = TRUE)
dw.filter
returns an object of class dw.filter
.
An object of class dw.filter
is a list containing the
following components:method
.inner.loc.sigma
, inner.reg.sigma
, outer.loc.sigma
and outer.reg.sigma
,
the scale estimated from the observations (loc
) or the residuals from the Repeated Median regression (reg
)
within the inner window of length inner.width
or the outer window of length outer.width
, respectively.
MTM
uses outer.loc.sigma
for trimming outliers,
MRM
and TRM
use outer.reg.sigma
for trimming outliers,
DWMTM
uses inner.loc.sigma
for trimming outliers,
DWMRM
and DWTRM
use inner.reg.sigma
for trimming outliers;
MED
, RM
and RM
require no scale estimation.
The function only returns values for inner.loc.sigma
, inner.reg.sigma
,
outer.loc.sigma
or outer.reg.sigma
if any specified method
requires their estimation; otherwise NA
s are returned.y
, and the settings used for the analysis are
returned as the list members outer.width
,
inner.width
, method
, scale
, d
,
minNonNAs
, online
and extrapolate
.
Application of the function plot
to an object of class
dw.filter
returns a plot showing the original time series
with the filtered output.dw.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, moving window techniques are applied.
A short inner window of length inner.width
is used in each
step for calculating an initial level estimate (by using either
the median or a robust regression fit) and a robust estimate of
the local standard deviation. Observations deviating strongly from this
initial fit are trimmed from an outer time window of length
outer.width
, and the signal level is estimated from the
remaining observations (by using either a location or regression
estimator). Values specified in method
determine which
combination of estimation methods should be applied to the inner
and outer window (see section method
should be chosen based on an a-priori
guess of the underlying signal and the data quality: Location
based method (MED
/ MTM
) are recommended in case
of a locally (piecewise) constant signal, regression based
approaches (RM
/ DWRM
/ TRM
/ MRM
) in
case of locally linear, monotone trends.
Since no big differences have been reported between TRM
and MRM
, the quicker and somewhat more efficient
TRM
option might be preferred. DWRM
is the quickest
of all regression based methods and performs better than the
ordinary RM
at shifts, but it is the least robust and
least efficient method.
If location based methods are used, the inner.width
should
be chosen at least twice the length of expected patches of
subsequent outliers in the time series; if regression based
methods are used, the inner.width
should be at least three
times that length, otherwise outlier patches can influence the
estimations strongly. To increase the efficiency of the final
estimates, outer.width
can then be chosen rather large -
provided that it is smaller than the time between subsequent
level shifts.
For robust scale estimation, MAD
is the classical choice;
SN
is a somewhat more efficient and almost equally robust
alternative, while QN
is much more efficient if the
window widths are not too small, and it performs very well at the
occurrence of level shifts.
The factor d
, specifying the trimming boundaries as a
multiple of the estimated scale, can be chosen similarly to
classical rules for detecting unusual observations in a Gaussian
sample. Choosing d=3
instead of d=2
increases
efficiency, but decreases robustness; d=2.5
might be seen
as a compromise.robreg.filter
, robust.filter
, hybrid.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.dw <- dw.filter(y, outer.width=31, inner.width=11, method="all")
# Plot:
plot(y.dw)
# Filtering with trimmed RM and double window TRM only:
y2.dw <- dw.filter(y, outer.width=31, inner.width=11, method=c("TRM","DWTRM"))
plot(y2.dw)
Run the code above in your browser using DataLab