| MATLAB MEX Function Reference |
In this example, the log-likelihood function of the SSM is computed using prediction error decomposition. The annual real GNP series, yt, can be decomposed as
It is straightforward to construct the SSM of the real GNP series.
![{H}& = & (1, 0) \
{F}& = & [ 1 & 1 \
0 & 1
] \
{z}_t & = & (\mu_t, \beta...
...\eta 1} & 0 & 0 \
0 & \sigma^2_{\eta 2} & 0 \
0 & 0 & \sigma^2_\epsilon
]](images/eq34.gif)

The following example MATLAB script computes the average log-likelihood function. First, the average log-likelihood function is computed using the default initial values: Z0=0 and VZ0=106I. The second call of function KALCVF produces the average log-likelihood function with the given initial conditions: Z0=0 and VZ0=10-3I. You can notice a sizable difference between the uncertain initial condition (VZ0=106I) and the almost deterministic initial condition (VZ0=10-3I) in Output 1.
Finally, the first 16 observations of one-step predictions, filtered values, and real GNP series are produced under the moderate initial condition (VZ0=10I). The data are the annual real GNP for the years 1909 to 1969.
y = [ 116.8 120.1 123.2 130.2 131.4 125.6 124.5 134.3 ...
135.2 151.8 146.4 139.0 127.8 147.0 165.9 165.5 ...
179.4 190.0 189.8 190.9 203.6 183.5 169.3 144.2 ...
141.5 154.3 169.5 193.0 203.2 192.9 209.4 227.2 ...
263.7 297.8 337.1 361.3 355.2 312.6 309.9 323.7 ...
324.1 355.3 383.4 395.1 412.8 406.0 438.0 446.1 ...
452.5 447.3 475.9 487.7 497.2 529.8 551.0 581.1 ...
617.8 658.1 675.2 706.6 724.7 ];
T = size(y,2);
lead = 0;
Nz = 2;
a = zeros(Nz,1);
F = [1 1; 0 1];
Ny = 1;
b = zeros(Ny,1);
H = [1 0];
var = eye(Ny+Nz)*1e-3;
fprintf('\nLikelihood Evaluation of SSM\n');
fprintf('DATA: Annual Real GNP 1909-1969\n\n');
logl = kalcvf(y, lead, a, F, b, H, var);
fprintf('No initial values are given\n');
fprintf('LOGL = %.2f\n\n', logl);
z0 = a;
vz0 = eye(Nz)*1e-3;
logl = kalcvf(y, lead, a, F, b, H, var, z0, vz0);
fprintf('Initial values are given\n');
fprintf('LOGL = %.2f\n\n', logl);
lead = 1;
z0 = a;
vz0 = eye(Nz)*10;
[logl, pred, vpred, filt, vfilt] = kalcvf(y, lead, a, F, b, H, var, z0, vz0);
fprintf('Filtering and One-Step Prediction\n');
fprintf(' Y PRED FILT\n')
format,disp([y(1:16); pred(:,1:16); filt(:,1:16)]')
Output 1: Average Log Likelihood of SSM
Likelihood Evaluation of SSM DATA: Annual Real GNP 1909-1969 No initial values are given LOGL = -26313.74 Initial values are given LOGL = -91883.49 |
Output 2 shows the observed data, the predicted state vectors, and the filtered state vectors for the first 16 observations.
Output 2: Filtering and One-Step Prediction
Y PRED FILT 116.8000 0 0 116.7883 0 120.1000 116.7883 0 120.0997 3.3107 123.2000 123.4104 3.3107 123.2234 3.1938 130.2000 126.4172 3.1938 129.5920 4.8826 131.4000 134.4746 4.8826 131.9381 3.5759 125.6000 135.5139 3.5759 127.3625 -0.6100 124.5000 126.7525 -0.6100 124.9012 -1.5607 134.3000 123.3405 -1.5607 132.3475 3.0651 135.2000 135.4126 3.0651 135.2379 2.9754 151.8000 138.2132 2.9754 149.3795 8.7101 146.4000 158.0896 8.7101 148.4825 3.7761 139.0000 152.2587 3.7761 141.3621 -1.8201 127.8000 139.5420 -1.8201 129.8919 -6.7762 147.0000 123.1157 -6.7762 142.7449 3.3050 165.9000 146.0499 3.3050 162.3636 11.6833 165.5000 174.0470 11.6833 167.0227 8.0758 |
See also
KALCVF performs covariance filtering and prediction
KALCVS performs fixed-interval smoothing
Getting Started with State Space Models
Kalman Filtering Example 2: Estimating an SSM Using the EM Algorithm
References
[1] Nelson, C.P. and Plosser, C.I., Trends and Random Walks in Macroeconomic Time Series: Some Evidence and Implications, Journal of Monetary Economics, vol 10, pp. 139-162, 1982.