%% Create Partially Specified Univariate Model for Estimation
% Consider fitting to data a two-state Markov-switching model for a 1-D response process.
% Create a discrete-time Markov chain model for the switching mechanism. Specify a 2-by-2 matrix of NaN values for the transition matrix. This setting indicates that you want to estimate all transition probabilities. Label the states.

P = NaN(2);
mc = dtmc(P,'StateNames',["Expansion" "Recession"])
mc.P

% mc is a partially specified dtmc object. The transition matrix mc.P is completely unknown and estimable.
% Create AR(1) and AR(2) models by using the shorthand syntax of arima. After you create each model, specify the model description  by using dot notation.

mdl1 = arima(1,0,0);
mdl1.Description = "Expansion State"
mdl2 = arima(2,0,0);
mdl2.Description = "Recession State"

% mdl1 and mdl2 are partially specified arima objects. NaN-valued properties correspond to unknown, estimable parameters.
% Store the submodels in a vector with order corresponding to the regimes in mc.StateNames.

mdl = [mdl1; mdl2];

% Create a Markov-switching model template from the switching mechanism mc and the state-specific submodels mdl.

Mdl = msVAR(mc,mdl)

% Mdl is a partially specified msVAR object representing a univariate two-state Markov-switching dynamic regression model.

Mdl.Submodels(1)
Mdl.Submodels(2)

% msVAR converts the arima object submodels to 1-D varm object equivalents.
% Mdl is prepared for estimation. You can pass Mdl, along with data and a fully specified model containing initial values for optimization,  to estimate.
% Copyright 2019 The MathWorks, Inc.