%% Create Fully Specified Univariate Model
% Create a two-state Markov-switching dynamic regression model for a 1-D response process.  Specify all parameter values (this example uses arbitrary values).
%
% Create a two-state discrete-time Markov chain model that describes the regime switching mechanism. Label the regimes.

P = [0.9 0.1; 0.3 0.7];
mc = dtmc(P,'StateNames',["Expansion" "Recession"])

% mc is a dtmc object.
%
% For each regime, use arima to create an AR model that describes the response process within the regime.

% Constants
C1 = 5;
C2 = -5;

% AR coefficients
AR1 = [0.3 0.2]; % 2 lags
AR2 = 0.1;       % 1 lag

% Innovations variances
v1 = 2;
v2 = 1;

% AR Submodels
mdl1 = arima('Constant',C1,'AR',AR1,...
    'Variance',v1,'Description','Expansion State')
mdl2 = arima('Constant',C2,'AR',AR2,...
    'Variance',v2,'Description','Recession State')

% mdl1 and mdl2 are fully specified arima objects.
% Store the submodels in a vector with order corresponding to the regimes in mc.StateNames.

mdl = [mdl1; mdl2];

%
% Use msVAR to create a Markov-switching dynamic regression model from the switching mechanism mc and the state-specific submodels mdl.

Mdl = msVAR(mc,mdl)
Mdl.Submodels(1)
Mdl.Submodels(2)

% Mdl is a fully specified msVAR object representing a univariate two-state Markov-switching dynamic regression model. msVAR stores specified arima submodels as varm objects.
% Because Mdl is fully specified, you can pass it to any msVAR object function for further analysis (see Object Functions). Or, you can specify that the parameters of Mdl are initial values for the estimation procedure (see estimate).
% Copyright 2019 The MathWorks, Inc.