Main Content

Create Multivariate Markov-Switching Dynamic Regression Models

These examples show how to create fully and partially specified, multivariate Markov-switching dynamic regression models by using the msVAR function. For an overview, see Creating Markov-Switching Dynamic Regression Models.

If you plan to fit a model to data, you must create a partially and fully specified model. The partially specified model contains unknown parameter values to be estimated, and the fully specified model contains parameter values that the estimate function uses to initiate the expectation-maximization algorithm.

If you do not plan to fit a model to data by using estimate, you must create a fully specified model for all other msVAR object functions.

Create Fully Specified Multivariate Model

This example shows how to create a fully specified, three-state Markov-switching dynamic regression model.

Consider the response processes y1t and y2t that switch between three states, governed by the latent process st with this observed transition matrix:

P=[101111011110].

That is, a researcher observed state 1 persist for 10 time steps, state 1 transition to state 2 once, state 1 transition to state 3 once, and so on.

Suppose that yt=[y1ty2t] is a VAR model in each state:

yt={[1-1]+ε1t;st=1[2-2]+[0.50.10.50.5]yt-1+ε2t;st=2[3-3]+[0.25000]yt-1+[000.250]yt-2+ε3t;st=3,

where, for j = 1,2,3, εjt is Gaussian with mean 0 and covariance matrix

Σj=j[1-0.1-0.11].

Describe Switching Mechanism

Create a three-state discrete-time Markov chain model that describes the regime switching mechanism by passing P to mc.

P = [10 1 1; 1 10 1; 1 1 10];
mc = dtmc(P)
mc = 
  dtmc with properties:

             P: [3x3 double]
    StateNames: ["1"    "2"    "3"]
     NumStates: 3

mc.P
ans = 3×3

    0.8333    0.0833    0.0833
    0.0833    0.8333    0.0833
    0.0833    0.0833    0.8333

mc is a dtmc object. dtmc normalizes P so that each row sums to 1 (each row is a valid conditional distribution).

Describe State-Specific Dynamic Regression Submodels

For each regime, create a VAR model for yt by using varm. Specify all parameter values.

% Constants (numSeries x 1 vectors)
C1 = [1;-1];
C2 = [2;-2];
C3 = [3;-3];

% Autoregression coefficients (numSeries x numSeries matrices)
AR1 = {};                            % 0 lags
AR2 = {[0.5 0.1; 0.5 0.5]};          % 1 lag
AR3 = {[0.25 0; 0 0] [0 0; 0.25 0]}; % 2 lags

% Innovations covariances (numSeries x numSeries matrices)
Sigma1 = [1 -0.1; -0.1 1];
Sigma2 = [2 -0.2; -0.2 2];
Sigma3 = [3 -0.3; -0.3 3];

% VAR Submodels
mdl1 = varm(Constant=C1,AR=AR1,Covariance=Sigma1);
mdl2 = varm(Constant=C2,AR=AR2,Covariance=Sigma2);
mdl3 = varm(Constant=C3,AR=AR3,Covariance=Sigma3);

mdl1 through mdl3 are fully specified varm objects.

Store the submodels in a vector with their order corresponding to the regimes in mc.StateNames.

mdl = [mdl1; mdl2; mdl3];

Create Markov-Switching Dynamic Regression Model

Create the Markov-switching dynamic regression model that describes the dynamic behavior of st and yt.

Mdl = msVAR(mc,mdl)
Mdl = 
  msVAR with properties:

      NumStates: 3
      NumSeries: 2
     StateNames: ["1"    "2"    "3"]
    SeriesNames: ["1"    "2"]
         Switch: [1x1 dtmc]
      Submodels: [3x1 varm]

Mdl is a fully specified msVAR object representing a multivariate, three-state Markov-switching dynamic regression model.

The state-specific submodels are fully specified 2-D VAR models, each varying by parameter values.

Mdl.Submodels(1)
ans = 
  varm with properties:

     Description: "2-Dimensional VAR(0) Model"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 0
        Constant: [1 -1]'
              AR: {}
           Trend: [2×1 vector of zeros]
            Beta: [2×0 matrix]
      Covariance: [2×2 matrix]
Mdl.Submodels(2)
ans = 
  varm with properties:

     Description: "AR-Stationary 2-Dimensional VAR(1) Model"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 1
        Constant: [2 -2]'
              AR: {2×2 matrix} at lag [1]
           Trend: [2×1 vector of zeros]
            Beta: [2×0 matrix]
      Covariance: [2×2 matrix]
Mdl.Submodels(3)
ans = 
  varm with properties:

     Description: "AR-Stationary 2-Dimensional VAR(2) Model"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 2
        Constant: [3 -3]'
              AR: {2×2 matrices} at lags [1 2]
           Trend: [2×1 vector of zeros]
            Beta: [2×0 matrix]
      Covariance: [2×2 matrix]

Create Fully Specified Multivariate Model Containing Regression Components

This example shows how to include an unknown regression component in each submodel of the Markov-switching dynamic regression model in Create Fully Specified Multivariate Model.

Consider adjusting the response variables with the exogenous variables x1t, x2t, and x3t by including a regression component in each submodel as follows:

yt={[1-1]+[1-1]x1t+ε1t;st=1[2-2]+[0.50.10.50.5]yt-1+[22-2-2][x1tx2t]+ε2t;st=2[3-3]+[0.25000]yt-1+[000.250]yt-2+[333-3-3-3][x1tx2tx3t]+ε3t;st=3.

Describe Switching Mechanism

Create a three-state discrete-time Markov chain model that describes the regime switching mechanism by passing P to mc.

P = [10 1 1; 1 10 1; 1 1 10];
mc = dtmc(P)
mc = 
  dtmc with properties:

             P: [3x3 double]
    StateNames: ["1"    "2"    "3"]
     NumStates: 3

mc.P
ans = 3×3

    0.8333    0.0833    0.0833
    0.0833    0.8333    0.0833
    0.0833    0.0833    0.8333

mc is a dtmc object.

Describe State-Specific Dynamic Regression Submodels

For each regime, create a VAR model for yt by using varm. Specify all parameter values.

% Constants (numSeries x 1 vectors)
C1 = [1;-1];
C2 = [2;-2];
C3 = [3;-3];
    
% Autoregression coefficients (numSeries x numSeries matrices)
AR1 = {};                            % 0 lags
AR2 = {[0.5 0.1; 0.5 0.5]};          % 1 lag
AR3 = {[0.25 0; 0 0] [0 0; 0.25 0]}; % 2 lags
    
% Regression coefficients (numSeries x numRegressors matrices)
Beta1 = [1;-1];           % 1 regressor
Beta2 = [2 2;-2 -2];      % 2 regressors
Beta3 = [3 3 3;-3 -3 -3]; % 3 regressors
    
% Innovations covariances (numSeries x numSeries matrices)
Sigma1 = [1 -0.1; -0.1 1];
Sigma2 = [2 -0.2; -0.2 2];
Sigma3 = [3 -0.3; -0.3 3];
    
% VAR Submodels
mdl1 = varm(Constant=C1,AR=AR1,Beta=Beta1,Covariance=Sigma1);
mdl2 = varm(Constant=C2,AR=AR2,Beta=Beta2,Covariance=Sigma2);
mdl3 = varm(Constant=C3,AR=AR3,Beta=Beta3,Covariance=Sigma3);

mdl1 through mdl3 are fully specified varm objects.

Store the submodels in a vector with order corresponding to the regimes in mc.StateNames.

mdl = [mdl1; mdl2; mdl3];

Create Markov-Switching Dynamic Regression Model

Create the Markov-switching dynamic regression model that describes the dynamic behavior of st and yt.

Mdl = msVAR(mc,mdl)
Mdl = 
  msVAR with properties:

      NumStates: 3
      NumSeries: 2
     StateNames: ["1"    "2"    "3"]
    SeriesNames: ["1"    "2"]
         Switch: [1x1 dtmc]
      Submodels: [3x1 varm]

Mdl is a fully specified msVAR object representing a multivariate, three-state Markov-switching dynamic regression model.

The state-specific submodels are fully specified 2-D VAR models, each varying by AR order and regression coefficient size.

Mdl.Submodels(1)
ans = 
  varm with properties:

     Description: "2-Dimensional VARX(0) Model with 1 Predictor"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 0
        Constant: [1 -1]'
              AR: {}
           Trend: [2×1 vector of zeros]
            Beta: [2×1 matrix]
      Covariance: [2×2 matrix]
Mdl.Submodels(2)
ans = 
  varm with properties:

     Description: "AR-Stationary 2-Dimensional VARX(1) Model with 2 Predictors"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 1
        Constant: [2 -2]'
              AR: {2×2 matrix} at lag [1]
           Trend: [2×1 vector of zeros]
            Beta: [2×2 matrix]
      Covariance: [2×2 matrix]
Mdl.Submodels(3)
ans = 
  varm with properties:

     Description: "AR-Stationary 2-Dimensional VARX(2) Model with 3 Predictors"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 2
        Constant: [3 -3]'
              AR: {2×2 matrices} at lags [1 2]
           Trend: [2×1 vector of zeros]
            Beta: [2×3 matrix]
      Covariance: [2×2 matrix]

Create Partially Specified Multivariate Model Containing Regression Components for Estimation

This example shows how to create a partially specified, three-state Markov-switching dynamic regression model to be fit to data.

Consider the 2-D response process yt=[y1ty2t] that switches between three states, governed by the latent process st with an unknown transition matrix. Suppose x1t, x2t, and x3t are exogenous variables of interest.

Suppose that during:

  • State 1, yt is a VAR(0) model containing a regression component for x1t

  • State 2, yt is a VAR(1) model containing a regression component for x1t and x2t

  • State 3, yt is a VAR(2) model containing a regression component for x1t, x2t, and x3t

Describe Switching Mechanism

A discrete-time Markov chain represents the switching mechanism, and a right stochastic matrix describes the chain. Because the transition probabilities are unknown, create a matrix of NaNs, and pass it to dtmc to create the chain. Label the states.

P = NaN(3);
mc = dtmc(P);
mc.P
ans = 3×3

   NaN   NaN   NaN
   NaN   NaN   NaN
   NaN   NaN   NaN

mc is a partially specified dtmc object. The transition matrix mc.P is completely unknown and estimable.

Describe State-Specific Dynamic Regression Submodels

The shorthand syntax of varm is well suited for the quick creation of VAR model templates for estimation. That is, given the response series dimensionality and VAR model order, all other parameters in the model are unknown and estimable.

For each regime, create a VAR model template by specifying the response series dimensionality and AR polynomial order.

numSeries = 2;
mdl1 = varm(numSeries,0);
mdl2 = varm(numSeries,1);
mdl3 = varm(numSeries,2);

mdl1, mdl2, and mdl3 are partially specified varm objects. By default, the Beta property is empty, which means the models do not contain a regression component. To include regression components for estimation, for each model, set Beta to a numSeries-by-numRegressors matrix of NaN values by using dot notation.

mdl1.Beta = NaN(numSeries,1);
mdl2.Beta = NaN(numSeries,2);
mdl3.Beta = NaN(numSeries,3);

Store the submodels in a vector with their order corresponding to the regimes in mc.StateNames.

mdl = [mdl2; mdl2; mdl3];

Create Markov-Switching Dynamic Regression Model

Create the Markov-switching dynamic regression model that describes the dynamic behavior of st and yt.

Mdl = msVAR(mc,mdl)
Mdl = 
  msVAR with properties:

      NumStates: 3
      NumSeries: 2
     StateNames: ["1"    "2"    "3"]
    SeriesNames: ["1"    "2"]
         Switch: [1x1 dtmc]
      Submodels: [3x1 varm]

Mdl is a partially specified msVAR object representing a multivariate, three-state Markov-switching dynamic regression model. To estimate the unknown parameter values of Mdl, pass Mdl, response and predictor data, and a fully specified Markov-switching model (which has the same structure as Mdl, but contains initial values for estimation) to estimate.

The state-specific submodels are partially specified 2-D VAR models, each varying by AR order and regression coefficient size.

Mdl.Submodels(1)
ans = 
  varm with properties:

     Description: "2-Dimensional VARX(1) Model with 2 Predictors"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 1
        Constant: [2×1 vector of NaNs]
              AR: {2×2 matrix of NaNs} at lag [1]
           Trend: [2×1 vector of zeros]
            Beta: [2×2 matrix of NaNs]
      Covariance: [2×2 matrix of NaNs]
Mdl.Submodels(2)
ans = 
  varm with properties:

     Description: "2-Dimensional VARX(1) Model with 2 Predictors"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 1
        Constant: [2×1 vector of NaNs]
              AR: {2×2 matrix of NaNs} at lag [1]
           Trend: [2×1 vector of zeros]
            Beta: [2×2 matrix of NaNs]
      Covariance: [2×2 matrix of NaNs]
Mdl.Submodels(3)
ans = 
  varm with properties:

     Description: "2-Dimensional VARX(2) Model with 3 Predictors"
     SeriesNames: "Y1"  "Y2" 
       NumSeries: 2
               P: 2
        Constant: [2×1 vector of NaNs]
              AR: {2×2 matrices of NaNs} at lags [1 2]
           Trend: [2×1 vector of zeros]
            Beta: [2×3 matrix of NaNs]
      Covariance: [2×2 matrix of NaNs]

See Also

Objects

Related Topics