%% Conduct Exclude-All Granger Causality Test
% Consider the 3-D VAR(3) model and leave-one-out Granger causality test in docid:econ_ug#mw_ef939d73-b815-439a-a3d4-b7000807a69a.
% Load the US macroeconomic data set Data_USEconModel.mat.  Preprocess the data. Fit a VAR(3) model to the preprocessed data.

load Data_USEconModel

m1slrate = price2ret(DataTable.M1SL);
inflation = price2ret(DataTable.CPIAUCSL);
rgdprate = price2ret(DataTable.GDP./DataTable.GDPDEF);

tbl = table(m1slrate,inflation,rgdprate);
tbl = rmmissing(tbl);

Mdl = varm(3,3);
Mdl.SeriesNames = tbl.Properties.VariableNames;
EstMdl = estimate(Mdl,tbl{5:end,:},'Y0',tbl{2:4,:});

%
% Conduct an exclude-all Granger causality test on the variables of the fitted model.

h = gctest(EstMdl,'Type',"exclude-all");

% gctest conducts numtests = 3 tests. The results indicate the following decisions, each at a 5% level of significance:
% Do not reject the claim that the inflation and real GDP rates do not Granger-cause the M1 money supply rate.
% Reject the claim that the M1 money supply and real GDP rates do not Granger-cause the inflation rate.
% Reject the claim that the M1 money supply and inflation rates do not Granger-cause the real GDP rate.
% Copyright 2018 The MathWorks, Inc.