Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


mFilter (version 0.1-5)

bkfilter: Baxter-King filter of a time series

Description

This function implements the Baxter-King approximation to the band pass filter for a time series. The function computes cyclical and trend components of the time series using band-pass approximation for fixed and variable length filters.

Usage

bkfilter(x,pl=NULL,pu=NULL,nfix=NULL,type=c("fixed","variable"),drift=FALSE)

Arguments

x

a regular time series

type

character, indicating the filter type, "fixed", for the fixed length Baxter-King filter (default), "variable", for the variable length Baxter-King filter.

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.

nfix

sets fixed lead/lag length or order of the filter. The nfix option sets the order of the filter by 2*nfix+1. The default is frequency(x)*3.

Value

A "mFilter" object (see mFilter).

Details

Almost all filters in this package can be put into the following framework. Given a time series {xt}t=1T we are interested in isolating component of xt, denoted yt with period of oscillations between pl and pu, where 2pl<pu<.

Consider the following decomposition of the time series xt=yt+x¯t The component yt is assumed to have power only in the frequencies in the interval {(a,b)(a,b)}(π,π). a and b are related to pl and pu by a=2πpu     b=2πpl

If infinite amount of data is available, then we can use the ideal bandpass filter yt=B(L)xt where the filter, B(L), is given in terms of the lag operator L and defined as B(L)=j=BjLj,   Lkxt=xtk The ideal bandpass filter weights are given by Bj=sin(jb)sin(ja)πj B0=baπ

The Baxter-King filter is a finite data approximation to the ideal bandpass filter with following moving average weights yt=B^(L)xt=j=nnB^jxt+j=B^0xt+j=1nB^j(xtj+xt+j) where B^j=Bj12n+1j=nnBj

If drift=TRUE the drift adjusted series is obtained x~t=xtt(xTx1T1),  t=0,1,,T1 where 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, bwfilter, cffilter, hpfilter, trfilter

Examples

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

data(unemp)

opar <- par(no.readonly=TRUE)

unemp.bk <- bkfilter(unemp)
plot(unemp.bk)
unemp.bk1 <- bkfilter(unemp, drift=TRUE)
unemp.bk2 <- bkfilter(unemp, pl=8,pu=40,drift=TRUE)
unemp.bk3 <- bkfilter(unemp, pl=2,pu=60,drift=TRUE)
unemp.bk4 <- bkfilter(unemp, pl=2,pu=40,drift=TRUE)

par(mfrow=c(2,1),mar=c(3,3,2,1),cex=.8)
plot(unemp.bk1$x,
    main="Baxter-King filter of unemployment: Trend, drift=TRUE",
    col=1, ylab="")
lines(unemp.bk1$trend,col=2)
lines(unemp.bk2$trend,col=3)
lines(unemp.bk3$trend,col=4)
lines(unemp.bk4$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.bk1$cycle,
main="Baxter-King filter of unemployment: Cycle,drift=TRUE",
      col=2, ylab="", ylim=range(unemp.bk3$cycle,na.rm=TRUE))
lines(unemp.bk2$cycle,col=3)
lines(unemp.bk3$cycle,col=4)
lines(unemp.bk4$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