%% Modify msVAR Model Specifications
% Properties of an msVAR object are read only.  Therefore, to adjust the specification of a created model, create a new model. This example shows how to specify known parameter values of a created, partially specified model.
%
% Suppose that y_t is a univariate response process representing an economic measurement that can suggest which state the economy experiences during a period (expansion or recession). During an expansion, y_t is this AR(2) model, and, during a recession, y_t is an AR(1) model. State-specific submodel coefficients and innovations variance are unknown.
% Create a partially specified, univariate, two-state Markov-switching model (for more details, see docid:econ_ug.mw_48d09bd7-279d-4681-82ba-87b6f1016bc3).

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

% AR Submodels
mdl1 = arima(1,0,0);
mdl1.Description = "Expansion State";
mdl2 = arima(2,0,0);
mdl2.Description = "Recession State";
mdl = [mdl1; mdl2];

% Markov-switching model
Mdl = msVAR(mc,mdl);

%
% Suppose economic theory suggests:
% An expansion persists into the next time step with probability 0.9.
% During an expansion, the model constant is 5.
% During a recession, the model constant is -5.
% Create a new msVAR model based on economic theory by:
% Creating a new dtmc object containing a transition matrix with the known transition probability
% Adjusting the Constant property of mdl1 and mdl2 by using doc notation
% Passing the new dtmc object and vector of adjusted arima objects to msVAR

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

mdl1.Constant = 5;
mdl2.Constant = -5;
mdl = [mdl1; mdl2];

MdlAdj = msVAR(mc,mdl);
MdlAdj.Switch.P
MdlAdj.Submodels(1)
MdlAdj.Submodels(2)

% Mdl is a partially specified msVAR model. During estimation, estimate treats the model constants and known transition probability as equality constraints.
% Copyright 2019 The MathWorks, Inc.