dssm class
Superclasses:
Create diffuse state-space model
Description
dssm
creates a lineardiffuse state-space modelwith independent Gaussian state disturbances and observation innovations. A diffuse state-space model contains diffuse states, and variances of the initial distributions of diffuse states areInf
。All diffuse states are independent of each other and all other states. The software implements the diffuse Kalman filter for filtering, smoothing, and parameter estimation.
You can:
Specify atime-invariantortime-varyingmodel.
Specify whether states are stationary,static, or nonstationary.
Specify the state-transition, state-disturbance-loading, measurement-sensitivity, or observation-innovation matrices:
Explicitly by providing the matrices
Implicitly by providing a function that maps the parameters to the matrices, that is, a parameter-to-matrix mapping function
After creating a diffuse state-space model containing unknown parameters, you can estimate its parameters by passing the createddssm
model object and data toestimate
。Theestimate
function builds the likelihood function using the diffuse Kalman filter.
Use a completely specified model (that is, all parameter values of the model are known) to:
Construction
creates adiffuse state-space model(Mdl
= dssm(A
,B
,C
)Mdl
) using state-transition matrixA
, state-disturbance-loading matrixB
, and measurement-sensitivity matrixC
。
creates a diffuse state-space model using state-transition matrixMdl
= dssm(A
,B
,C
,D
)A
, state-disturbance-loading matrixB
, measurement-sensitivity matrixC
, and observation-innovation matrixD
。
uses any of the input arguments in the previous syntaxes and additional options that you specify by one or moreMdl
= dssm(___,Name,Value
)Name,Value
pair arguments.
creates a diffuse state-space model using a parameter-to-matrix mapping function (Mdl
= dssm(ParamMap
)ParamMap
) that you write. The function maps a vector of parameters to the matricesA
,B
, andC
。Optionally,ParamMap
can map parameters toD
,Mean0
,Cov0
。To specify the types of states, the function can returnStateType
。To accommodate a regression component in the observation equation,ParamMap
can also return deflated observation data.
converts a state-space model object (Mdl
= dssm(SSMMdl
)SSMMdl
) to a diffuse state-space model object (Mdl
).dssm
sets all initial variances of diffuse states inSSMMdl.Cov0
toInf
。
输入参数
A
—State-transition coefficient matrix
matrix|cell vector of matrices
State-transition coefficient matrix for explicit state-space model creation, specified as a matrix or cell vector of matrices.
The state-transition coefficient matrix,At, specifies how the states,xt, are expected to transition from periodt– 1 tot, for allt= 1,...,T。That is, the expected state-transition equation at periodtisE(xt|xt–1) =Atxt–1。
For time-invariant state-space models, specifyA
as anm-by-mmatrix, wheremis the number of states per period.
For time-varying state-space models, specifyA
as aT-dimensional cell array, whereA{t}
contains anmt-by-mt– 1state-transition coefficient matrix. If the number of states changes from periodt– 1 tot, thenmt≠mt– 1。
NaN
values in any coefficient matrix indicate unique, unknown parameters in the state-space model.A
contributes:
sum(isnan(A(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inA
at each period.numParamsA
unknown parameters to time-varying state-space models, wherenumParamsA = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),A,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inA
。
You cannot specifyA
andParamMap
simultaneously.
Data Types:double
|cell
B
—State-disturbance-loading coefficient matrix
matrix|cell vector of matrices
State-disturbance-loading coefficient matrix for explicit state-space model creation, specified as a matrix or cell vector of matrices.
The state disturbances,ut, are independent Gaussian random variables with mean 0 and standard deviation 1. The state-disturbance-loading coefficient matrix,Bt, specifies the additive error structure in the state-transition equation from periodt– 1 tot, for allt= 1,...,T。That is, the state-transition equation at periodtisxt=Atxt–1+Btut。
For time-invariant state-space models, specifyB
as anm-by-kmatrix, wheremis the number of states andkis the number of state disturbances per period.B*B'
is the state-disturbance covariance matrix for all periods.
For time-varying state-space models, specifyB
as aT-dimensional cell array, whereB{t}
contains anmt-by-ktstate-disturbance-loading coefficient matrix. If the number of states or state disturbances changes at periodt, then the matrix dimensions betweenB{t-1}
andB{t}
vary.B{t}*B{t}'
is the state-disturbance covariance matrix for periodt
。
NaN
values in any coefficient matrix indicate unique, unknown parameters in the state-space model.B
contributes:
sum(isnan(B(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inB
at each period.numParamsB
unknown parameters to time-varying state-space models, wherenumParamsB = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),B,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inB
。
You cannot specifyB
andParamMap
simultaneously.
Data Types:double
|cell
C
—Measurement-sensitivity coefficient matrix
matrix|cell vector of matrices
Measurement-sensitivity coefficient matrix for explicit state-space model creation, specified as a matrix or cell vector of matrices.
The measurement-sensitivity coefficient matrix,Ct, specifies how the states are expected to linearly combine at periodt形成了观察,yt, for allt= 1,...,T。That is, the expected observation equation at periodtisE(yt|xt) =Ctxt。
For time-invariant state-space models, specifyC
as ann-by-mmatrix, wherenis the number of observations andmis the number of states per period.
For time-varying state-space models, specifyC
as aT-dimensional cell array, whereC{t}
contains annt-by-mtmeasurement-sensitivity coefficient matrix. If the number of states or observations changes at periodt, then the matrix dimensions betweenC{t-1}
andC{t}
vary.
NaN
values in any coefficient matrix indicate unique, unknown parameters in the state-space model.C
contributes:
sum(isnan(C(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inC
at each period.numParamsC
unknown parameters to time-varying state-space models, wherenumParamsC = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),C,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inC
。
You cannot specifyC
andParamMap
simultaneously.
Data Types:double
|cell
D
—Observation-innovation coefficient matrix
[]
(default) |matrix|cell vector of matrices
Observation-innovation coefficient matrix for explicit state-space model creation, specified as a matrix or cell vector of matrices.
The observation innovations,εt, are independent Gaussian random variables with mean 0 and standard deviation 1. The observation-innovation coefficient matrix,Dt, specifies the additive error structure in the observation equation at periodt, for allt= 1,...,T。That is, the observation equation at periodtisyt=Ctxt+Dtεt。
For time-invariant state-space models, specifyD
as ann-by-hmatrix, wherenis the number of observations andhis the number of observation innovations per period.D*D'
is the observation-innovation covariance matrix for all periods.
For time-varying state-space models, specifyD
as aT-dimensional cell array, whereD{t}
contains annt-by-htmatrix. If the number of observations or observation innovations changes at periodt, then the matrix dimensions betweenD{t-1}
andD{t}
vary.D{t}*D{t}'
is the observation-innovation covariance matrix for periodt
。
NaN
values in any coefficient matrix indicate unique, unknown parameters in the state-space model.D
contributes:
sum(isnan(D(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inD
at each period.numParamsD
unknown parameters to time-varying state-space models, wherenumParamsD = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),D,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inD
。
By default,D
is an empty matrix indicating no observation innovations in the state-space model.
You cannot specifyD
andParamMap
simultaneously.
Data Types:double
|cell
ParamMap
—Parameter-to-matrix mapping function
empty array ([]
)(default) |function handle
Parameter-to-matrix mapping function for implicit state-space model creation, specified as a function handle.
ParamMap
must be a function that takes at least one input argument and returns at least three output arguments. The requisite input argument is a vector of unknown parameters, and the requisite output arguments correspond to the coefficient matricesA
,B
, andC
, respectively. If your parameter-to-mapping function requires the input parameter vector argument only, then implicitly create a diffuse state-space model by entering the following:
Mdl = dssm(@ParamMap)
In general, you can write an intermediate function, for example,ParamFun
, using this syntax:
function [A,B,C,D,Mean0,Cov0,StateType,DeflateY] = ... ParamFun(params,...otherInputArgs...)
In this general case, create the diffuse state-space model by entering
Mdl = dssm(@(params)ParamMap(params,...otherInputArgs...))
However:
Follow the order of the output arguments.
params
is a vector, and each element corresponds to an unknown parameter.ParamFun
must returnA
,B
, andC
, which correspond to the state-transition, state-disturbance-loading, and measurement-sensitivity coefficient matrices, respectively.If you specify more input arguments than the parameter vector (
params
), such as observed responses and predictors, then implicitly create the diffuse state-space model using the syntax patternMdl = dssm(@(params)ParamFun(params,y,z))
For the optional output arguments
D
,Mean0
,Cov0
,StateType
, andDeflateY
:The optional output arguments correspond to the observation-innovation coefficient matrix
D
and the name-value pair argumentsMean0
,Cov0
, andStateType
。To skip specifying an optional output argument, set the argument to
[]
in the function body. For example, to skip specifyingD
, then setD = [];
in the function.DeflateY
is the deflated-observation data, which accommodates a regression component in the observation equation. For example, in this function, which has a linear regression component,Y
is the vector of observed responses andZ
is the vector of predictor data.function [A,B,C,D,Mean0,Cov0,StateType,DeflateY] = ParamFun(params,Y,Z) ... DeflateY = Y - params(9) - params(10)*Z; ... end
For the default values of
Mean0
,Cov0
, andStateType
, seeAlgorithms。
It is best practice to:
Load the data to the MATLAB®Workspace before specifying the model.
Create the parameter-to-matrix mapping function as its own file.
If you specifyParamMap
, then you cannot specify any name-value pair arguments or any other input arguments.
Data Types:function_handle
SSMMdl
—State-space model
ssm
model object
State-space model to convert to a diffuse state-space model, specified as anssm
model object.
dssm
sets all initial variances of diffuse states inSSMMdl.Cov0
toInf
。
To use the diffuse Kalman filter for filtering, smoothing, and parameter estimation instead of the standard Kalman filter, convert a state-space model to a diffuse state-space model.
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, whereName
is the argument name andValue
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Mean0
—Initial state mean
numeric vector
Initial state mean for explicit state-space model creation, specified as the comma-separated pair consisting of'Mean0'
and a numeric vector with length equal to the number of initial states. For the default values, seeAlgorithms。
If you specifyParamMap
, then you cannot specifyMean0
。Instead, specify the initial state mean in the parameter-to-matrix mapping function.
Data Types:double
Cov0
—Initial state covariance matrix
square matrix
Initial state covariance matrix for explicit state-space model creation, specified as the comma-separated pair consisting of'Cov0'
and a square matrix with dimensions equal to the number of initial states. For the default values, seeAlgorithms。
If you specifyParamMap
, then you cannot specifyCov0
。Instead, specify the initial state covariance in the parameter-to-matrix mapping function.
Data Types:double
StateType
—Initial state distribution indicator
0|1|2
Initial state distribution indicator for explicit state-space model creation, specified as the comma-separated pair consisting of'StateType'
and a numeric vector with length equal to the number of initial states. This table summarizes the available types of initial state distributions.
Value | Initial State Distribution Type |
---|---|
0 |
Stationary (for example, ARMA models) |
1 |
The constant 1 (that is, the state is 1 with probability 1) |
2 |
Diffuse or nonstationary (for example, random walk model, seasonal linear time series) orstatic state |
例如,假设状态方程two state variables: The first state variable is an AR(1) process, and the second state variable is a random walk. Specify the initial distribution types by setting'StateType',[0; 2]
。
If you specifyParamMap
, then you cannot specifyMean0
。Instead, specify the initial state distribution indicator in the parameter-to-matrix mapping function.
For the default values, seeAlgorithms。
Data Types:double
Properties
A
—State-transition coefficient matrix
matrix|cell vector of matrices|empty array ([]
)
State-transition coefficient matrix for explicitly created state-space models, specified as a matrix, a cell vector of matrices, or an empty array ([]
). For implicitly created state-space models and before estimation,A
is[]
and read only.
The state-transition coefficient matrix,At, specifies how the states,xt, are expected to transition from periodt– 1 tot, for allt= 1,...,T。That is, the expected state-transition equation at periodtisE(xt|xt–1) =Atxt–1。
For time-invariant state-space models,A
is anm-by-mmatrix, wheremis the number of states per period.
For time-varying state-space models,A
is aT-dimensional cell array, whereA{t}
contains anmt-by-mt– 1state-transition coefficient matrix. If the number of states changes from periodt– 1 tot, thenmt≠mt– 1。
NaN
values in any coefficient matrix indicate unknown parameters in the state-space model.A
contributes:
sum(isnan(A(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inA
at each period.numParamsA
unknown parameters to time-varying state-space models, wherenumParamsA = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),A,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inA
。
Data Types:double
|cell
B
—State-disturbance-loading coefficient matrix
matrix|cell vector of matrices|empty array ([]
)
State-disturbance-loading coefficient matrix for explicitly created state-space models, specified as a matrix, a cell vector of matrices, or an empty array ([]
). For implicitly created state-space models and before estimation,B
is[]
and read only.
The state disturbances,ut, are independent Gaussian random variables with mean 0 and standard deviation 1. The state-disturbance-loading coefficient matrix,Bt, specifies the additive error structure in the state-transition equation from periodt– 1 tot, for allt= 1,...,T。That is, the state-transition equation at periodtisxt=Atxt–1+Btut。
For time-invariant state-space models,B
is anm-by-kmatrix, wheremis the number of states andkis the number of state disturbances per period.B*B'
is the state-disturbance covariance matrix for all periods.
For time-varying state-space models,B
is aT-dimensional cell array, whereB{t}
contains anmt-by-ktstate-disturbance-loading coefficient matrix. If the number of states or state disturbances changes at periodt, then the matrix dimensions betweenB{t-1}
andB{t}
vary.B{t}*B{t}'
is the state-disturbance covariance matrix for periodt
。
NaN
values in any coefficient matrix indicate unknown parameters in the state-space model.B
contributes:
sum(isnan(B(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inB
at each period.numParamsB
unknown parameters to time-varying state-space models, wherenumParamsB = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),B,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inB
。
Data Types:double
|cell
C
—Measurement-sensitivity coefficient matrix
matrix|cell vector of matrices|empty array ([]
)
Measurement-sensitivity coefficient matrix for explicitly created state-space models, specified as a matrix, a cell vector of matrices, or an empty array ([]
). For implicitly created state-space models and before estimation,C
is[]
and read only.
The measurement-sensitivity coefficient matrix,Ct, specifies how the states are expected to combine linearly at periodt形成了观察,yt, for allt= 1,...,T。That is, the expected observation equation at periodtisE(yt|xt) =Ctxt。
For time-invariant state-space models,C
is ann-by-mmatrix, wherenis the number of observations andmis the number of states per period.
For time-varying state-space models,C
is aT-dimensional cell array, whereC{t}
contains annt-by-mtmeasurement-sensitivity coefficient matrix. If the number of states or observations changes at periodt, then the matrix dimensions betweenC{t-1}
andC{t}
vary.
NaN
values in any coefficient matrix indicate unknown parameters in the state-space model.C
contributes:
sum(isnan(C(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inC
at each period.numParamsC
unknown parameters to time-varying state-space models, wherenumParamsC = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),C,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inC
。
Data Types:double
|cell
D
—Observation-innovation coefficient matrix
matrix|cell vector of matrices|empty array ([]
)
Observation-innovation coefficient matrix for explicitly created state-space models, specified as a matrix, a cell vector of matrices, or an empty array ([]
). For implicitly created state-space models and before estimation,D
is[]
and read only.
The observation innovations,εt, are independent Gaussian random variables with mean 0 and standard deviation 1. The observation-innovation coefficient matrix,Dt, specifies the additive error structure in the observation equation at periodt, for allt= 1,...,T。That is, the observation equation at periodtisyt=Ctxt+Dtεt。
For time-invariant state-space models,D
is ann-by-hmatrix, wherenis the number of observations andhis the number of observation innovations per period.D*D'
is the observation-innovation covariance matrix for all periods.
For time-varying state-space models,D
is aT-dimensional cell array, whereD{t}
contains annt-by-htmatrix. If the number of observations or observation innovations changes at periodt, then the matrix dimensions betweenD{t-1}
andD{t}
vary.D{t}*D{t}'
is the state-disturbance covariance matrix for periodt
。
NaN
values in any coefficient matrix indicate unknown parameters in the state-space model.D
contributes:
sum(isnan(D(:)))
unknown parameters to time-invariant state-space models. In other words, if the state-space model is time invariant, then the software uses the same unknown parameters defined inD
at each period.numParamsD
unknown parameters to time-varying state-space models, wherenumParamsD = sum(cell2mat(cellfun(@(x)sum(sum(isnan(x))),D,'UniformOutput',0)))
。In other words, if the state-space model is time varying, then the software assigns a new set of parameters for each matrix inD
。
Data Types:double
|cell
Mean0
—Initial state mean
numeric vector|empty array ([]
)
Initial state mean, specified as a numeric vector or an empty array ([]
).Mean0
has length equal to the number of initial states (size(A,1)
orsize(A{1},1)
).
Mean0
is the mean of the Gaussian distribution of the states at period 0.
For implicitly created state-space models and before estimation,Mean0
is[]
and read only. However,estimate
specifiesMean0
after estimation.
Data Types:double
Cov0
—Initial state covariance matrix
square matrix|empty array ([]
)
Initial state covariance matrix, specified as a square matrix or an empty array ([]
).Cov0
has dimensions equal to the number of initial states (size(A,1)
orsize(A{1},1)
).
Cov0
is the covariance of the Gaussian distribution of the states at period 0.
For implicitly created state-space models and before estimation,Cov0
is[]
and read only. However,estimate
specifiesCov0
after estimation.
Diagonal elements ofCov0
that have valueInf
correspond to diffuse initial state distributions. This specification indicates complete ignorance or no prior knowledge of the initial state value. Subsequently, the software filters, smooths, and estimates parameters in the presence of diffuse initial state distributions using the diffuse Kalman filter. To use the standard Kalman filter for diffuse states instead, set each diagonal element ofCov0
to a large, positive value, for example,1e7
。This specification suggests relatively weak knowledge of the initial state value.
Data Types:double
StateType
—Initial state distribution type
numeric vector|empty array ([]
)
Initial state distribution indicator, specified as a numeric vector or empty array ([]
).StateType
has length equal to the number of initial states.
For implicitly created state-space models or models with unknown parameters,StateType
is[]
and read only.
This table summarizes the available types of initial state distributions.
Value | Initial State Distribution Type |
---|---|
0 |
Stationary (e.g., ARMA models) |
1 |
The constant 1 (that is, the state is 1 with probability 1) |
2 |
Nonstationary (e.g., random walk model, seasonal linear time series) orstatic state。 |
例如,假设状态方程two state variables: The first state variable is an AR(1) process, and the second state variable is a random walk. Then,StateType
is[0; 2]
。
For nonstationary states,dssm
setsCov0
toInf
by default. Subsequently, the software assumes that diffuse states are uncorrelated and implements the diffuse Kalman filter for filtering, smoothing, and parameter estimation. This specification imposes no prior knowledge on the initial state values of diffuse states.
Data Types:double
ParamMap
—Parameter-to-matrix mapping function
function handle|empty array ([]
)
Parameter-to-matrix mapping function, specified as a function handle or an empty array ([]
).ParamMap
completely specifies the structure of the state-space model. That is,ParamMap
definesA
,B
,C
,D
, and, optionally,Mean0
,Cov0
, andStateType
。For explicitly created state-space models,ParamMap
is[]
and read only.
Data Types:function_handle
Object Functions
Fit Model to Data
估计状态变量
Impulse Response Function
Generate Minimum Mean Square Error Forecasts
forecast |
Forecast states and observations of diffuse state-space models |
Copy Semantics
Value. To learn how value classes affect copy operations, seeCopying Objects。
Examples
Explicitly Create Diffuse State-Space Model Containing Known and Unknown Parameters
创建一个包含两个状态空间模型independent states, and , and an observation, , that is the deterministic sum of the two states at time 。 is an AR(1) model with a constant and is a random walk. Symbolically, the state-space model is
The state disturbances, and , are standard Gaussian random variables.
Specify the state-transition matrix.
A = [NaN NaN 0; 0 1 0; 0 0 1];
TheNaN
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:
is a stationary AR(1) model, so its state type is
0
。is a placeholder for the constant in the AR(1) model. Because the constant is unknown and is expressed in the first equation, is
1
for the entire series. Therefore, its state type is1
。is a nonstationary, random walk with drift, so its state type is
2
。
StateType = [0 1 2];
Create the state-space model usingdssm
。
Mdl = dssm(A,B,C,'StateType',StateType)
类型:状态空间模型Mdl = dssm状态向量ngth: 3 Observation vector length: 1 State disturbance vector length: 2 Observation innovation vector length: 0 Sample size supported by model: Unlimited Unknown parameters for estimation: 4 State variables: x1, x2,... State disturbances: u1, u2,... Observation series: y1, y2,... Observation innovations: e1, e2,... Unknown parameters: c1, c2,... State equations: x1(t) = (c1)x1(t-1) + (c2)x2(t-1) + (c3)u1(t) x2(t) = x2(t-1) x3(t) = x3(t-1) + (c4)u2(t) Observation equation: y1(t) = x1(t) + x3(t) Initial state distribution: Initial state means are not specified. Initial state covariance matrix is not specified. State types x1 x2 x3 Stationary Constant Diffuse
Mdl
is adssm
model object containing unknown parameters. A detailed summary ofMdl
prints to the Command Window. If you do not specify the initial state covariance matrix, then the initial variance of
isInf
。
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.
Explicitly Create Diffuse State-Space Model Containing Observation Error
创建一个包含两个状态空间模型random walk states. The observations are the sum of the two states, plus Gaussian error. Symbolically, the equation is
Define the state-transition matrix.
A = [1 0; 0 1];
Define the state-disturbance-loading matrix.
B = [NaN 0; 0 NaN];
Define the measurement-sensitivity matrix.
C = [1 1];
Define the observation-innovation matrix.
D = NaN;
Create a vector that specifies that both states are nonstationary.
StateType = [2; 2];
Create the state-space model usingdssm
。
Mdl = dssm(A,B,C,D,'StateType',StateType)
类型:状态空间模型Mdl = dssm状态向量ngth: 2 Observation vector length: 1 State disturbance vector length: 2 Observation innovation vector length: 1 Sample size supported by model: Unlimited Unknown parameters for estimation: 3 State variables: x1, x2,... State disturbances: u1, u2,... Observation series: y1, y2,... Observation innovations: e1, e2,... Unknown parameters: c1, c2,... State equations: x1(t) = x1(t-1) + (c1)u1(t) x2(t) = x2(t-1) + (c2)u2(t) Observation equation: y1(t) = x1(t) + x2(t) + (c3)e1(t) Initial state distribution: Initial state means are not specified. Initial state covariance matrix is not specified. State types x1 x2 Diffuse Diffuse
Mdl
is andssm
model containing unknown parameters. A detailed summary ofMdl
prints to the Command Window.
Pass the data andMdl
toestimate
to estimate the parameters. During estimation, the initial state variances areInf
, andestimate
implements the diffuse Kalman filter.
Create Known Diffuse State-Space Model with Initial State Values
Create a diffuse state-space model, where:
The state is a stationary AR(2) model with , , and a constant 0.5. The state disturbance is a mean zero Gaussian random variable with standard deviation 0.3.
The state is a random walk. The state disturbance is a mean zero Gaussian random variable with standard deviation 0.05.
The observation is the difference between the current and previous value in the AR(2) state, plus a mean 0 Gaussian observation innovation with standard deviation 0.1.
The observation is the random walk state plus a mean 0 Gaussian observation innovation with standard deviation 0.02.
Symbolically, the state-space model is
The model has four states: is the AR(2) process, represents , is the AR(2) model constant, and is the random walk.
Define the state-transition matrix.
A = [0.6 0.2 0.5 0; 1 0 0 0; 0 0 1 0; 0 0 0 1];
Define the state-disturbance-loading matrix.
B = [0.3 0; 0 0; 0 0; 0 0.05];
Define the measurement-sensitivity matrix.
C = [1 -1 0 0; 0 0 0 1];
Define the observation-innovation matrix.
D = [0.1; 0.02];
Usedssm
to create the state-space model. Identify the type of initial state distributions (StateType
) by noting the following:
is a stationary AR(2) process.
is also a stationary AR(2) process.
is the constant 1 for all periods.
is nonstationary.
Set the initial state means (Mean0
) to 0. The initial state mean for constant states must be 1.
Mean0 = [0; 0; 1; 0]; StateType = [0; 0; 1; 2]; Mdl = dssm(A,B,C,D,'Mean0',Mean0,'StateType',StateType)
类型:状态空间模型Mdl = dssm状态向量ngth: 4 Observation vector length: 2 State disturbance vector length: 2 Observation innovation vector length: 1 Sample size supported by model: Unlimited State variables: x1, x2,... State disturbances: u1, u2,... Observation series: y1, y2,... Observation innovations: e1, e2,... State equations: x1(t) = (0.60)x1(t-1) + (0.20)x2(t-1) + (0.50)x3(t-1) + (0.30)u1(t) x2(t) = x1(t-1) x3(t) = x3(t-1) x4(t) = x4(t-1) + (0.05)u2(t) Observation equations: y1(t) = x1(t) - x2(t) + (0.10)e1(t) y2(t) = x4(t) + (0.02)e1(t) Initial state distribution: Initial state means x1 x2 x3 x4 0 0 1 0 Initial state covariance matrix x1 x2 x3 x4 x1 0.21 0.16 0 0 x2 0.16 0.21 0 0 x3 0 0 0 0 x4 0 0 0 Inf State types x1 x2 x3 x4 Stationary Stationary Constant Diffuse
Mdl
is adssm
model object.dssm
sets the initial state:
Covariance matrix for the stationary states to the asymptotic covariance of the AR(2) model
Variance for constant states to
0
Variance for diffuse states to
Inf
You can display or modify properties ofMdl
using dot notation. For example, display the initial state covariance matrix.
Mdl.Cov0
ans =4×40.2143 0.1607 0 0 0.1607 0.2143 0 0 0 0 0 0 0 0 0 Inf
Reset the initial state means for the stationary states to their asymptotic values.
Mdl.Mean0(1:2) = 0.5/(1-0.2-0.6); Mdl.Mean0
ans =4×12.5000 2.5000 1.0000 0
Implicitly Create Time-Invariant State-Space Model
Use a parameter mapping function to create a time-invariant state-space model, where the state model is AR(1) model. The states are observed with bias, but without random error. Set the initial state mean and variance, and specify that the state is stationary.
Write a function that specifies how the parameters inparams
map to the state-space model matrices, the initial state values, and the type of state. Symbolically, the model is
% Copyright 2015 The MathWorks, Inc.function[A,B,C,D,Mean0,Cov0,StateType] = timeInvariantParamMap(params)% Time-invariant state-space model parameter mapping function example. This% function maps the vector params to the state-space matrices (A, B, C, and% D), the initial state value and the initial state variance (Mean0 and% Cov0), and the type of state (StateType). The state model is AR(1)% without observation error.varu1 = exp(params(2));% Positive variance constraintA = params(1); B = sqrt(varu1); C = params(3); D = []; Mean0 = 0.5; Cov0 = 100; StateType = 0;end
Save this code as a file namedtimeInvariantParamMap.m
to a folder on your MATLAB® path.
Create the state-space model by passing the functiontimeInvariantParamMap
as a function handle tossm
。
Mdl = ssm(@timeInvariantParamMap);
ssm
implicitly creates the state-space model. Usually, you cannot verify implicitly defined state-space models.
Convert Standard to Diffuse State-Space Model
By default,ssm
assigns a large scalar (1e7
) to the initial state variance of all diffuse states in a standard state-space model. Using this specification, the software subsequently estimates, filters, and smooths a standard state-space model using the standard Kalman filter. A standard state-space model treatment is an approximation to results from an analysis that treats diffuse states using infinite variance. To implement the diffuse Kalman filter instead, convert the standard state-space model to a diffuse state-space model. This conversion attributes infinite variance to all diffuse states.
Explicitly create a two-dimensional standard state-space model. Specify that the first state equation is and that the second state equation is 。Specify that the first observation equation is and that the second observation equation is 。Specify that the states are diffuse and nonstationary, respectively.
A = [1 0; 0 0.2]; B = [1 0; 0 1]; C = [1 0;0 1]; D = [1 0; 0 1]; StateType = [2 0]; MdlSSM = ssm(A,B,C,D,'StateType',StateType)
MdlSSM = State-space model type: ssm State vector length: 2 Observation vector length: 2 State disturbance vector length: 2 Observation innovation vector length: 2 Sample size supported by model: Unlimited State variables: x1, x2,... State disturbances: u1, u2,... Observation series: y1, y2,... Observation innovations: e1, e2,... State equations: x1(t) = x1(t-1) + u1(t) x2(t) = (0.20)x2(t-1) + u2(t) Observation equations: y1(t) = x1(t) + e1(t) y2(t) = x2(t) + e2(t) Initial state distribution: Initial state means x1 x2 0 0 Initial state covariance matrix x1 x2 x1 1.00e+07 0 x2 0 1.04 State types x1 x2 Diffuse Stationary
MdlSSM
is anssm
model object. In some cases,ssm
can detect the state type, but it is good practice to specify whether the state is stationary, diffuse, or the constant1
。Because the model does not contain any unknown parameters,ssm
infers the initial state distributions.
ConvertMdlSSM
to a diffuse state-space model.
Mdl = dssm(MdlSSM)
类型:状态空间模型Mdl = dssm状态向量ngth: 2 Observation vector length: 2 State disturbance vector length: 2 Observation innovation vector length: 2 Sample size supported by model: Unlimited State variables: x1, x2,... State disturbances: u1, u2,... Observation series: y1, y2,... Observation innovations: e1, e2,... State equations: x1(t) = x1(t-1) + u1(t) x2(t) = (0.20)x2(t-1) + u2(t) Observation equations: y1(t) = x1(t) + e1(t) y2(t) = x2(t) + e2(t) Initial state distribution: Initial state means x1 x2 0 0 Initial state covariance matrix x1 x2 x1 Inf 0 x2 0 1.04 State types x1 x2 Diffuse Stationary
Mdl
is adssm
model object. The structures ofMdl
andMdlSSM
are equivalent, except that the initial state variance of the state inMdl
isInf
rather than1e7
。
To see the difference between the two models, simulate 10 periods of data from a state-space model that is similar toMdlSSM
。Set the initial state covariance matrix to
。
Mdl0 = MdlSSM; Mdl0.Cov0 = eye(2); T = 10; rng(1);% For reproducibilityy = simulate(Mdl0,T);
Obtain filtered and smoothed states fromMdl
andMdlSSM
using the simulated data.
fY = filter(MdlSSM,y); fYD = filter(Mdl,y); sY = smooth(MdlSSM,y); sYD = smooth(Mdl,y);
Plot the filtered and smoothed states.
figure; subplot(2,1,1) plot(1:T,y(:,1),'-o',1:T,fY(:,1),'-d',1:T,fYD(:,1),'-*'); title('Filtered States for x_{1,t}') legend('Simulated Data','Filtered States -- MdlSSM','Filtered States -- Mdl'); subplot(2,1,2) plot(1:T,y(:,1),'-o',1:T,sY(:,1),'-d',1:T,sYD(:,1),'-*'); title('Smoothed States for x_{1,t}') legend('Simulated Data','Smoothed States -- MdlSSM','Smoothed States -- Mdl');
figure; subplot(2,1,1) plot(1:T,y(:,2),'-o',1:T,fY(:,2),'-d',1:T,fYD(:,2),'-*'); title('Filtered States for x_{2,t}') legend('Simulated Data','Filtered States -- MdlSSM','Filtered States -- Mdl'); subplot(2,1,2) plot(1:T,y(:,2),'-o',1:T,sY(:,2),'-d',1:T,sYD(:,2),'-*'); title('Smoothed States for x_{2,t}') legend('Simulated Data','Smoothed States -- MdlSSM','Smoothed States -- Mdl');
In addition to apparent transient behavior in the random walk, the filtered and smoothed states between the standard and diffuse state-space models appear nearly equivalent. The slight difference occurs becausefilter
andsmooth
set all diffuse state estimates in the diffuse state-space model to 0 while they implement the diffuse Kalman filter. Once the covariance matrices of the smoothed states attain full rank,filter
andsmooth
switch to using the standard Kalman filter. In this case, the switching time occurs after the first period.
More About
Static State
Astatic statedoes not change in value throughout the sample, that is, for allt= 1,...,T。
Tips
Specify
ParamMap
in a more general or complex setting, where, for example:The initial state values are parameters.
In time-varying models, you want to use the same parameters for more than one period.
You want to impose parameter constraints.
You can create a
dssm
model object that does not contain any diffuse states. However, subsequent computations, for example, filtering and parameter estimation, can be inefficient. If all states have stationary distributions or are the constant 1, then create anssm
model object instead.
Algorithms
Default values for
Mean0
andCov0
:如果你explicitly specify the state-space model (that is, you provide the coefficient matrices
A
,B
,C
, and optionallyD
), then:For stationary states, the software generates the initial value using the stationary distribution. If you provide all values in the coefficient matrices (that is, your model has no unknown parameters), then
dssm
generates the initial values. Otherwise, the software generates the initial values during estimation.For states that are always the constant 1,
dssm
setsMean0
to 1 andCov0
to0
。For diffuse states, the software sets
Mean0
to 0 andCov0
toInf
by default.
If you implicitly specify the state-space model (that is, you provide the parameter vector to the coefficient-matrices-mapping function
ParamMap
), then the software generates the initial values during estimation.
For static states that do not equal 1 throughout the sample, the software cannot assign a value to the degenerate, initial state distribution. Therefore, set static states to
2
using the name-value pair argumentStateType
。随后,该软件将静态状态as nonstationary and assigns the static state a diffuse initial distribution.It is best practice to set
StateType
for each state. By default, the software generatesStateType
, but this behavior might not be accurate. For example, the software cannot distinguish between a constant 1 state and a static state.The software cannot infer
StateType
from data because the data theoretically comes from the observation equation. The realizations of the state equation are unobservable.dssm
models do not store observed responses or predictor data. Supply the data wherever necessary using the appropriate input or name-value pair arguments.Suppose that you want to create a diffuse state-space model using a parameter-to-matrix mapping function with this signature:
[A,B,C,D,Mean0,Cov0,StateType,DeflateY] = paramMap(params,Y,Z)
Mdl = dssm(@(params)paramMap(params,Y,Z))
Y
and predictor dataZ
are not input arguments in the anonymous function. IfY
andZ
exist in the MATLAB Workspace before you createMdl
, then the software establishes a link to them. Otherwise, if you passMdl
toestimate
, the software throws an error.The link to the data established by the anonymous function overrides all other corresponding input argument values of
estimate
。This distinction is important particularly when conducting a rolling window analysis. For details, seeRolling-Window Analysis of Time-Series Models。
Alternatives
Create anssm
model object instead of adssm
model object when:
The model does not contain any diffuse states.
The diffuse states are correlated with each other or to other states.
You want to implement the standard Kalman filter.
References
[1] Durbin J., and S. J. Koopman.Time Series Analysis by State Space Methods。2nd ed. Oxford: Oxford University Press, 2012.
Version History
Introduced in R2015b
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)