Why does gctest fail when using discontinuous lags?

16 次查看(过去 30 天)
I'm running a Granger-causality test on a varm model object. The gctest function returns an indexing error when the lags are discontinuous. For example it works when lags = 1,2,3,4. It fails when lags = 1,2,4. Below code recreates the error.
%Following Matlab gctest example
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);
T = size(tbl,1); % Total sample size
numseries = 3;
% Partition time base.
maxp = 4; % Maximum number of required presample responses
idxpre = 1:maxp;
idxest = (maxp + 1):T;
% Fit VAR models to data.
Y0 = tbl{idxpre,:}; % Presample
Y = tbl{idxest,:}; % Estimation sample
%Two different models. Second model omits lag number 3
lags1=[1:4];
lags2=[1,2,4];
coef0=nan(numseries,numseries);
numlags1=length(lags1);
numlags2=length(lags2);
for i=1:length(lags1)
coef_1{i}=coef0;
end
for i=1:length(lags2)
coef_2{i}=coef0;
end
Mdl_1 = varm('AR',coef_1,'Lags',lags1);
EstMdl_1 = estimate(Mdl_1,Y,'Y0',Y0);
gctest(EstMdl_1)
Mdl_2 = varm('AR',coef_2,'Lags',lags2);
EstMdl_2 = estimate(Mdl_2,Y,'Y0',Y0);
gctest(EstMdl_2) %gctest fails for the second model

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Autoregression Models 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by