mFilter-package {mFilter} | R Documentation |
Getting started with the mFilter package
Description
Getting started with the mFilter package
Details
This package provides some tools for decomposing time series into trend (smooth) and cyclical (irregular) components. The package implements come commonly used filters such as the Hodrick-Prescott, Baxter-King and Christiano-Fitzgerald filter.
For loading the package, type:
library(mFilter)
A good place to start learning the package usage is to examine examples for
the mFilter
function. At the R prompt, write:
example("mFilter")
For a full list of functions exported by the package, type:
ls("package:mFilter")
Each exported function has a corresponding man page (some man pages are common to more functions). Display it by typing
help(functionName)
.
Almost all filters in this package can be put into the following
framework. Given a time series we are interested
in isolating component of
, denoted
with period of
oscillations between
and
, where
.
Consider the following decomposition of the time series
The component is assumed to have power only in the frequencies
in the interval
.
and
are related to
and
by
If infinite amount of data is available, then we can use the ideal bandpass filter
where the filter, , is given in terms of the lag operator
and defined as
The ideal bandpass filter weights are given by
The finite sample approximation to the ideal bandpass filter uses the alternative filter
Here the weights, , of the approximation is a
solution to
The Christiano-Fitzgerald filter is a finite data approximation to the ideal bandpass filter and minimizes the mean squared error defined in the above equation.
Several band-pass approximation strategies can be selected in the
function cffilter
. The default setting of cffilter
returns
the filtered data associated with the unrestricted optimal filter
assuming no unit root, no drift and an iid filter.
If theta
is not equal to 1 the series is assumed to follow a
moving average process. The moving average weights are given by theta
. The default is
theta=1
(iid series). If theta
then
the series is assumed to be
where if the option
root=1
and
if the option
root=0
, and is a white noise.
The Baxter-King filter is a finite data approximation to the ideal bandpass filter with following moving average weights
where
The Hodrick-Prescott filter obtains the filter weights
as a solution to
The Hodrick-Prescott filter is a finite data approximation with following moving average weights
The digital version of the Butterworth highpass filter is described by the rational polynomial expression (the filter's z-transform)
The time domain version can be obtained by substituting for the
lag operator
.
Pollock (2000) derives a specialized finite-sample version of the Butterworth
filter on the basis of signal extraction theory. Let be the
trend and
cyclical component of
, then these
components are extracted as
where and
.
Let be even and define
and
. The
trigonometric regression filter is based on the following relation
where and
are the coefficients obtained by
regressing
on the indicated sine and cosine
functions. Specifically,
for
for
and
for
for
Let be the trigonometric regression filter. It can
be showed that
, so that
has a unit
root for
. Also, when
is symmetric,
it has a second unit root in the middle of the data for
. Therefore it is important to drift adjust data before it is
filtered with a trigonometric regression filter.
If drift=TRUE
the drift adjusted series is obtained as
where is the undrifted series.
Author(s)
Mehmet Balcilar, mehmet@mbalcilar.net
References
M. Baxter and R.G. King. Measuring business cycles: Approximate bandpass filters. The Review of Economics and Statistics, 81(4):575-93, 1999.
L. Christiano and T.J. Fitzgerald. The bandpass filter. International Economic Review, 44(2):435-65, 2003.
J. D. Hamilton. Time series analysis. Princeton, 1994.
R.J. Hodrick and E.C. Prescott. Postwar US business cycles: an empirical investigation. Journal of Money, Credit, and Banking, 29(1):1-16, 1997.
R.G. King and S.T. Rebelo. Low frequency filtering and real business cycles. Journal of Economic Dynamics and Control, 17(1-2):207-31, 1993.
D.S.G. Pollock. Trend estimation and de-trending via rational square-wave filters. Journal of Econometrics, 99:317-334, 2000.
See Also
mFilter-methods
for listing all currently
available mFilter
methods. For help on common interface function
"mFilter
", mFilter
. For individual filter function
usage, bwfilter
, bkfilter
,
cffilter
, hpfilter
, trfilter
.