msVAR

Create Markov-switching dynamic regression model

Description

The msVAR function returns an msVAR object that specifies the functional form of a Markov-switching dynamic regression model for the univariate or multivariate response process yt. The msVAR object also stores the parameter values of the model.

An msVAR object has two key components: the switching mechanism among states, represented by a discrete-time Markov chain (dtmc object); and the state-specific submodels, either autoregressive (ARX) or vector autoregression (VARX) models (arima or varm objects), which can contain exogenous regression components. The components completely specify the model structure. The Markov chain transition matrix and submodel parameters, such as the AR coefficients and innovation-distribution variance, are unknown and estimable unless you specify their values.

To estimate a model containing unknown parameter values, pass the model and data to estimate. To work with an estimated or fully specified msVAR object, pass it to an object function.

Creation

Description

example

Mdl = msVAR(mc,mdl) creates a Markov-switching dynamic regression model that has the switching mechanism among states mc and the state-specific, stable dynamic regression submodels mdl.

Input Arguments

expand all

Discrete-time Markov chain for the switching mechanism among states, specified as a dtmc object.

The states represented in the rows and columns of the transition matrix mc.P correspond to the states represented in the submodel vector mdl.

msVAR processes and stores mc in the property Switch.

State-specific dynamic regression submodels, specified as a length mc.NumStates vector of model objects individually constructed by arima or varm. All submodels must be of the same type (arima or varm) and have the same number of series.

Unlike other model estimation tools, estimate does not infer the size of submodel regression coefficient arrays during estimation. Therefore, you must specify the Beta property of each submodel appropriately. For example, to include and estimate three predictors of the regression component of univariate submodel j, set mdl(j).Beta = NaN(3,1).

msVAR processes and stores mdl in the property Submodels.

Properties

expand all

This property is read-only.

Number of states, specified as a positive scalar.

Data Types: double

This property is read-only.

Number of time series, specified as a positive integer. NumSeries specifies the dimensionality of the response variable and innovation in all submodels.

Data Types: double

This property is read-only.

State labels, specified as a string vector of length NumStates.

Data Types: string

This property is read-only.

Discrete-time Markov chain for the switching mechanism among states, specified as a dtmc object.

This property is read-only.

State-specific vector autoregression submodels, specified as a vector of varm objects of length NumStates.

msVAR removes unsupported submodel components.

  • For arima submodels, msVAR does not support the moving average (MA), differencing, and seasonal components. If any submodel is a composite conditional mean and variance model (for example, its Variance property is a garch object), msVAR issues an error.

  • For varm submodels, msVAR does not support the trend component.

msVAR converts submodels specified as arima objects to 1-D varm objects.

Notes:

  • NaN-valued elements in either the properties of Switch or the submodels of Submodels indicate unknown, estimable parameters. Specified elements, except submodel innovation variances, indicate equality constraints on parameters in model estimation.

  • All unknown submodel parameters are state dependent.

Object Functions

estimateFit Markov-switching dynamic regression model to data
filterFiltered inference of operative latent states in Markov-switching dynamic regression data
forecastForecast sample paths from Markov-switching dynamic regression model
simulateSimulate sample paths of Markov-switching dynamic regression model
smoothSmoothed inference of operative latent states in Markov-switching dynamic regression data

Examples

collapse all

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 = 
  dtmc with properties:

             P: [2x2 double]
    StateNames: ["Expansion"    "Recession"]
     NumStates: 2

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')
mdl1 = 
  arima with properties:

     Description: "Expansion State"
    Distribution: Name = "Gaussian"
               P: 2
               D: 0
               Q: 0
        Constant: 5
              AR: {0.3 0.2} at lags [1 2]
             SAR: {}
              MA: {}
             SMA: {}
     Seasonality: 0
            Beta: [1×0]
        Variance: 2
 
   ARIMA(2,0,0) Model (Gaussian Distribution)
mdl2 = arima('Constant',C2,'AR',AR2,...
    'Variance',v2,'Description','Recession State')
