3. Table 4.2: Parameter Estimates - Least Square Estimations - R
> reg1 <- lm(cbind(df1$Y1t,df1$Y2t,df1$Y3t,df1$Y4t) ~ df1$GDP +
+ df1$GDP.1 + df1$GDP.2 + df1$DJIA.1 + df1$CPI)
> reg1$coefficients
[,1] [,2] [,3] [,4]
(Intercept) 777627.09661 -27084.663452 -5201.6629663 -54006.488874
df1$GDP 175401.30692 4173.497742 13974.9142752 29242.491488
df1$GDP.1 -36455.81505 -7546.185360 -4211.7261226 9150.613030
df1$GDP.2 -75015.94665 7829.347243 14931.1867830 -2403.837672
df1$DJIA.1 23.90672 1.247541 -0.0428268 -1.867618
df1$CPI -5779.45128 2466.320767 -451.6185712 619.559370
In SAS VARMAX Procedure, we can choose to use least square estimation by adding METHOD = LS in MODEL clause.
lm in R software uses the method of least square estimation only. There is no significant difference between coefficients
in Table 4.1 and Table 4.2. Use summary(reg1), we can get standard error, t value and p-value just like Table 4.1.
However, the results from summary(reg1) is too lengthy so I decide to not to show.
According to Table 4.2 (round to 5 digits after decimal), the equation for VARX(0,0) model is
ˆy1,t
ˆy2,t
ˆy3,t
ˆy4,t
=
777627.09661
−27084.66345
−5201.66297
−54006.48887
+
175401.30692 −36455.81505 −75015.94665 23.90672 −5779.45128
4173.49774 −7546.18536 7829.34724 1.24754 2466.32077
13974.91428 −4211.72612 14931.18678 −0.04283 −451.61857
29242.49149 9150.61303 −2403.83767 −1.86762 619.55937
GDPt
GDPt−1
GDPt−2
DJIAt−1
CPIt
3
4. 5 VARX(1,0) by SAS and R
5.1 VARX(1,0) without restrictions
In R software, vars package provides VAR function to fit VARX model by least squares per equation. In SAS software,
we can chose ML, conditional ML or least squares. However, for this data, SAS software fails to estimate parameters
and shows ERROR: Optimization cannot be completed, if use ML or conditional ML.
Table 5.1: Model Parameter Estimations - SAS
Model Parameter Estimates
Equation Parameter Estimate Standard Error t Value Pr > |t| Variable
Y1t CONST1 −138568.2188 384566.44338 −0.36 0.7244 1
XL0_1_1 175712.21495 37440.58373 4.69 0.0004 GDP(t)
XL0_1_2 −238864.7623 72981.27416 −3.27 0.0061 GDP_1(t)
XL0_1_3 5206.34733 45878.71597 0.11 0.9114 GDP_2(t)
XL0_1_4 4.32965 9.07958 0.48 0.6414 DJIA_1(t)
XL0_1_5 −1838.52061 5367.62007 −0.34 0.7374 CPI(t)
AR1_1_1 0.78748 0.19798 3.98 0.0016 Y1t(t−1)
AR1_1_2 2.00610 1.26674 1.58 0.1373 Y2t(t−1)
AR1_1_3 −0.02937 2.00817 −0.01 0.9886 Y3t(t−1)
AR1_1_4 0.53449 2.47715 0.22 0.8325 Y4t(t−1)
Y2t CONST2 −90511.94320 42928.71297 −2.11 0.0550 1
XL0_2_1 5626.81231 4179.44961 1.35 0.2012 GDP(t)
XL0_2_2 23142.83745 8146.81630 2.84 0.0139 GDP_1(t)
XL0_2_3 −1960.13723 5121.38868 −0.38 0.7081 GDP_2(t)
XL0_2_4 −0.52221 1.01354 −0.52 0.6150 DJIA_1(t)
XL0_2_5 2649.37949 599.18130 4.42 0.0007 CPI(t)
AR1_2_1 0.00115 0.02210 0.05 0.9594 Y1t(t−1)
AR1_2_2 0.29378 0.14141 2.08 0.0581 Y2t(t−1)
AR1_2_3 0.53691 0.22417 2.40 0.0324 Y3t(t−1)
AR1_2_4 −1.00662 0.27652 −3.64 0.0030 Y4t(t−1)
Y3t CONST3 1950.28068 36837.27329 0.05 0.9586 1
XL0_3_1 4332.87985 3586.39980 1.21 0.2485 GDP(t)
XL0_3_2 1454.17407 6990.81053 0.21 0.8384 GDP_1(t)
XL0_3_3 8999.78992 4394.68089 2.05 0.0613 GDP_2(t)
XL0_3_4 0.04481 0.86973 0.05 0.9597 DJIA_1(t)
XL0_3_5 155.90712 514.15949 0.30 0.7665 CPI(t)
AR1_3_1 0.02446 0.01896 1.29 0.2196 Y1t(t−1)
AR1_3_2 −0.14084 0.12134 −1.16 0.2666 Y2t(t−1)
AR1_3_3 0.88377 0.19236 4.59 0.0005 Y3t(t−1)
AR1_3_4 −0.25965 0.23728 −1.09 0.2937 Y4t(t−1)
Y4t CONST4 66724.03690 32404.01465 2.06 0.0601 1
XL0_4_1 16288.90163 3154.78702 5.16 0.0002 GDP(t)
XL0_4_2 −10826.97884 6149.48682 −1.76 0.1018 GDP_1(t)
4
5. Table 5.1: Model Parameter Estimations - SAS
Model Parameter Estimates
Equation Parameter Estimate Standard Error t Value Pr > |t| Variable
XL0_4_3 −6046.35443 3865.79383 −1.56 0.1418 GDP_2(t)
XL0_4_4 1.28271 0.76506 1.68 0.1175 DJIA_1(t)
XL0_4_5 580.21030 452.28189 1.28 0.2219 CPI(t)
AR1_4_1 −0.01138 0.01668 −0.68 0.5071 Y1t(t−1)
AR1_4_2 −0.39193 0.10674 −3.67 0.0028 Y2t(t−1)
AR1_4_3 0.48076 0.16921 2.84 0.0139 Y3t(t−1)
AR1_4_4 0.86201 0.20873 4.13 0.0012 Y4t(t−1)
Table 5.2: Covariance matrix of residuals - SAS
Covariances of Innovations
Variable Y1t Y2t Y3t Y4t
Y1t 747331773.51 19587262.285 30483755.224 27425710.675
Y2t 19587262.285 9312502.7109 1240027.6894 2258369.7439
Y3t 30483755.224 1240027.6894 6857181.2306 1106124.7065
Y4t 27425710.675 2258369.7439 1106124.7065 5306013.0675
Table 5.3: Information Criteria of VARX(1,0) Model without restriction - SAS
Information Criteria
AICC 1502.229
HQC 1698.651
AIC 1684.372
SBC 1741.147
FPEC 6.278E29
Code in SAS:
PROC VARMAX DATA = rawdata;
MODEL Y1t Y2t Y3t Y4t = GDP GDP_1 GDP_2 DJIA_1 CPI/
P = 1 XLAG = 0 METHOD = LS;
RUN;
5
17. Table 6.3: Information Criteria of VAR(1,2) model without restriction - SAS
Information Criteria
AICC 1392.215
HQC 1605.712
AIC 1588.749
SBC 1660.757
FPEC 4.294E29
There are several packages available in R to fit VARX models. However, packages like MTS, BigVAR and fastVAR all
use R base function solve with default tolerance level,1e-16. This is problematic for this dataset. If the tolerance level
is "high"(large numeric value), the software will treat input matrix as singular matrix computationally. Unfortunately,
I have not found any package that provides function to change the tolerance level. Later on, I will modify MTS:VARX
function by adding a component,tol, so we can estimate parameters of VAR(1,2) model.Error message from using
MTS::VARX is shown in Table 6.4, line7 and 8.
Table 6.4: Fail to Estimate VARX(1,2) by MTS::VARX - R
1 > library(MTS)
2 > endogenous <- cbind.data.frame(df1$Y1t,df1$Y2t,df1$Y3t,df1$Y4t)
3 > names(endogenous) <- c("Y1t","Y2t","Y3t","Y4t")
4 > exogenous <- cbind(df1$GDP,df1$DJIA,df1$CPI)
5 > names(exogenous) <- c("GDP","DJIA","CPI")
6 > MTS::VARX(zt = df1[,2:5], p = 1, xt = exogenous, m = 2, include.mean = T)
7 Error in solve.default(xpx) :
8 system is computationally singular: reciprocal condition number = 5.14308e-17
There isn’t significant difference between the estimated parameters from Table 6.1 and Table 6.5. R and SAS software
give same estimated parameters. However, the se / standard error and covariance matrix of residuals from R and SAS
output are different! The modified varx function can be found at section 6.2.
Table 6.5: Model Parameter Estimates - R
1 > exogenous <- cbind(df1$GDP,df1$DJIA,df1$CPI)
2 > names(exogenous) <- c("GDP","DJIA","CPI")
3 > varx(zt = df1[,2:5], p = 1, xt = exogenous, m = 2,
4 + include.mean = T, tol = 1e-17)
5 constant term:
6 est: 246291.3 20797.39 -16601.31 51273.02
7 se: 276302.9 37643.34 37598.88 35043.14
8 AR( 1 ) matrix
9 Y1t Y2t Y3t Y4t
10 Y1t 0.601 1.764 1.844 -0.208
11 Y2t 0.002 0.488 0.890 -1.198
12 Y3t 0.013 -0.131 0.728 -0.152
13 Y4t -0.019 -0.391 0.369 0.825
14 standard errors
15 [,1] [,2] [,3] [,4]
16 [1,] 0.101 0.774 1.252 1.311
17 [2,] 0.014 0.105 0.171 0.179
18 [3,] 0.014 0.105 0.170 0.178
17
26. Table 6.8: Covariance matrix of residuals - SAS
Covariances of Innovations
Variable Y1t Y2t Y3t Y4t
Y1t 5165530498.7 314559262.97 248467883.43 471482909.10
Y2t 314559262.97 151210399.46 46854526.794 124725426.62
Y3t 248467883.43 46854526.794 54338000.081 44670584.728
Y4t 471482909.10 124725426.62 44670584.728 208909954.10
Table 6.9: Information Criteria of Model with restrictions - SAS
Information Criteria
AICC 720.7625
HQC 1738.417
AIC 1732.762
SBC 1756.765
FPEC 1.633E34
The estimated parameters information, list of restricted parameters and information criteria, generated by SAS VAR-
MAX Procedure, could be found in Table 6.6, Table 6.7 and Table 6.9 respectively. Comparing Table 6.3 and Table
6.9, we have that restriction is necessary since information criterion decrease much from model without restriction to
model with restrictions.
Code in SAS:
PROC VARMAX DATA = rawdata;
MODEL Y1t Y2t Y3t Y4t = GDP DJIA CPI/
P = 1 XLAG = 2 METHOD = LS;
RESTRICT
CONST(1) = 0,XL(0,1,3) = 0,XL(1,1,2) = 0,
XL(1,1,3) = 0,XL(2,1,1) = 0,XL(2,1,2) = 0,
XL(2,1,3) = 0,AR(1,1,2) = 0,AR(1,1,3) = 0,
AR(1,1,4) = 0,CONST(2) = 0,XL(0,2,1) = 0,
XL(0,2,2) = 0,XL(1,2,1) = 0,XL(1,2,2) = 0,
XL(1,2,3) = 0,XL(2,2,1) = 0,XL(2,2,2) = 0,
XL(2,2,3) = 0,AR(1,2,1) = 0,CONST(3) = 0,
XL(0,3,1) = 0,XL(0,3,2) = 0,XL(0,3,3) = 0,
XL(1,3,1) = 0,XL(1,3,2) = 0,XL(1,3,3) = 0,
XL(2,3,1) = 0,XL(2,3,2) = 0,XL(2,3,3) = 0,
AR(1,3,1) = 0,AR(1,3,2) = 0,AR(1,3,4) = 0,
CONST(4) = 0,XL(0,4,2) = 0,XL(0,4,3) = 0,
XL(1,4,1) = 0,XL(1,4,2) = 0,XL(1,4,3) = 0,
XL(2,4,1) = 0,XL(2,4,2) = 0,XL(2,4,3) = 0,
AR(1,4,1) = 0,AR(1,4,3) = 0
;
RUN;
For VARX(1,2) model with same restriction in Table 6.7, the estimated parameters from R and SAS are different again
just like what we have in section 5.2. Table 6.10 contains estimated parameters for VARX(1,2) model with restrictions
by R software.
26
30. 7 Forecast based on VARX(1,2) with restrictions
We need to modify the dataset so we can build VARX(1,2) models based on observations from year 1992 to year 2014
then forecast for year 2015.
Table 7.1: Last 6 observations from modified dataset
Obs Year Y1t Y2t Y3t Y4t GDP DJIA CPI
19 2010 742913 580530 260435 603757 14.964 11577.5 218.056
20 2011 812938 609137 271612 624766 15.518 12217.6 224.939
21 2012 886494 628205 274000 642313 16.155 13104.1 229.594
22 2013 959294 640847 281840 651874 16.692 16576.7 232.957
23 2014 1020851 669165 299263 667163 17.393 17823.07 236.736
24 2015 . . . . 18.037 17425.03 237.017
Code in SAS for data import:
PROC IMPORT FILE = "C:/Users/Kevin Liu/Desktop/Book2.csv" OUT = df2;
RUN;
Code in R for data import:
df2 <- read.csv(file = "C:/Users/Kevin Liu/Desktop/Book2.csv")
7.1 Forecast via SAS
According to Table 7.2, Table 7.3 and Table 7.4, the equation of VARX(1,2) model for forecasting is:
y1,t
y2,t
y3,t
y4,t
=
0
0
0
0
+
50174.73125 18.00883 0
0 0 0
0 0 0
15724.42719 0 0
GDPt
DJIAt
CPIt
+
−36281.40682 0 0
0 0 0
0 0 0
0 0 0
GDPt−1
DJIAt−1
CPIt−1
+
0 0 0
0 0 0
0 0 0
0 0 0
GDPt−2
DJIAt−2
CPIt−2
+
0.5207 0 0 0
0 1.02625 0.41863 −0.16745
0 0 1.04812 0
0 −0.02316 0 0.65136
y1,t−1
y2,t−1
y3,t−1
y4,t−1
+
ξ1,t
ξ2,t
ξ3,t
ξ4,t
(7.1)
where ξt is a 4-dimensional Gaussian vector white noise process, VWN(0, Σ).
ˆΣ =
10699358614 715994057.43 438950329.55 995560416.12
715994057.43 173917231.03 62412049.314 95035472.176
438950329.55 62412049.314 61739028.580 48801287.342
995560416.12 95035472.176 48801287.342 166981942.52
The Equation 7.1 implies that GDP, Dow Jones Industrial Average(DJIA) and CPI have no relationship with current
year’s motor and parts dealers’ sales, food and beverage stores sales, health and personal care stores sales and gen-
eral merchandise stores sales. Current year’s GDP and DJIA have positive relationship with motor and parts dealers’
sales. However, previous one year’s GDP has negative relationship with motor and parts dealers’ sales. The food and
beverage stores sales and health and personal care stores sales are only self-related. Current year’s CPI has positive
30
35. Table 7.5: Information Criteria before/after restrictions for forecast model - SAS
Information Criteria - before restictions Information Criteria - after restrictions
AICC 1312.519 AICC 729.9106
HQC 1519.742 HQC 1658.671
AIC 1504.78 AIC 1653.911
SBC 1573.719 SBC 1675.846
FPEC 2.81E+29 FPEC 2.48E+34
Table 7.6: Forecast for year 2015 - SAS
Forecasts
Variable Obs Forecast Standard Error 95% Confidence Limits Actual Value
Y1t 24 1119316.0641 103437.70403 916581.88953 1322050.2386 1095412
Y2t 24 700295.37641 13187.76824 674447.82563 726142.92718 685568
Y3t 24 313664.51979 7857.41870 298264.26213 329064.77745 315257
Y4t 24 702687.10480 12922.14930 677360.15757 728014.05203 674928
Code in SAS:
PROC VARMAX DATA = df2; /*without restrictions*/
MODEL Y1t Y2t Y3t Y4t = GDP DJIA CPI/
P = 1 XLAG = 2 METHOD = LS;
OUTPUT LEAD = 1 OUT = out1;
RUN;
PROC VARMAX DATA = df2; /*with restrictions*/
MODEL Y1t Y2t Y3t Y4t = GDP DJIA CPI/
P = 1 XLAG = 2 METHOD = LS;
RESTRICT
CONST(1) = 0,XL(0,1,3) = 0,XL(1,1,2) = 0,
XL(1,1,3) = 0,XL(2,1,1) = 0,XL(2,1,2) = 0,
XL(2,1,3) = 0,AR(1,1,2) = 0,AR(1,1,3) = 0,
AR(1,1,4) = 0,CONST(2) = 0,XL(0,2,1) = 0,
XL(0,2,2) = 0,XL(1,2,1) = 0,XL(1,2,2) = 0,
XL(1,2,3) = 0,XL(2,2,1) = 0,XL(2,2,2) = 0,
XL(2,2,3) = 0,AR(1,2,1) = 0,CONST(3) = 0,
XL(0,3,1) = 0,XL(0,3,2) = 0,XL(0,3,3) = 0,
XL(1,3,1) = 0,XL(1,3,2) = 0,XL(1,3,3) = 0,
XL(2,3,1) = 0,XL(2,3,2) = 0,XL(2,3,3) = 0,
AR(1,3,1) = 0,AR(1,3,2) = 0,AR(1,3,4) = 0,
CONST(4) = 0,XL(0,4,2) = 0,XL(0,4,3) = 0,
XL(1,4,1) = 0,XL(1,4,2) = 0,XL(1,4,3) = 0,
XL(2,4,1) = 0,XL(2,4,2) = 0,XL(2,4,3) = 0,
AR(1,4,1) = 0,AR(1,4,3) = 0,XL(0,2,3) = 0
;
OUTPUT LEAD = 1 OUT = out1;
RUN;
35
36. 8 The reason that SAS/R estimations are different (experimental)
I spend few days trying to find out why SAS/R estimations for VARX(1,2) models are different. Even though I have
not figured out completely, there are still some interesting findings.
Comparing Equation 6.1 and Equation 6.2, we find that ratio between every element in Equation 6.1 and in Equation
6.2 is constant. For example 424276632/154282412 = 25554671/9292608 = 2.75.
On page 2965 of SAS/STAT 14.1 User’s Guide The VARMAX Procedure [1], the estimation formula for Σ is
Y = XB + E or y = (X ⊗ Ik)β + e (8.1)
where
Y = (y1, ..., yT )
′
B = (δ, Φ1, ..., Φp)
′
X = (X0, ..., XT−1)
′
Xt = (1, y
′
t, ..., y
′
t−p+1)
′
E = (ϵ1, ..., ϵT )
′
y = vec(Y
′
)
β = vec(B
′
)
e = vec(E
′
)
The conditional least square estimator of β is (not depend on ˆΣ, this should be the reason why estimated parameters
are same for VARX(1,2) without restrictions)
ˆβ = ((X
′
X)−1
X
′
⊗ Ik)y
and the estimate of Σ is
ˆΣ = (T − (kp + 1))−1
T∑
t=1
ˆϵt ˆϵ
′
t
However, according to page 46 of Multivariate Time Series Analysis with R and Financial Applications[2], which is
the textbook for MTS package, the estimate of Σ is
ˆΣ = (T − p − (kp + 1))−1
T∑
t=1
ˆϵt ˆϵ
′
t
However, I can’t find the formula for VARX models estimation. Since T = 24, k = 4, p = 1, the ratio should be very
small, not 2.75. Overall, this can only explain the difference between SAS/R output partially.
Using debug function in R, we show the key steps of parameter estimations step by step.The essential steps for
calculating covariance matrix of residual are shown blow.
1 nobe = dim(xmtx)[1]
2 xpx = t(xmtx) %*% xmtx
3 xpy = t(xmtx) %*% yt
4 xpxi = solve(xpx,tol = tol)
5 beta = xpxi %*% xpy
6 resi = as.matrix(yt - xmtx %*% beta)
7 sig = crossprod(resi, resi)/nobe
8 co = kronecker(sig, xpxi)
36
37. 9 se = sqrt(diag(co))
10 se.beta = matrix(se, nrow(beta), k)
11 npar = nrow(beta) * k
12 d1 = log(det(sig))
13 aic = d1 + 2 * npar/nobe
14 bic = d1 + (npar * log(nobe))/nobe
xmtx is the design matrix
xmtx =
1 y1,1993 y2,1993 y3,1993 y4,1993 GDP1994 CPI1994 DJIA1994 GDP1993 CPI1993 DJIA1993 GDP1992 CPI1992 DJIA1992
1 y1,1994 y2,1994 y3,1994 y4,1994 GDP1995 CPI1995 DJIA1995 GDP1994 CPI1994 DJIA1994 GDP1993 CPI1993 DJIA1993
...
...
...
...
...
...
...
...
...
...
...
...
...
...
1 y1,2014 y2,2014 y3,2014 y4,2014 GDP2015 CPI2015 DJIA2015 GDP2014 CPI2014 DJIA2014 GDP2013 CPI2013 DJIA2013
yt =
(
y1,t y2,t y3,t y4,t
)
22×4
nobe = the number of row of xmtx = 22
sig = crossprod(resi, resi)/nobe =
154282412 9292608 6163810.5 9217645.05
9292608 2863662 1379082.96 1401828.51
6163810 1379083 2856901.81 −15700.14
9217645 1401829 −15700.14 2481712.32
which is Equation 6.2
I think this is where Prof.Tsay made mistakes. The dominator should not be nobe, which is T = 22 in Equation 8.1.
Instead the dominator should be (T − p − (kp + 1 + ks)) = (22 − 1 − (4 × 1 + 1 + 4 × 2)) = 8. ks component is my guess.
I didn’t derive this formula even though I should.
Check my guess using R software.
Browse[2]> crossprod(resi, resi)/8
Y1t Y2t Y3t Y4t
Y1t 424276633 25554672 16950478.87 25348523.89
Y2t 25554672 7875070 3792478.13 3855028.40
Y3t 16950479 3792478 7856479.98 -43175.39
Y4t 25348524 3855028 -43175.39 6824708.87
which is equivalent to Equation 6.1.
This section only explain why there is difference between SAS/R (MTS package) estimated covariance matrix of resid-
uals for VARX(1,2) models without restrictions. Much more work need to done to explain the difference between
SAS/R estimated covariance matrix of residuals for VARX(1,2) models with restrictions.
References
[1] SAS/STAT 14.1 User’s Guide The VARMAX Procedure
[2] RUEY S. TSAY, Ph.D, Multivariate Time Series Analysis with R and Financial Applications
37