Learn R Programming

mFilter (version 0.1-5)

trfilter: Trigonometric regression filter of a time series

Description

This function uses trigonometric regression filter for estimating cyclical and trend components of a time series. The function computes cyclical and trend components of the time series using a lower and upper cut-off frequency in the spirit of a band pass filter.

Usage

trfilter(x,pl=NULL,pu=NULL,drift=FALSE)

Arguments

x

a regular time series.

pl

integer. minimum period of oscillation of desired component (pl<=2).

pu

integer. maximum period of oscillation of desired component (2<=pl<pu<infinity).

drift

logical, FALSE if no drift in time series (default), TRUE if drift in time series.

Value

A "mFilter" object (see mFilter).

Details

Almost all filters in this package can be put into the following framework. Given a time series \(\{x_t\}^T_{t=1}\) we are interested in isolating component of \(x_t\), denoted \(y_t\) with period of oscillations between \(p_l\) and \(p_u\), where \(2 \le p_l < p_u < \infty\).

Consider the following decomposition of the time series $$x_t = y_t + \bar{x}_t$$ The component \(y_t\) is assumed to have power only in the frequencies in the interval \(\{(a,b) \cup (-a,-b)\} \in (-\pi, \pi)\). \(a\) and \(b\) are related to \(p_l\) and \(p_u\) by $$a=\frac{2 \pi}{p_u}\ \ \ \ \ {b=\frac{2 \pi}{p_l}}$$

If infinite amount of data is available, then we can use the ideal bandpass filter $$y_t = B(L)x_t$$ where the filter, \(B(L)\), is given in terms of the lag operator \(L\) and defined as $$B(L) = \sum^\infty_{j=-\infty} B_j L^j, \ \ \ L^k x_t = x_{t-k}$$ The ideal bandpass filter weights are given by $$B_j = \frac{\sin(jb)-\sin(ja)}{\pi j}$$ $$B_0=\frac{b-a}{\pi}$$

Let \(T\) be even and define \(n_1=T/p_u\) and \(n_2=T/p_l\). The trigonometric regression filter is based on the following relation $${y}_t=\sum^{n_1}_{j=n_2}\left\{ a_j \cos(\omega_j t) + b_j \sin(\omega_j t) \right\}$$ where \(a_j\) and \(b_j\) are the coefficients obtained by regressing \(x_t\) on the indicated sine and cosine functions. Specifically,

\(a_j=\frac{T}{2}\sum^{T}_{t=1}\cos(\omega_j t) x_t,\ \ \ \) for \(j=1,\dots,T/2-1\)

\(a_j=\frac{T}{2}\sum^{T}_{t=1}\cos(\pi t) x_t,\ \ \ \) for \(j=T/2\)

and

\(b_j=\frac{T}{2}\sum^{T}_{t=1}\sin(\omega_j t) x_t,\ \ \ \) for \(j=1,\dots,T/2-1\)

\(b_j=\frac{T}{2}\sum^{T}_{t=1}\sin(\pi t) x_t,\ \ \ \) for \(j=T/2\)

Let \(\hat{B}(L) x_t\) be the trigonometric regression filter. It can be showed that \(\hat{B}(1)=0\), so that \(\hat{B}(L)\) has a unit root for \(t=1,2,\dots,T\). Also, when \(\hat{B}(L)\) is symmetric, it has a second unit root in the middle of the data for \(t\). 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 $$\tilde{x}_{t}=x_t-t\left(\frac{x_{T}-x_{1}}{T-1}\right), \ \ t=0,1,\dots,T-1$$ where \(\tilde{x}_{t}\) is the undrifted series.

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, hpfilter, cffilter, bkfilter, bwfilter

Examples

Run this code
# NOT RUN {
## library(mFilter)

data(unemp)

opar <- par(no.readonly=TRUE)

unemp.tr <- trfilter(unemp, drift=TRUE)
plot(unemp.tr)
unemp.tr1 <- trfilter(unemp, drift=TRUE)
unemp.tr2 <- trfilter(unemp, pl=8,pu=40,drift=TRUE)
unemp.tr3 <- trfilter(unemp, pl=2,pu=60,drift=TRUE)
unemp.tr4 <- trfilter(unemp, pl=2,pu=40,drift=TRUE)

par(mfrow=c(2,1),mar=c(3,3,2,1),cex=.8)
plot(unemp.tr1$x,
main="Trigonometric regression filter of unemployment: Trend, drift=TRUE",
     col=1, ylab="")
lines(unemp.tr1$trend,col=2)
lines(unemp.tr2$trend,col=3)
lines(unemp.tr3$trend,col=4)
lines(unemp.tr4$trend,col=5)
legend("topleft",legend=c("series", "pl=2, pu=32", "pl=8, pu=40",
"pl=2, pu=60", "pl=2, pu=40"), col=1:5, lty=rep(1,5), ncol=1)

plot(unemp.tr1$cycle,
main="Trigonometric regression filter of unemployment: Cycle,drift=TRUE",
     col=2, ylab="", ylim=range(unemp.tr3$cycle,na.rm=TRUE))
lines(unemp.tr2$cycle,col=3)
lines(unemp.tr3$cycle,col=4)
lines(unemp.tr4$cycle,col=5)
## legend("topleft",legend=c("pl=2, pu=32", "pl=8, pu=40", "pl=2, pu=60",
## "pl=2, pu=40"), col=1:5, lty=rep(1,5), ncol=1)

par(opar)
# }

Run the code above in your browser using DataLab