%% Return Estimation Summary Table
% Create a discrete threshold transition at mid-level 1.

ttDGP = threshold(1)

% Create the following fully specified self-exciting TAR (SETAR) model for the DGP.
% State 1: y_t =\varepsilon_t.
% State 2: y_t =2+\varepsilon_t \ldotp
% \varepsilon_t \sim N\left(0,1\right).
% Specify the submodels by using arima.

mdl1DGP = arima(Constant=0);
mdl2DGP = arima(Constant=2);
mdlDGP = [mdl1DGP mdl2DGP];

% Create a threshold-switching model for the DGP. Specify the model-wide innovations variance.

MdlDGP = tsVAR(ttDGP,mdlDGP,Covariance=1);

% Generate a random response path of length 100 from the DGP. By default, simulate assumes a SETAR model with delay d=1, in other words, the threshold variable is yt-1.

rng(1) % For reproducibiliy
y = simulate(MdlDGP,100);

% Create a partially specified threshold-switching model that has the same structure as the data-generating process, but specify the transition mid-level, submodel coefficients, and model-wide constant as unknown for estimation.

tt = threshold(NaN);
mdl1 = arima('Constant',NaN);
mdl2 = arima('Constant',NaN);
Mdl = tsVAR(tt,[mdl1,mdl2],'Covariance',NaN);

% Fully specify a threshold transition that has the same structure as tt, but set the mid-level to 0.

tt0 = threshold(0);

% Fit the model to the simulated path. By default, the model is self exciting and the delay of the threshold variable is d=1.

EstMdl = estimate(Mdl,tt0,y);

% Return an estimation summary table.

results = summarize(EstMdl)

% results is a table containing estimates and inferences for all submodel coefficients.
% Identify significant coefficient estimates.

results.Properties.RowNames(results.PValue < 0.05)

% Copyright 2021 The MathWorks, Inc.