mdl2 = 
  arima with properties:

     Description: "Recession State"
    Distribution: Name = "Gaussian"
               P: 1
               D: 0
               Q: 0
        Constant: -5
              AR: {0.1} at lag [1]
             SAR: {}
              MA: {}
             SMA: {}
     Seasonality: 0
            Beta: [1×0]
        Variance: 1
 
   ARIMA(1,0,0) Model (Gaussian Distribution)

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 = 
  msVAR with properties:

     NumStates: 2
     NumSeries: 1
    StateNames: ["Expansion"    "Recession"]
        Switch: [1x1 dtmc]
     Submodels: [2x1 varm]

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

     Description: "Expansion State"
     SeriesNames: "Y1" 
       NumSeries: 1
               P: 2
        Constant: 5
              AR: {0.3 0.2} at lags [1 2]
           Trend: 0
            Beta: [1×0 matrix]
      Covariance: 2
 
   AR-Stationary 1-Dimensional VAR(2) Model
Mdl.Submodels(2)
ans = 
  varm with properties:

     Description: "Recession State"
     SeriesNames: "Y1" 
       NumSeries: 1
               P: 1
        Constant: -5
              AR: {0.1} at lag [1]
           Trend: 0
            Beta: [1×0 matrix]
      Covariance: 1
 
   AR-Stationary 1-Dimensional VAR(1) Model

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).

Consider a two-state Markov-switching dynamic regression model of the postwar US real GDP growth rate. The model has the parameter estimates presented in [1].

Create a discrete-time Markov chain model that describes the regime switching mechanism. Label the regimes.

P = [0.92 0.08; 0.26 0.74];
mc = dtmc(P,'StateNames',["Expansion" "Recession"]);

mc is a fully specified dtmc object.

Create separate AR(0) models (constant only) for the two regimes.

sigma = 3.34; % Homoscedastic models across states
mdl1 = arima('Constant',4.62,'Variance',sigma^2);
mdl2 = arima('Constant',-0.48,'Variance',sigma^2);
mdl = [mdl1 mdl2];

Create the Markov-switching dynamic regression model that describes the behavior of the US GDP growth rate.

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

     NumStates: 2
     NumSeries: 1
    StateNames: ["Expansion"    "Recession"]
        Switch: [1x1 dtmc]
     Submodels: [2x1 varm]

Mdl is a fully specified msVAR object.

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 = 
  dtmc with properties:

             P: [2x2 double]
    StateNames: ["Expansion"    "Recession"]
     NumStates: 2

mc.P
ans = 2×2

   NaN   NaN
   NaN   NaN

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"
mdl1 = 
  arima with properties:

     Description: "Expansion State"
    Distribution: Name = "Gaussian"
               P: 1
               D: 0
               Q: 0
        Constant: NaN
              AR: {NaN} at lag [1]
             SAR: {}
              MA: {}
             SMA: {}
     Seasonality: 0
            Beta: [1×0]
        Variance: NaN
 
   ARIMA(1,0,0) Model (Gaussian Distribution)
mdl2 = arima(2,0,0);
mdl2.Description = "Recession State"
mdl2 = 
  arima with properties:

     Description: "Recession State"
    Distribution: Name = "Gaussian"
               P: 2
               D: 0
               Q: 0
        Constant: NaN
              AR: {NaN NaN} at lags [1 2]
             SAR: {}
              MA: {}
             SMA: {}
     Seasonality: 0
            Beta: [1×0]
        Variance: NaN
 
   ARIMA(2,0,0) Model (Gaussian Distribution)

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 = 
  msVAR with properties:

     NumStates: 2
     NumSeries: 1
    StateNames: ["Expansion"    "Recession"]
        Switch: [1x1 dtmc]
     Submodels: [2x1 varm]

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

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

     Description: "Expansion State"
     SeriesNames: "Y1" 
       NumSeries: 1
               P: 1
        Constant: NaN
              AR: {NaN} at lag [1]
           Trend: 0
            Beta: [1×0 matrix]
      Covariance: NaN
 
   1-Dimensional VAR(1) Model
Mdl.Submodels(2)
ans = 
  varm with properties:

     Description: "Recession State"
     SeriesNames: "Y1" 
       NumSeries: 1
               P: 2
        Constant: NaN
              AR: {NaN NaN} at lags [1 2]
           Trend: 0
            Beta: [1×0 matrix]
      Covariance: NaN
 
   1-Dimensional VAR(2) Model

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.

Create a three-state Markov-switching dynamic regression model for a 2-D response process. Specify all parameter values (this example uses arbitrary values).

Create a three-state discrete-time Markov chain model that describes the regime switching mechanism.

P = [10 1 1; 1 10 1; 1 1 10];
mc = dtmc(P);
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.

For each regime, use varm to create a VAR model that describes the response process within the regime. 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, mdl2, and 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];

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 = 
  msVAR with properties:

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

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]

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

