Description Usage Arguments Details Value Author(s) See Also Examples
mFilter
is a generic function for filtering
time series data. The function invokes particular
filters which depend on filter type specified via its argument
filter
. The filters implemented in the package mFilter
package are useful for smoothing, and estimating tend and cyclical components.
Some of these filters are commonly used in economics and
finance for estimating cyclical component of time series.
The mFilter
currently applies only to time series
objects. However a default method is available and should work for any
numeric
or vector
object.
1 2 3 4 5 |
x |
a regular a time series. |
filter |
filter type, the filter types are |
... |
Additional arguments to pass to the relevant filter
functions. These are passed to |
The default behaviour is to apply the default filter to
ts
objects.
An object of class "mFilter
".
The function summary
is used to obtain and print a summary of the
results, while the function plot
produces a plot of the original
series, the trend, and the cyclical components. The function print
is also available
for displaying estimation results.
The generic accessor functions fitted
and residuals
extract estimated trend and cyclical componets of an "mFilter
"
object, respectively.
An object of class "mFilter
" is a list containing at least the following elements:
cycle |
Estimated cyclical (irregular) component of the series. |
trend |
Estimated trend (smooth) component of the series. |
fmatrix |
The filter matrix applied to original series. |
method |
The method, if available, for the filter type applied. |
type |
The filter type applied to the series. |
call |
Call to the function. |
title |
The title for displaying results. |
xname |
Name of the series passed to |
x |
The original or drift adjusted, if |
Following additional elements may exists depending on the type of filter applied:
nfix |
Length or order of the fixed length filters. |
pl |
Minimum period of oscillation of desired component (2<=pl). |
pu |
Maximum period of oscillation of desired component (2<=pl<pu<infinity). |
lambda |
Lambda (smoothness) parameter of the HP filter. |
root |
Whether time series has a unit root, TRUE or FALSE (default). |
drift |
Whether time series has drift, TRUE or FALSE (default). |
theta |
MA coefficients for time series model, used in |
Mehmet Balcilar, mehmet@mbalcilar.net
Other functions which return objects of class "mFilter"
are
bkfilter
,
bwfilter
,
cffilter
,
bkfilter
,
trfilter
.
Following functions apply the relevant methods to an object of the
"mFilter"
class:
print.mFilter
,
summary.mFilter
,
plot.mFilter
,
fitted.mFilter
,
residuals.mFilter
.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ## library(mFilter)
data(unemp)
opar <- par(no.readonly=TRUE)
unemp.hp <- mFilter(unemp,filter="HP") # Hodrick-Prescott filter
print(unemp.hp)
summary(unemp.hp)
residuals(unemp.hp)
fitted(unemp.hp)
plot(unemp.hp)
unemp.bk <- mFilter(unemp,filter="BK") # Baxter-King filter
unemp.cf <- mFilter(unemp,filter="CF") # Christiano-Fitzgerald filter
unemp.bw <- mFilter(unemp,filter="BW") # Butterworth filter
unemp.tr <- mFilter(unemp,filter="TR") # Trigonometric regression filter
par(mfrow=c(2,1),mar=c(3,3,2,1),cex=.8)
plot(unemp,main="Unemployment Series & Estimated Trend", col=1, ylab="")
lines(unemp.hp$trend,col=2)
lines(unemp.bk$trend,col=3)
lines(unemp.cf$trend,col=4)
lines(unemp.bw$trend,col=5)
lines(unemp.tr$trend,col=6)
legend("topleft",legend=c("series", "HP","BK","CF","BW","TR"),
col=1:6,lty=rep(1,6),ncol=2)
plot(unemp.hp$cycle,main="Estimated Cyclical Component",
ylim=c(-2,2.5),col=2,ylab="")
lines(unemp.bk$cycle,col=3)
lines(unemp.cf$cycle,col=4)
lines(unemp.bw$cycle,col=5)
lines(unemp.tr$cycle,col=6)
## legend("topleft",legend=c("HP","BK","CF","BW","TR"),
## col=2:6,lty=rep(1,5),ncol=2)
unemp.cf1 <- mFilter(unemp,filter="CF", drift=TRUE, root=TRUE)
unemp.cf2 <- mFilter(unemp,filter="CF", pl=8,pu=40,drift=TRUE, root=TRUE)
unemp.cf3 <- mFilter(unemp,filter="CF", pl=2,pu=60,drift=TRUE, root=TRUE)
unemp.cf4 <- mFilter(unemp,filter="CF", pl=2,pu=40,drift=TRUE,
root=TRUE,theta=c(.1,.4))
plot(unemp,
main="Christiano-Fitzgerald filter of unemployment: Trend \n root=TRUE,drift=TRUE",
col=1, ylab="")
lines(unemp.cf1$trend,col=2)
lines(unemp.cf2$trend,col=3)
lines(unemp.cf3$trend,col=4)
lines(unemp.cf4$trend,col=5)
legend("topleft",legend=c("series", "pl=2, pu=32", "pl=8, pu=40",
"pl=2, pu=60", "pl=2, pu=40, theta=.1,.4"), col=1:5, lty=rep(1,5), ncol=1)
plot(unemp.cf1$cycle,
main="Christiano-Fitzgerald filter of unemployment: Cycle \n root=TRUE,drift=TRUE",
col=2, ylab="", ylim=range(unemp.cf3$cycle))
lines(unemp.cf2$cycle,col=3)
lines(unemp.cf3$cycle,col=4)
lines(unemp.cf4$cycle,col=5)
## legend("topleft",legend=c("pl=2, pu=32", "pl=8, pu=40", "pl=2, pu=60",
## "pl=2, pu=40, theta=.1,.4"), col=2:5, lty=rep(1,4), ncol=2)
par(opar)
|
Title:
Hodrick-Prescott Filter
Call:
hpfilter(x = x, freq = ag$freq, type = ag$type, drift = ag$drift)
Method:
hpfilter
Filter Type:
lambda
Series:
unemp
unemp Trend Cycle
1959 Q1 5.833 5.779 0.054097
1959 Q2 5.100 5.793 -0.692883
1959 Q3 5.267 5.807 -0.539896
1959 Q4 5.600 5.820 -0.219877
1960 Q1 5.133 5.832 -0.698756
1960 Q2 5.233 5.842 -0.608992
1960 Q3 5.533 5.849 -0.315941
1960 Q4 6.267 5.851 0.415422
1961 Q1 6.800 5.846 0.953652
1961 Q2 7.000 5.833 1.167046
1961 Q3 6.767 5.810 0.956636
1961 Q4 6.200 5.777 0.422726
1962 Q1 5.633 5.735 -0.101644
1962 Q2 5.533 5.684 -0.150366
1962 Q3 5.567 5.624 -0.057268
1962 Q4 5.533 5.556 -0.022751
1963 Q1 5.767 5.481 0.286154
1963 Q2 5.733 5.398 0.335762
1963 Q3 5.500 5.308 0.192210
1963 Q4 5.567 5.212 0.354760
1964 Q1 5.467 5.111 0.355885
1964 Q2 5.200 5.005 0.194503
1964 Q3 5.000 4.897 0.102644
1964 Q4 4.967 4.788 0.178883
1965 Q1 4.900 4.678 0.221730
1965 Q2 4.667 4.570 0.096251
1965 Q3 4.367 4.466 -0.099294
1965 Q4 4.100 4.367 -0.266705
1966 Q1 3.867 4.274 -0.407720
1966 Q2 3.833 4.191 -0.357244
1966 Q3 3.767 4.117 -0.349925
1966 Q4 3.700 4.054 -0.353525
1967 Q1 3.833 4.002 -0.168918
1967 Q2 3.833 3.963 -0.130090
1967 Q3 3.800 3.938 -0.137589
1967 Q4 3.900 3.925 -0.025216
1968 Q1 3.733 3.927 -0.193350
1968 Q2 3.567 3.942 -0.375690
1968 Q3 3.533 3.972 -0.439147
1968 Q4 3.400 4.017 -0.617063
1969 Q1 3.400 4.076 -0.675840
1969 Q2 3.433 4.148 -0.714826
1969 Q3 3.567 4.233 -0.666283
1969 Q4 3.567 4.329 -0.762022
1970 Q1 4.167 4.433 -0.266774
1970 Q2 4.767 4.545 0.221874
1970 Q3 5.167 4.660 0.506501
1970 Q4 5.833 4.777 1.056214
1971 Q1 5.933 4.894 1.039805
1971 Q2 5.900 5.008 0.892072
1971 Q3 6.033 5.120 0.913828
1971 Q4 5.933 5.228 0.705330
1972 Q1 5.767 5.334 0.432931
1972 Q2 5.700 5.437 0.262541
1972 Q3 5.567 5.540 0.026469
1972 Q4 5.367 5.643 -0.276476
1973 Q1 4.933 5.747 -0.814166
1973 Q2 4.933 5.854 -0.920969
1973 Q3 4.800 5.964 -1.164076
1973 Q4 4.767 6.077 -1.310103
1974 Q1 5.133 6.192 -1.058272
1974 Q2 5.200 6.307 -1.106985
1974 Q3 5.633 6.421 -0.787317
1974 Q4 6.600 6.530 0.070348
1975 Q1 8.267 6.631 1.636121
1975 Q2 8.867 6.720 2.146732
1975 Q3 8.467 6.795 1.671225
1975 Q4 8.300 6.856 1.443968
1976 Q1 7.733 6.902 0.831616
1976 Q2 7.567 6.933 0.633256
1976 Q3 7.733 6.953 0.780791
1976 Q4 7.767 6.961 0.805724
1977 Q1 7.500 6.961 0.539074
1977 Q2 7.133 6.955 0.178019
1977 Q3 6.900 6.947 -0.047263
1977 Q4 6.667 6.940 -0.273374
1978 Q1 6.333 6.937 -0.603552
1978 Q2 6.000 6.941 -0.940865
1978 Q3 6.033 6.955 -0.921336
1978 Q4 5.900 6.980 -1.080402
1979 Q1 5.867 7.020 -1.152922
1979 Q2 5.700 7.073 -1.373080
1979 Q3 5.867 7.141 -1.274342
1979 Q4 5.967 7.223 -1.255979
1980 Q1 6.300 7.316 -1.016467
1980 Q2 7.333 7.420 -0.086831
1980 Q3 7.667 7.531 0.135873
1980 Q4 7.400 7.645 -0.245356
1981 Q1 7.433 7.761 -0.327605
1981 Q2 7.400 7.874 -0.474472
1981 Q3 7.400 7.983 -0.582688
1981 Q4 8.233 8.082 0.151317
1982 Q1 8.833 8.169 0.664808
1982 Q2 9.433 8.238 1.194957
1982 Q3 9.900 8.288 1.611852
1982 Q4 10.667 8.315 2.351502
1983 Q1 10.367 8.318 2.048909
1983 Q2 10.133 8.296 1.837604
1983 Q3 9.367 8.250 1.116505
1983 Q4 8.533 8.183 0.350048
1984 Q1 7.867 8.098 -0.231362
1984 Q2 7.433 7.998 -0.564206
1984 Q3 7.433 7.885 -0.451486
1984 Q4 7.300 7.763 -0.462520
1985 Q1 7.233 7.633 -0.399674
1985 Q2 7.300 7.498 -0.198363
1985 Q3 7.200 7.360 -0.160413
1985 Q4 7.033 7.221 -0.187531
1986 Q1 7.033 7.081 -0.047987
1986 Q2 7.167 6.943 0.223396
1986 Q3 6.967 6.808 0.158496
1986 Q4 6.833 6.678 0.155714
1987 Q1 6.600 6.553 0.046689
1987 Q2 6.267 6.437 -0.170375
1987 Q3 6.000 6.331 -0.330632
1987 Q4 5.833 6.236 -0.402466
1988 Q1 5.700 6.154 -0.454053
1988 Q2 5.467 6.087 -0.619985
1988 Q3 5.467 6.035 -0.567902
1988 Q4 5.333 5.998 -0.665059
1989 Q1 5.200 5.978 -0.778353
1989 Q2 5.233 5.974 -0.740934
1989 Q3 5.233 5.985 -0.752132
1989 Q4 5.367 6.011 -0.644147
1990 Q1 5.300 6.049 -0.748708
1990 Q2 5.333 6.097 -0.763811
1990 Q3 5.700 6.154 -0.453647
1990 Q4 6.133 6.215 -0.081932
1991 Q1 6.600 6.279 0.321236
1991 Q2 6.833 6.341 0.492475
1991 Q3 6.867 6.398 0.468206
1991 Q4 7.100 6.449 0.651204
1992 Q1 7.367 6.489 0.877289
1992 Q2 7.600 6.518 1.081871
1992 Q3 7.633 6.534 1.099814
1992 Q4 7.367 6.535 0.831970
1993 Q1 7.133 6.521 0.611840
1993 Q2 7.067 6.494 0.572402
1993 Q3 6.800 6.454 0.346253
1993 Q4 6.633 6.401 0.232300
1994 Q1 6.567 6.337 0.229232
1994 Q2 6.200 6.264 -0.064408
1994 Q3 6.000 6.184 -0.183550
1994 Q4 5.633 6.096 -0.463088
1995 Q1 5.467 6.004 -0.537799
1995 Q2 5.667 5.909 -0.242170
1995 Q3 5.667 5.810 -0.143687
1995 Q4 5.567 5.710 -0.143017
1996 Q1 5.533 5.607 -0.074071
1996 Q2 5.500 5.504 -0.004002
1996 Q3 5.267 5.400 -0.133253
1996 Q4 5.333 5.296 0.037736
1997 Q1 5.267 5.191 0.075278
1997 Q2 5.000 5.088 -0.087674
1997 Q3 4.867 4.985 -0.118213
1997 Q4 4.667 4.883 -0.216712
1998 Q1 4.667 4.783 -0.116800
1998 Q2 4.433 4.685 -0.251974
1998 Q3 4.500 4.589 -0.088990
1998 Q4 4.433 4.494 -0.061113
1999 Q1 4.300 4.402 -0.101552
1999 Q2 4.300 4.310 -0.010146
1999 Q3 4.233 4.220 0.013331
1999 Q4 4.100 4.131 -0.030890
2000 Q1 4.033 4.043 -0.009251
2000 Q2 4.033 3.955 0.078490
2000 Q3 4.000 3.867 0.132581
2000 Q4 3.967 3.780 0.186556
Title:
Hodrick-Prescott Filter
Call:
hpfilter(x = x, freq = ag$freq, type = ag$type, drift = ag$drift)
Method:
hpfilter
Filter Type:
lambda
Series:
unemp
Descriptive Statistics:
unemp Trend Cycle
Min. : 3.400 Min. :3.780 Min. :-1.37308
1st Qu.: 5.000 1st Qu.:5.007 1st Qu.:-0.45203
Median : 5.700 Median :5.982 Median :-0.08725
Mean : 5.948 Mean :5.948 Mean : 0.00000
3rd Qu.: 7.008 3rd Qu.:6.867 3rd Qu.: 0.32487
Max. :10.667 Max. :8.318 Max. : 2.35150
In-sample error measures:
ME MSE MAE MPE MAPE
-7.523e-17 4.780e-01 5.175e-01 -1.533e-02 8.488e-02
Qtr1 Qtr2 Qtr3 Qtr4
1959 0.054096813 -0.692882513 -0.539895648 -0.219876687
1960 -0.698755619 -0.608991679 -0.315940714 0.415422053
1961 0.953652190 1.167045629 0.956635603 0.422725942
1962 -0.101644092 -0.150366102 -0.057268166 -0.022751052
1963 0.286153603 0.335761711 0.192210338 0.354760034
1964 0.355884550 0.194502578 0.102643718 0.178882669
1965 0.221729981 0.096251066 -0.099293910 -0.266704938
1966 -0.407719951 -0.357243525 -0.349925409 -0.353525411
1967 -0.168917967 -0.130089893 -0.137589100 -0.025215522
1968 -0.193349772 -0.375690031 -0.439146974 -0.617063135
1969 -0.675839913 -0.714826379 -0.666282534 -0.762021614
1970 -0.266773763 0.221873807 0.506500617 1.056214184
1971 1.039805460 0.892071933 0.913827877 0.705330022
1972 0.432930622 0.262541099 0.026468962 -0.276475704
1973 -0.814166022 -0.920968986 -1.164076066 -1.310103132
1974 -1.058271834 -1.106985012 -0.787317417 0.070348066
1975 1.636120623 2.146732140 1.671225263 1.443967595
1976 0.831615557 0.633256423 0.780791042 0.805724477
1977 0.539073796 0.178019157 -0.047262870 -0.273373645
1978 -0.603551653 -0.940864523 -0.921335996 -1.080401773
1979 -1.152921719 -1.373080451 -1.274342007 -1.255978916
1980 -1.016467246 -0.086831410 0.135872806 -0.245356118
1981 -0.327604619 -0.474472456 -0.582687966 0.151317058
1982 0.664808337 1.194957017 1.611852075 2.351502305
1983 2.048909092 1.837604135 1.116505229 0.350048335
1984 -0.231361736 -0.564205620 -0.451486019 -0.462519672
1985 -0.399674474 -0.198362576 -0.160413002 -0.187530799
1986 -0.047987420 0.223396219 0.158495863 0.155714300
1987 0.046688591 -0.170374857 -0.330632150 -0.402466245
1988 -0.454053452 -0.619985208 -0.567902499 -0.665058819
1989 -0.778352726 -0.740933780 -0.752131738 -0.644146608
1990 -0.748708314 -0.763810856 -0.453646958 -0.081931962
1991 0.321235654 0.492475283 0.468205549 0.651203943
1992 0.877288663 1.081870904 1.099813554 0.831970001
1993 0.611839580 0.572401647 0.346253157 0.232299982
1994 0.229231583 -0.064407763 -0.183550384 -0.463088353
1995 -0.537799025 -0.242170322 -0.143687377 -0.143017300
1996 -0.074070729 -0.004002249 -0.133253486 0.037736437
1997 0.075278346 -0.087673849 -0.118213291 -0.216711657
1998 -0.116800075 -0.251974230 -0.088990136 -0.061112994
1999 -0.101552385 -0.010146360 0.013330500 -0.030890045
2000 -0.009251233 0.078489670 0.132581181 0.186556094
Qtr1 Qtr2 Qtr3 Qtr4
1959 5.779237 5.792883 5.806562 5.819877
1960 5.832089 5.842325 5.849274 5.851245
1961 5.846348 5.832954 5.810031 5.777274
1962 5.734977 5.683699 5.623935 5.556084
1963 5.480513 5.397572 5.307790 5.211907
1964 5.110782 5.005497 4.897356 4.787784
1965 4.678270 4.570416 4.465961 4.366705
1966 4.274387 4.190577 4.116592 4.053525
1967 4.002251 3.963423 3.937589 3.925216
1968 3.926683 3.942357 3.972480 4.017063
1969 4.075840 4.148160 4.232949 4.328688
1970 4.433440 4.544793 4.660166 4.777119
1971 4.893528 5.007928 5.119505 5.228003
1972 5.333736 5.437459 5.540198 5.643142
1973 5.747499 5.854302 5.964076 6.076770
1974 6.191605 6.306985 6.420651 6.529652
1975 6.630546 6.719935 6.795441 6.856032
1976 6.901718 6.933410 6.952542 6.960942
1977 6.960926 6.955314 6.947263 6.940040
1978 6.936885 6.940865 6.954669 6.980402
1979 7.019588 7.073080 7.141009 7.222646
1980 7.316467 7.420165 7.530794 7.645356
1981 7.760938 7.874472 7.982688 8.082016
1982 8.168525 8.238376 8.288148 8.315164
1983 8.317758 8.295729 8.250161 8.183285
1984 8.098028 7.997539 7.884819 7.762520
1985 7.633008 7.498363 7.360413 7.220864
1986 7.081321 6.943270 6.808171 6.677619
1987 6.553311 6.437042 6.330632 6.235800
1988 6.154053 6.086652 6.034569 5.998392
1989 5.978353 5.974267 5.985465 6.010813
1990 6.048708 6.097144 6.153647 6.215265
1991 6.278764 6.340858 6.398461 6.448796
1992 6.489378 6.518129 6.533520 6.534697
1993 6.521494 6.494265 6.453747 6.401033
1994 6.337435 6.264408 6.183550 6.096422
1995 6.004466 5.908837 5.810354 5.709684
1996 5.607404 5.504002 5.399920 5.295597
1997 5.191388 5.087674 4.984880 4.883378
1998 4.783467 4.685308 4.588990 4.494446
1999 4.401552 4.310146 4.220003 4.130890
2000 4.042585 3.954844 3.867419 3.780111
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.