%% Access Test p-Values
% 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 a leave-one-out Granger causality test on the variables of the fitted model. Return the test result summary table and suppress the test results display.

[~,Summary] = gctest(EstMdl,'Display',false)

% Summary is a MATLAB table containing numtests = 6 rows.  The rows contain the results of each test. The columns are table variables containing characteristics of the tests.
% Extract the p-values of the tests.

pvalues = Summary.PValue

% Copyright 2018 The MathWorks, Inc.