MATLAB Examples

Implicitly Create Diffuse State-Space Model Containing Regression Component

This example shows how to implicitly create a diffuse state-space model that contains a regression component in the observation equation. The state model contains an ARMA(1,1) state and random walk.

Write a function that specifies how the parameters in params map to the state-space model matrices, to the initial state values, and to the type of state. Specify the regression component by deflating the observations within the function. Symbolically, the model is:

\left[ {\begin{array}{*{20}{c}}
\end{array}} \right] = \left[ {\begin{array}{*{20}{c}}
{{\phi _1}}&{{\theta _1}}&0\\
\end{array}} \right]\left[ {\begin{array}{*{20}{c}}
{{x_{1,t - 1}}}\\
{{x_{2,t - 1}}}\\
x_{3,t - 1}
\end{array}} \right] + \left[ {\begin{array}{*{20}{c}}
{{\sigma _1}}& 0\\
1 & 0\\
0 & \sigma_3
\end{array}} \right]\left[ {\begin{array}{*{20}{c}}
\end{array}} \right]\\
{y_t} - \beta {z_t} = a_1{x_{1,t}} + a_2x_{3,t}  + {\sigma_2}{\varepsilon _t}.

% Copyright 2015 The MathWorks, Inc.

function [A,B,C,D,Mean0,Cov0,StateType,DeflateY] = diffuseRegressionParamMap(params,y,z)
% Diffuse state-space model with a regression component parameter mapping
% function example. This function maps the vector params to the state-space
% matrices (A, B, C, and D) and indicates the type of states (StateType).
% The state model contains an ARMA(1,1) model and a random walk.
    varu1 = exp(params(3)); % Positive variance constraint
    vare1 = exp(params(5));
    A = [params(1) params(2); 0 0];
    B = [sqrt(varu1) 0; 1 0]; 
    C = [varu1 0];
    D = sqrt(vare1);
    Mean0 = []; % Let software infer Mean0
    Cov0 = [];  % Let software infer Cov0
    StateType = [0 0 2];
    DeflateY = y - params(6)*z;

Save this code as a file named diffuseRegressionParamMap.m to a folder on your MATLAB® path.

Create the diffuse state-space model by passing diffuseRegressionParamMap as a function handle to dssm.

Mdl = dssm(@(params)diffuseRegressionParamMap(params,y,z));

dssm implicitly creates the diffuse state-space model. Usually, you cannot verify implicitly defined state-space models.

Before creating the model, ensure that the variables y and z exist in your workspace.