%% Explicitly Create Diffuse State-Space Model Containing Known and Unknown Parameters
% Create a diffuse state-space model containing two independent states,  x_{1,t} and x_{3,t}, and an observation, y_t, that is the deterministic sum of the two states at time t. x_1 is an AR(1) model with a constant and x_3 is a random walk. Symbolically, the state-space model is
% \left[
% {\begin{array}{*{20}{c}}x_{1,t}\\x_{2,t}\\x_{3,t}\end{array}}
% \right] = \left[ {\begin{array}{*{20}{c}}{{\phi
% _1}}&c_1&0\\0&1&0\\0&0&1\end{array}} \right]\left[
% \begin{array}{*{20}{c}}x_{t - 1,1}\\x_{t - 1,2}\\x_{t - 1,3}\end{array}
% \right] + \left[ {\begin{array}{*{20}{c}}{\sigma_1} & 0\\0 & 0\\ 0&
% \sigma_2\end{array}} \right]\left[
% {\begin{array}{*{20}{c}}{{u_{t,1}}}\\{{u_{t,3}}}\end{array}} \right]
% {y_t} = \left[ {\begin{array}{*{20}{c}}1&0&1\end{array}}
% \right]\left[
% {\begin{array}{*{20}{c}}{{x_{t,1}}}\\{{x_{t,2}}}\\{{x_{t,3}}}\end{array}}
% \right].
% The state disturbances, u_{1,t} and u_{3,t}, are standard Gaussian random variables.
% Specify the state-transition matrix.

A = [NaN NaN 0; 0 1 0; 0 0 1];

% The NaN values indicate unknown parameters.
%
% Specify the state-disturbance-loading matrix.

B = [NaN 0; 0 0; 0 NaN];

%
% Specify the measurement-sensitivity matrix.

C = [1 0 1];

%
% Create a vector that specifies the state types. In this example:
% x_{1,t} is a stationary AR(1) model, so its state type is 0.
% x_{2,t} is a placeholder for the constant in the AR(1) model. Because the constant is unknown and is expressed in the first equation, x_{2,t} is 1 for the entire series. Therefore, its state type is 1.
% x_{3,t} is a nonstationary, random walk with drift, so its state type is 2.

StateType = [0 1 2];

%
% Create the state-space model using dssm.

Mdl = dssm(A,B,C,'StateType',StateType)

% Mdl is a dssm model object containing unknown parameters. A detailed summary of Mdl prints to the Command Window. If you do not specify the initial state covariance matrix, then the initial variance of x_{3,t} is Inf.
% It is good practice to verify that the state and observation equations are correct. If the equations are not correct, then expand the state-space equation and verify it manually.
% Copyright 2015 The MathWorks, Inc.