Consider including regression components for exogenous variables in each submodel of the Markov-switching dynamic regression model in Create Fully Specified Multivariate Model.

Create a three-state discrete-time Markov chain model that describes the regime switching mechanism.

P = [10 1 1; 1 10 1; 1 1 10];
mc = dtmc(P);

For each regime, use varm to create a VARX model that describes the response process within the regime. 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];

% VARX 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, mdl2, and mdl3 are fully specified varm objects representing the state-specified submodels.

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

mdl = [mdl1; mdl2; mdl3];

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 = 
  msVAR with properties:

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

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]

Consider fitting to data a three-state Markov-switching model for a 2-D response process.

Create a discrete-time Markov chain model for the switching mechanism. Specify a 3-by-3 matrix of NaN values for the transition matrix. This setting indicates that you want to estimate all transition probabilities.

P = nan(3);
mc = dtmc(P);

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

Create 2-D VAR(0), VAR(1), and VAR(2) models by using the shorthand syntax of varm. Store the models in a vector.

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

mdl = [mdl1 mdl2 mdl3];
mdl(1)
ans = 
  varm with properties:

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

mdl contains three state-specific varm model templates for estimation. NaN values in the properties indicate estimable parameters.

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

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

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

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

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

     Description: "2-Dimensional VAR(1) Model"
     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×0 matrix]
      Covariance: [2×2 matrix of NaNs]
Mdl.Submodels(3)
ans = 
  varm with properties:

     Description: "2-Dimensional VAR(2) Model"
     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×0 matrix]
      Covariance: [2×2 matrix of NaNs]

Mdl is a partially specified msVAR model for estimation.

Consider including regression components for exogenous variables in the submodels of the Markov-switching dynamic regression model in Create Partially Specified Multivariate Model for Estimation. Assume that the VAR(0) model includes the regressor x1t, the VAR(1) model includes the regressors x1t and x2t, and the VAR(2) model includes the regressors x1t, x2t, and x3t.

Create the discrete-time Markov chain.

P = nan(3);
mc = dtmc(P);

Create 2-D VARX(0), VARX(1), and VARX(2) models by using the shorthand syntax of varm. For each model, set the Beta property to a numSeries-by-numRegressors matrix of NaN values by using dot notation. Store all models in a vector.

numSeries = 2;

mdl1 = varm(numSeries,0);
mdl1.Beta = NaN(numSeries,1);

mdl2 = varm(numSeries,1);
mdl2.Beta = NaN(numSeries,2);

mdl3 = varm(numSeries,2);
mdl3.Beta = nan(numSeries,3);

mdl = [mdl1; mdl2; mdl3];

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

Mdl = msVAR(mc,mdl); 
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]

Consider the model in Create Partially Specified Multivariate Model for Estimation. Suppose theory dictates that states do not persist.

Create a discrete-time Markov chain model for the switching mechanism. Specify a 3-by-3 matrix of NaN values for the transition matrix. Indicate that states do not persist by setting the diagonal elements of the matrix to 0.

P = nan(3);
P(logical(eye(3))) = 0;
mc = dtmc(P);

mc is a partially specified dtmc object.

Create the submodels and store them in a vector.

mdl1 = varm(2,0);
mdl2 = varm(2,1);
mdl3 = varm(2,2);
submdl = [mdl1; mdl2; mdl3];

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

Mdl = msVAR(mc,submdl);
Mdl.Switch.P
ans = 3×3

     0   NaN   NaN
   NaN     0   NaN
   NaN   NaN     0

estimate treats the known diagonal elements of the transition matrix as equality constraints during estimation. For more details, see estimate.

More About

expand all

References

[1] Chauvet, M., and J. D. Hamilton. "Dating Business Cycle Turning Points." In Nonlinear Analysis of Business Cycles (Contributions to Economic Analysis, Volume 276). (C. Milas, P. Rothman, and D. van Dijk, eds.). Amsterdam: Emerald Group Publishing Limited, 2006.

[2] Hamilton, J. D. "A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle." Econometrica. Vol. 57, 1989, pp. 357–384.

[3] Hamilton, J. D. "Analysis of Time Series Subject to Changes in Regime." Journal of Econometrics. Vol. 45, 1990, pp. 39–70.

[4] Hamilton, J. D. Time Series Analysis. Princeton, NJ: Princeton University Press, 1994.

[5] Krolzig, H.-M. Markov-Switching Vector Autoregressions. Berlin: Springer, 1997.

See Also

| |

Introduced in R2019b