bwfilter: Butterworth filter of a time series

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/bwfilter.R

Description

Filters a time series using the Butterworth square-wave highpass filter described in Pollock (2000).

Usage

1
bwfilter(x,freq=NULL,nfix=NULL,drift=FALSE)

Arguments

x

a regular time series

nfix

sets the order of the filter. The default is nfix=2, when nfix=NULL.

freq

integer, the cut-off frequency of the Butterworth filter. The default is trunc(2.5*frequency(x)).

drift

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

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 ≤ p_l < p_u < ∞.

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 (-π, π). a and b are related to p_l and p_u by

a=\frac{2 π}{p_u}\ \ \ \ \ {b=\frac{2 π}{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) = ∑^∞_{j=-∞} 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)}{π j}

B_0=\frac{b-a}{π}

The digital version of the Butterworth highpass filter is described by the rational polynomial expression (the filter's z-transform)

\frac{λ(1-z)^n(1-z^{-1})^n}{(1+z)^n(1+z^{-1})^n+λ(1-z)^n(1-z^{-1})^n}

The time domain version can be obtained by substituting z for the lag operator L.

Pollock derives a specialized finite-sample version of the Butterworth filter on the basis of signal extraction theory. Let s_t be the trend and c_t cyclical component of y_t, then these components are extracted as

y_t=s_t+c_t=\frac{(1+L)^n}{(1-L)^d}ν_t+(1-L)^{n-d}\varepsilon_t

where ν_t \sim N(0,σ_ν^2) and \varepsilon_t \sim N(0,σ_\varepsilon^2).

If drift=TRUE the drift adjusted series is obtained as

\tilde{x}_{t}=x_t-t≤ft(\frac{x_{T}-x_{1}}{T-1}\right), \ \ t=0,1,…,T-1

where \tilde{x}_{t} is the undrifted series.

Value

A "mFilter" object (see mFilter).

Author(s)

Mehmet Balcilar, [email protected]

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, trfilter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## library(mFilter)

data(unemp)

opar <- par(no.readonly=TRUE)

unemp.bw <- bwfilter(unemp)
plot(unemp.bw)
unemp.bw1 <- bwfilter(unemp, drift=TRUE)
unemp.bw2 <- bwfilter(unemp, freq=8,drift=TRUE)
unemp.bw3 <- bwfilter(unemp, freq=10, nfix=3, drift=TRUE)
unemp.bw4 <- bwfilter(unemp, freq=10, nfix=4, drift=TRUE)

par(mfrow=c(2,1),mar=c(3,3,2,1),cex=.8)
plot(unemp.bw1$x,
     main="Butterworth filter of unemployment: Trend,
     drift=TRUE",col=1, ylab="")
lines(unemp.bw1$trend,col=2)
lines(unemp.bw2$trend,col=3)
lines(unemp.bw3$trend,col=4)
lines(unemp.bw4$trend,col=5)
legend("topleft",legend=c("series", "freq=10, nfix=2",
       "freq=8, nfix=2", "freq=10, nfix=3", "freq=10, nfix=4"),
       col=1:5, lty=rep(1,5), ncol=1)

plot(unemp.bw1$cycle,
     main="Butterworth filter of unemployment: Cycle,drift=TRUE",
     col=2, ylab="", ylim=range(unemp.bw3$cycle,na.rm=TRUE))
lines(unemp.bw2$cycle,col=3)
lines(unemp.bw3$cycle,col=4)
lines(unemp.bw4$cycle,col=5)
## legend("topleft",legend=c("series", "freq=10, nfix=2", "freq=8,
## nfix=2", "freq## =10, nfix=3", "freq=10, nfix=4"), col=1:5,
## lty=rep(1,5), ncol=1)

par(opar)

mbalcilar/mFilter documentation built on Sept. 23, 2018, 12:56 a.m.