Formally a VAR model is
$$Y_t = A_1 Y_{t-1} + \ldots + A_p Y_{t-p} + u_t$$$$u_t \sim {\sf Normal}(0, \Sigma_u)$$where $Y_t$ is of dimension $K$ and $A_i$ is a $K \times K$ coefficient matrix.
dta = sm.datasets.macrodata.load_pandas().data
endog = dta[["infl", "unemp", "tbilrate"]]
index = sm.tsa.datetools.dates_from_range('1959Q1', '2009Q3')
dta.index = pandas.Index(index)
del dta['year']
del dta['quarter']
endog.index = pandas.Index(index) # DatetimeIndex or PeriodIndex in 0.8.0
print endog.head(10)
infl unemp tbilrate 1959-03-31 0.00 5.8 2.82 1959-06-30 2.34 5.1 3.08 1959-09-30 2.74 5.3 3.82 1959-12-31 0.27 5.6 4.33 1960-03-31 2.31 5.2 3.50 1960-06-30 0.14 5.2 2.68 1960-09-30 2.70 5.6 2.36 1960-12-31 1.21 6.3 2.29 1961-03-31 -0.40 6.8 2.37 1961-06-30 1.47 7.0 2.29
endog.plot(subplots=True, figsize=(14,18));
/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:1210: UserWarning: findfont: Font family ['monospace'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))
# model only after Volcker appointment
var_mod = sm.tsa.VAR(endog.ix['1979-12-31':]).fit(maxlags=4, ic=None)
print var_mod.summary()
Summary of Regression Results ================================== Model: VAR Method: OLS Date: Tue, 17, Jul, 2012 Time: 12:29:31 -------------------------------------------------------------------- No. of Equations: 3.00000 BIC: -1.38214 Nobs: 116.000 HQIC: -1.93210 Log likelihood: -320.932 FPE: 0.0997509 AIC: -2.30792 Det(Omega_mle): 0.0725307 -------------------------------------------------------------------- Results for equation infl ============================================================================== coefficient std. error t-stat prob ------------------------------------------------------------------------------ const 1.861765 0.975933 1.908 0.059 L1.infl 0.043747 0.099137 0.441 0.660 L1.unemp -1.772916 1.068556 -1.659 0.100 L1.tbilrate 1.068492 0.308544 3.463 0.001 L2.infl -0.047131 0.094792 -0.497 0.620 L2.unemp 3.350585 1.947357 1.721 0.088 L2.tbilrate -0.801488 0.364698 -2.198 0.030 L3.infl 0.130702 0.096459 1.355 0.178 L3.unemp 0.483236 1.915270 0.252 0.801 L3.tbilrate 0.767990 0.323361 2.375 0.019 L4.infl -0.118506 0.105590 -1.122 0.264 L4.unemp -2.109414 1.046155 -2.016 0.046 L4.tbilrate -0.709641 0.246646 -2.877 0.005 ============================================================================== Results for equation unemp ============================================================================== coefficient std. error t-stat prob ------------------------------------------------------------------------------ const 0.196149 0.091636 2.141 0.035 L1.infl -0.006733 0.009309 -0.723 0.471 L1.unemp 1.543511 0.100333 15.384 0.000 L1.tbilrate -0.101861 0.028971 -3.516 0.001 L2.infl 0.004712 0.008901 0.529 0.598 L2.unemp -0.434913 0.182848 -2.379 0.019 L2.tbilrate 0.154581 0.034244 4.514 0.000 L3.infl 0.009677 0.009057 1.068 0.288 L3.unemp -0.239875 0.179835 -1.334 0.185 L3.tbilrate -0.092268 0.030362 -3.039 0.003 L4.infl 0.026235 0.009914 2.646 0.009 L4.unemp 0.082838 0.098229 0.843 0.401 L4.tbilrate 0.035650 0.023159 1.539 0.127 ============================================================================== Results for equation tbilrate ============================================================================== coefficient std. error t-stat prob ------------------------------------------------------------------------------ const -0.210139 0.313916 -0.669 0.505 L1.infl -0.034879 0.031888 -1.094 0.277 L1.unemp -0.679575 0.343709 -1.977 0.051 L1.tbilrate 1.151534 0.099246 11.603 0.000 L2.infl 0.043524 0.030491 1.427 0.156 L2.unemp 0.601872 0.626382 0.961 0.339 L2.tbilrate -0.448569 0.117308 -3.824 0.000 L3.infl 0.023667 0.031027 0.763 0.447 L3.unemp 0.748752 0.616061 1.215 0.227 L3.tbilrate 0.558119 0.104012 5.366 0.000 L4.infl 0.041376 0.033964 1.218 0.226 L4.unemp -0.586963 0.336504 -1.744 0.084 L4.tbilrate -0.373850 0.079336 -4.712 0.000 ============================================================================== Correlation matrix of residuals infl unemp tbilrate infl 1.000000 -0.150786 0.258308 unemp -0.150786 1.000000 -0.389991 tbilrate 0.258308 -0.389991 1.000000
np.abs(var_mod.roots)
array([ 2.7821, 2.7821, 1.5472, 1.5472, 1.3908, 1.3908, 1.3806, 1.3806, 1.1395, 1.1395, 1.104 , 1.104 ])
var_mod.test_causality('unemp', 'tbilrate', kind='Wald')
Granger causality Wald-test ======================================================= Test statistic Critical Value p-value df ------------------------------------------------------- 22.700855 9.487729 0.000 4 ======================================================= H_0: ['tbilrate'] do not Granger-cause unemp Conclusion: reject H_0 at 5.00% significance level
{'conclusion': 'reject', 'crit_value': 9.487729036781154, 'df': 4, 'pvalue': 0.00014529611487641404, 'signif': 0.05, 'statistic': 22.700854791605487}
table = pandas.DataFrame(np.zeros((9,3)), columns=['chi2', 'df', 'prob(>chi2)'])
index = []
variables = set(endog.columns.tolist())
i = 0
for vari in variables:
others = []
for j,ex_vari in enumerate(variables):
if vari == ex_vari: # don't want to test this
continue
others.append(ex_vari)
res = var_mod.test_causality(vari, ex_vari, kind='Wald', verbose=False)
table.ix[[i], ['chi2', 'df', 'prob(>chi2)']] = (res['statistic'], res['df'], res['pvalue'])
i += 1
index.append([vari, ex_vari])
res = var_mod.test_causality(vari, others, kind='Wald', verbose=False)
table.ix[[i], ['chi2', 'df', 'prob(>chi2)']] = res['statistic'], res['df'], res['pvalue']
index.append([vari, 'ALL'])
i += 1
table.index = pandas.MultiIndex.from_tuples(index, names=['Equation', 'Excluded'])
print table
chi2 df prob(>chi2) Equation Excluded unemp infl 10.866 4 0.028 tbilrate 22.701 4 0.000 ALL 35.853 8 0.000 infl unemp 10.497 4 0.033 tbilrate 21.629 4 0.000 ALL 29.597 8 0.000 tbilrate unemp 12.447 4 0.014 infl 6.119 4 0.190 ALL 16.362 8 0.037
From this we reject the null that these variables do not Granger cause for all cases except for infl -> tbilrate. In other words, in almost all cases we can reject the null hypothesis that the lags of the excluded variable are jointly zero in Equation.
var_mod.model.select_order()
VAR Order Selection ====================================================== aic bic fpe hqic ------------------------------------------------------ 0 3.821 3.895 45.63 3.851 1 -2.693 -2.393 0.06769 -2.571 2 -3.424* -2.900* 0.03259* -3.212* 3 -3.335 -2.586 0.03567 -3.031 4 -3.404 -2.429 0.03338 -3.009 5 -3.289 -2.090 0.03754 -2.803 6 -3.239 -1.815 0.03967 -2.661 7 -3.199 -1.550 0.04156 -2.530 8 -3.213 -1.340 0.04131 -2.454 9 -3.255 -1.156 0.04006 -2.404 10 -3.278 -0.9547 0.03969 -2.336 11 -3.206 -0.6580 0.04339 -2.173 12 -3.144 -0.3716 0.04711 -2.020 13 -3.065 -0.06718 0.05231 -1.850 ====================================================== * Minimum
{'aic': 2, 'bic': 2, 'fpe': 2, 'hqic': 2}
irf = var_mod.irf(24)
irf.plot(orth=True, signif=.33, subplot_params = {'fontsize' : 18})
var_mod.fevd(24).summary()
FEVD for infl infl unemp tbilrate 0 1.000000 0.000000 0.000000 1 0.852378 0.068321 0.079300 2 0.821960 0.072742 0.105298 3 0.800366 0.071008 0.128626 4 0.782810 0.069296 0.147895 5 0.778382 0.073392 0.148226 6 0.774765 0.077698 0.147538 7 0.773304 0.078759 0.147937 8 0.772711 0.079996 0.147293 9 0.771720 0.081095 0.147185 10 0.770519 0.081963 0.147518 11 0.769590 0.082942 0.147467 12 0.768802 0.083723 0.147474 13 0.768341 0.084163 0.147496 14 0.768186 0.084338 0.147476 15 0.768135 0.084354 0.147511 16 0.768094 0.084314 0.147592 17 0.768034 0.084282 0.147684 18 0.767934 0.084280 0.147786 19 0.767816 0.084301 0.147883 20 0.767702 0.084342 0.147955 21 0.767601 0.084394 0.148005 22 0.767518 0.084444 0.148038 23 0.767455 0.084490 0.148056 FEVD for unemp infl unemp tbilrate 0 0.022736 0.977264 0.000000 1 0.044880 0.930399 0.024721 2 0.041784 0.930260 0.027956 3 0.037486 0.930276 0.032238 4 0.027721 0.931560 0.040719 5 0.022468 0.934437 0.043095 6 0.021990 0.936267 0.041743 7 0.025581 0.935272 0.039147 8 0.031058 0.931753 0.037189 9 0.037851 0.924482 0.037667 10 0.045527 0.913280 0.041193 11 0.053402 0.898884 0.047714 12 0.061321 0.882177 0.056503 13 0.068823 0.864635 0.066542 14 0.075418 0.847729 0.076853 15 0.080988 0.832408 0.086604 16 0.085516 0.819282 0.095202 17 0.089098 0.808583 0.102320 18 0.091923 0.800184 0.107893 19 0.094151 0.793811 0.112038 20 0.095907 0.789125 0.114968 21 0.097291 0.785765 0.116944 22 0.098382 0.783403 0.118215 23 0.099239 0.781764 0.118996 FEVD for tbilrate infl unemp tbilrate 0 0.066723 0.126097 0.807180 1 0.046150 0.198100 0.755749 2 0.056621 0.251998 0.691381 3 0.081954 0.248844 0.669202 4 0.099227 0.238387 0.662386 5 0.108544 0.228719 0.662736 6 0.113163 0.212939 0.673899 7 0.117658 0.199234 0.683108 8 0.120920 0.193892 0.685188 9 0.122879 0.197398 0.679723 10 0.124824 0.208597 0.666578 11 0.126204 0.224548 0.649248 12 0.126978 0.242303 0.630718 13 0.127918 0.259257 0.612825 14 0.129091 0.273537 0.597373 15 0.130529 0.284485 0.584986 16 0.132460 0.292021 0.575519 17 0.134787 0.296476 0.568738 18 0.137301 0.298526 0.564173 19 0.139874 0.298875 0.561251 20 0.142334 0.298162 0.559504 21 0.144535 0.296922 0.558544 22 0.146418 0.295511 0.558070 23 0.147973 0.294149 0.557878
var_mod.fevd(24).plot(figsize=(12,12))
Experiment with different VAR models. You can try to adjust the number of lags in the VAR model calculated above or the ordering of the variables and see how it affects the model.
You might also try adding variables to the VAR, say M1 measure of money supply, or estimating a different model using measures of consumption (realcons), government spending (realgovt), or GDP (realgdp).