For this task we need to obtain quarterly time series for Disposable Personal Income FRED/DPI
and for Personal Consumption Expenditures FRED/PCEC
.
library(Quandl)
library(vars)
Now first let’s load the data from Quandl website:
dpi<-Quandl("FRED/DPI", type="ts")
pce<-Quandl("FRED/PCEC", type="ts")
str(dpi)
## Time-Series [1:277] from 1947 to 2016: 171 170 178 180 185 ...
str(pce)
## Time-Series [1:277] from 1947 to 2016: 156 160 164 168 170 ...
Let’s log transform the series as \(y_{1,t} = \log PCE_t\) and \(y_{2,t} = \log PDI_t\).
y1<-log(pce)
dy1<-diff(y1)
y2<-log(dpi)
dy2<-diff(y2)
Now we test these log transformed time series and their first differences for unit root:
summary( ur.ers(y1, type="P-test", lag.max=8, model="trend") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 63.1974
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary( ur.ers(y2, type="P-test", lag.max=8, model="trend") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 83.7733
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
The test for log transformed series indicate that it is non-stationary. Let’s further look at the log difference of the series.
summary( ur.ers(dy1, type="P-test", lag.max=8, model="trend") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 1.7594
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary( ur.ers(dy2, type="P-test", lag.max=8, model="trend") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 2.2919
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
From the first difference of the series we can verify that they are in fact I(1).
NExt task is to perform the trace and max eigenvalue tests for cointegration of \(y_{1,t}\) and \(y_{2,t}\).
Trace Test
y.bind <- cbind(y1,y2)
y.trace <- ca.jo(y.bind, ecdet="const", type="trace", K=2, spec="transitory", season=4)
summary(y.trace)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: trace statistic , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 3.035673e-01 6.067856e-02 2.735830e-16
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 1 | 17.21 7.52 9.24 12.97
## r = 0 | 116.70 17.85 19.96 24.60
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## y1.l1 y2.l1 constant
## y1.l1 1.00000000 1.0000000 1.000000
## y2.l1 -1.00125397 -1.0165837 -0.961505
## constant 0.01523677 0.2530166 -0.154454
##
## Weights W:
## (This is the loading matrix)
##
## y1.l1 y2.l1 constant
## y1.d -0.10390559 -0.01391660 -1.224577e-13
## y2.d -0.07471752 0.08070184 2.163910e-14
Max Eigenvalue Test
y.ev <- ca.jo(y.bind, ecdet="const", type="eigen", K=2, spec="transitory", season=4)
summary(y.ev)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: maximal eigenvalue statistic (lambda max) , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 3.035673e-01 6.067856e-02 2.735830e-16
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 1 | 17.21 7.52 9.24 12.97
## r = 0 | 99.49 13.75 15.67 20.20
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## y1.l1 y2.l1 constant
## y1.l1 1.00000000 1.0000000 1.000000
## y2.l1 -1.00125397 -1.0165837 -0.961505
## constant 0.01523677 0.2530166 -0.154454
##
## Weights W:
## (This is the loading matrix)
##
## y1.l1 y2.l1 constant
## y1.d -0.10390559 -0.01391660 -1.224577e-13
## y2.d -0.07471752 0.08070184 2.163910e-14
From the results of both tests it is clear that there is on cointegration.
Now we have to perform the test for the presence of a restricted constant:
lttest(y.trace, r=1)
## LR-test for no linear trend
##
## H0: H*2(r<=1)
## H1: H2(r<=1)
##
## Test statistic is distributed as chi-square
## with 1 degress of freedom
## test statistic p-value
## LR test 10 0
From the results we can say that Constant should not be included.
y.VEC <- cajorls(y.trace, r=1)
y.VEC
## $rlm
##
## Call:
## lm(formula = substitute(form1), data = data.mat)
##
## Coefficients:
## y1.d y2.d
## ect1 -0.1039056 -0.0747175
## sd1 0.0017478 0.0020127
## sd2 0.0006162 0.0011779
## sd3 0.0027065 0.0017336
## y1.dl1 0.0569502 0.5009011
## y2.dl1 0.1877098 -0.0587900
##
##
## $beta
## ect1
## y1.l1 1.00000000
## y2.l1 -1.00125397
## constant 0.01523677
In this task we have to perform following three tests:
Test 1: \(\beta_2=-1\)
test1.beta2 <- matrix(c(1,0,0,
0,-1,0), c(3,2))
test1 <- blrtest(y.trace, H=test1.beta2, r=1)
summary(test1)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Estimation and testing under linear restrictions on beta
##
## The VECM has been estimated subject to:
## beta=H*phi and/or alpha=A*psi
##
## [,1] [,2]
## [1,] 1 0
## [2,] 0 -1
## [3,] 0 0
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.3034 0.0025
##
## The value of the likelihood ratio test statistic:
## 0.07 distributed as chi square with 1 df.
## The p-value of the test statistic is: 0.79
##
## Eigenvectors, normalised to first column
## of the restricted VAR:
##
## [,1] [,2]
## [1,] 1.0000 1.0000
## [2,] -1.0002 -0.9824
## [3,] 0.0000 0.0000
##
## Weights W of the restricted VAR:
##
## [,1] [,2]
## y1.d -0.0980 -0.0016
## y2.d -0.0715 0.0086
Test 2: \(\alpha_2=0\)
test2.alpha2 <- matrix(c(1,0), c(2,1))
test2 <- alrtest(y.trace, A=test2.alpha2, r=1)
summary(test2)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Estimation and testing under linear restrictions on beta
##
## The VECM has been estimated subject to:
## beta=H*phi and/or alpha=A*psi
##
## [,1]
## [1,] 1
## [2,] 0
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.2106 0.0000 0.0000
##
## The value of the likelihood ratio test statistic:
## 34.44 distributed as chi square with 1 df.
## The p-value of the test statistic is: 0
##
## Eigenvectors, normalised to first column
## of the restricted VAR:
##
## [,1]
## RK.y1.l1 1.0000
## RK.y2.l1 -1.0074
## RK.constant 0.1106
##
## Weights W of the restricted VAR:
##
## [,1]
## [1,] -0.1204
## [2,] 0.0000
Test 3: \(\beta_2=-1, \alpha_2=0\)
test3 <- ablrtest(y.trace, A=test2.alpha2, H=test1.beta2, r=1)
summary(test3)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Estimation and testing under linear restrictions on alpha and beta
##
## The VECM has been estimated subject to:
## beta=H*phi and/or alpha=A*psi
##
## [,1] [,2]
## [1,] 1 0
## [2,] 0 -1
## [3,] 0 0
##
##
## [,1]
## [1,] 1
## [2,] 0
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.1892 0.0000
##
## The value of the likelihood ratio test statistic:
## 41.83 distributed as chi square with 1 df.
## The p-value of the test statistic is: 0
##
## Eigenvectors, normalised to first column
## of the restricted VAR:
##
## [,1]
## [1,] 1.000
## [2,] -0.999
## [3,] 0.000
##
## Weights W of the restricted VAR:
##
## [,1]
## [1,] -0.0743
## [2,] 0.0000
Now we have to convert the VEC model into a VAR model in levels:
y.VAR <- vec2var(y.trace, r=1)
And create and plot eight quarter ahead forecast.
y.forecast <- predict(y.VAR, n.ahead=8)
plot(y.forecast)