Disposable PersonalIncome:FRED/DPI.
Personal Consumption Expenditures:FRED/PCEC
Attaching the packages needed to accomplish the work.
library(Quandl)
## Warning: package 'Quandl' was built under R version 3.2.5
## Loading required package: xts
## Warning: package 'xts' was built under R version 3.2.4
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.2.4
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(tseries)
## Warning: package 'tseries' was built under R version 3.2.5
library(urca)
## Warning: package 'urca' was built under R version 3.2.5
library(vars)
## Warning: package 'vars' was built under R version 3.2.5
## Loading required package: MASS
## Loading required package: strucchange
## Warning: package 'strucchange' was built under R version 3.2.4
## Loading required package: sandwich
## Warning: package 'sandwich' was built under R version 3.2.4
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 3.2.4
library(gdata)
## gdata: Unable to locate valid perl interpreter
## gdata:
## gdata: read.xls() will be unable to read Excel XLS and XLSX files
## gdata: unless the 'perl=' argument is used to specify the location
## gdata: of a valid perl intrpreter.
## gdata:
## gdata: (To avoid display of this message in the future, please
## gdata: ensure perl is installed and available on the executable
## gdata: search path.)
## gdata: Unable to load perl libaries needed by read.xls()
## gdata: to support 'XLX' (Excel 97-2004) files.
##
## gdata: Unable to load perl libaries needed by read.xls()
## gdata: to support 'XLSX' (Excel 2007+) files.
##
## gdata: Run the function 'installXLSXsupport()'
## gdata: to automatically download and install the perl
## gdata: libaries needed to support Excel XLS and XLSX formats.
##
## Attaching package: 'gdata'
## The following objects are masked from 'package:xts':
##
## first, last
## The following object is masked from 'package:stats':
##
## nobs
## The following object is masked from 'package:utils':
##
## object.size
income <- Quandl("FRED/DPI",api_key="T8gDpM8iFjXR9pfbXBmx",type = "zoo")
expenditure <- Quandl("FRED/PCEC", api_key="T8gDpM8iFjXR9pfbXBmx", type= "zoo")
y1 <- log(income)
dy1 <- diff(y1)
y2 <- log(expenditure)
dy2 <- diff(y2)
plot(dy1, xlab="Years", ylab="",main="Disposable Income Trend")
plot(dy2, xlab="years", ylab="",main="Consumption Expenditure Trends")
Zivot and Andrews Test
za.y1 <- ur.za(y1, model="both", lag=2)
summary(za.y1)
##
## ################################
## # Zivot-Andrews Unit Root Test #
## ################################
##
##
## Call:
## lm(formula = testmat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.048519 -0.004565 -0.000838 0.004413 0.060969
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.763e-02 3.661e-02 2.394 0.01737 *
## y.l1 9.848e-01 7.206e-03 136.648 < 2e-16 ***
## trend 3.212e-04 1.220e-04 2.634 0.00893 **
## y.dl1 4.192e-02 5.918e-02 0.708 0.47938
## y.dl2 1.201e-01 5.888e-02 2.039 0.04239 *
## du 7.823e-03 3.936e-03 1.987 0.04789 *
## dt -2.041e-04 3.951e-05 -5.166 4.7e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.009853 on 267 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 1, Adjusted R-squared: 0.9999
## F-statistic: 8.934e+05 on 6 and 267 DF, p-value: < 2.2e-16
##
##
## Teststatistic: -2.116
## Critical values: 0.01= -5.57 0.05= -5.08 0.1= -4.82
##
## Potential break point at position: 121
za.y2 <- ur.za(y2, model="both", lag=2)
summary(za.y2)
##
## ################################
## # Zivot-Andrews Unit Root Test #
## ################################
##
##
## Call:
## lm(formula = testmat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.036019 -0.003662 0.000183 0.004156 0.056841
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.560e-02 2.511e-02 2.612 0.00950 **
## y.l1 9.882e-01 5.198e-03 190.109 < 2e-16 ***
## trend 2.438e-04 1.002e-04 2.431 0.01570 *
## y.dl1 5.259e-02 5.677e-02 0.926 0.35513
## y.dl2 3.534e-01 5.666e-02 6.236 1.74e-09 ***
## du -2.222e-03 2.267e-03 -0.980 0.32791
## dt -1.803e-04 5.844e-05 -3.085 0.00225 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.008429 on 267 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.249e+06 on 6 and 267 DF, p-value: < 2.2e-16
##
##
## Teststatistic: -2.2711
## Critical values: 0.01= -5.57 0.05= -5.08 0.1= -4.82
##
## Potential break point at position: 193
za.dy1 <- ur.za(dy1, model="both", lag=2)
summary(za.dy1)
##
## ################################
## # Zivot-Andrews Unit Root Test #
## ################################
##
##
## Call:
## lm(formula = testmat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.048191 -0.004364 -0.000830 0.004444 0.061193
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.006e-02 2.112e-03 4.761 3.17e-06 ***
## y.l1 1.116e-01 9.895e-02 1.128 0.260359
## trend 9.424e-05 2.391e-05 3.942 0.000104 ***
## y.dl1 -7.970e-02 8.414e-02 -0.947 0.344408
## y.dl2 2.387e-02 5.979e-02 0.399 0.690041
## du -6.483e-03 2.462e-03 -2.633 0.008962 **
## dt -1.677e-04 3.559e-05 -4.711 3.98e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.009875 on 266 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.1999, Adjusted R-squared: 0.1819
## F-statistic: 11.08 on 6 and 266 DF, p-value: 5e-11
##
##
## Teststatistic: -8.9782
## Critical values: 0.01= -5.57 0.05= -5.08 0.1= -4.82
##
## Potential break point at position: 138
za.dy2 <- ur.za(dy2, model="both", lag=2)
summary(za.dy2)
##
## ################################
## # Zivot-Andrews Unit Root Test #
## ################################
##
##
## Call:
## lm(formula = testmat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.037180 -0.003309 -0.000036 0.004261 0.059127
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.114e-03 1.755e-03 4.053 6.65e-05 ***
## y.l1 2.139e-01 9.417e-02 2.271 0.02392 *
## trend 1.034e-04 2.138e-05 4.835 2.25e-06 ***
## y.dl1 -2.436e-01 8.394e-02 -2.903 0.00401 **
## y.dl2 2.399e-02 6.016e-02 0.399 0.69040
## du -5.615e-03 2.031e-03 -2.764 0.00611 **
## dt -1.748e-04 3.227e-05 -5.416 1.36e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.00818 on 266 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.3142, Adjusted R-squared: 0.2988
## F-statistic: 20.32 on 6 and 266 DF, p-value: < 2.2e-16
##
##
## Teststatistic: -8.3476
## Critical values: 0.01= -5.57 0.05= -5.08 0.1= -4.82
##
## Potential break point at position: 136
Explanation: The Difference data are stationary while log transformed data are not. It is decided by analysing the p-values at 0.01. Therefore, y1 and y2 are i(1).
Using Trace Method
j1 <- cbind(dy1,dy2)
Income_expenditures <- ca.jo(j1, ecdet="const", type="trace", K=2, spec="transitory")
summary(Income_expenditures)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: trace statistic , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 4.206346e-01 1.208725e-01 5.551115e-17
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 1 | 35.30 7.52 9.24 12.97
## r = 0 | 184.85 17.85 19.96 24.60
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## dy1.l1 dy2.l1 constant
## dy1.l1 1.0000000000 1.00000000 1.000000
## dy2.l1 -0.9871826303 2.48640003 2.368009
## constant -0.0002433448 -0.05460147 -0.735661
##
## Weights W:
## (This is the loading matrix)
##
## dy1.l1 dy2.l1 constant
## dy1.d -0.8817257 -0.1078676 -3.985992e-18
## dy2.d 0.4828511 -0.1096399 3.796507e-18
Income_expenditures <- ca.jo(j1, ecdet="const", type="eigen", K=2, spec="transitory")
summary(Income_expenditures)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: maximal eigenvalue statistic (lambda max) , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 4.206346e-01 1.208725e-01 5.551115e-17
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 1 | 35.30 7.52 9.24 12.97
## r = 0 | 149.56 13.75 15.67 20.20
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## dy1.l1 dy2.l1 constant
## dy1.l1 1.0000000000 1.00000000 1.000000
## dy2.l1 -0.9871826303 2.48640003 2.368009
## constant -0.0002433448 -0.05460147 -0.735661
##
## Weights W:
## (This is the loading matrix)
##
## dy1.l1 dy2.l1 constant
## dy1.d -0.8817257 -0.1078676 -3.985992e-18
## dy2.d 0.4828511 -0.1096399 3.796507e-18
lttest(Income_expenditures, 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 0.04 0.83
Income_expenditures.VEC <- cajorls(Income_expenditures, r=1)
Income_expenditures.VEC
## $rlm
##
## Call:
## lm(formula = substitute(form1), data = data.mat)
##
## Coefficients:
## dy1.d dy2.d
## ect1 -0.8817 0.4829
## dy1.dl1 -0.1259 -0.2345
## dy2.dl1 -0.3203 -0.4041
##
##
## $beta
## ect1
## dy1.l1 1.0000000000
## dy2.l1 -0.9871826303
## constant -0.0002433448
For Beta two equal to -1.
rest.beta2 <- matrix(c(0,-1,0,
0,0,1), c(3,2))
rbeta2 <- blrtest(Income_expenditures, H=rest.beta2, r=1)
summary(rbeta2)
##
## ######################
## # 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,] 0 0
## [2,] -1 0
## [3,] 0 1
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.1366 0.0000
##
## The value of the likelihood ratio test statistic:
## 109.32 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] [,2]
## [1,] NaN NaN
## [2,] -Inf Inf
## [3,] Inf -Inf
##
## Weights W of the restricted VAR:
##
## [,1] [,2]
## dy1.d NaN NaN
## dy2.d NaN NaN
For Alpha two is equal to zero.
r.a <- matrix(c(1,0), c(2,1))
A.ra <- alrtest(Income_expenditures, A=r.a, r=1)
summary(A.ra)
##
## ######################
## # 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.37 0.00 0.00
##
## The value of the likelihood ratio test statistic:
## 22.94 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.dy1.l1 1.0000
## RK.dy2.l1 -0.8341
## RK.constant -0.0026
##
## Weights W of the restricted VAR:
##
## [,1]
## [1,] -1.1798
## [2,] 0.0000
For Alpha and Beta two joint
joint <- ablrtest(Income_expenditures, A=r.a, H=rest.beta2, r=1)
summary(joint)
##
## ######################
## # 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,] 0 0
## [2,] -1 0
## [3,] 0 1
##
##
## [,1]
## [1,] 1
## [2,] 0
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.0014 0.0000
##
## The value of the likelihood ratio test statistic:
## 149.17 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,] NaN
## [2,] -Inf
## [3,] Inf
##
## Weights W of the restricted VAR:
##
## [,1]
## [1,] 0
## [2,] 0
var <- vec2var(Income_expenditures,r=1)
Forecast
forecast <- predict(var, n.ahead=8)
par( mar=c(4,4,2,1), cex= 0.25)
plot(forecast)