Language Reference

KALDFS Call

computes the smoothed state vector and its mean square error matrix from the one-step forecast and mean square error matrix computed by KALDFF

CALL KALDFS( sm, vsm, data, int, coef, var, bvec, bmat, initial, at,
           mt, s2 <, un, vun>);


The inputs to the KALDFS subroutine are as follows:

data
is a t x n_y matrix containing data ({y}_1,  ... , {y}_t)^'.

int
is an (n_y + n_z) x n_\beta vector for a time-invariant intercept, or a (t+{lead})(n_y + n_z) x   n_\beta vector containing fixed matrices for the time-variant model in the transition equation and the measurement equation - that is, ({w}^'_t, {x}^'_t)^'.

coef
is an (n_y + n_z) x n_z matrix for a time-invariant coefficient, or a (t+{lead})(n_y + n_z) x n_z matrix containing coefficients at each time in the transition equation and the measurement equation - that is, ({f}^'_t, {h}^'_t)^'.

var
is an (n_y + n_z) x (n_y + n_z) matrix for a time-invariant variance matrix for transition equation noise and the measurement equation noise, or a (t+{lead})(n_y + n_z) x (n_y + n_z) matrix containing covariance matrices for the transition equation and measurement equation errors - that is, (\eta^'_t, \epsilon^'_t)^'.

bvec
is an n_\beta x 1 constant vector for the intercept for the mean effect \beta.

bmat
is an n_\beta x n_\delta matrix for the coefficient for the mean effect \beta.

initial
is an n_\delta x (n_\delta + 1) matrix containing an initial random vector estimate and its covariance matrix - that is, (\hat{\delta}_t, \hat{\sigma}_{\delta, t}).

at
is a tn_z x (n_\delta + 1) matrix containing ({a}^'_1,  ... , {a}^'_t)^'.

mt
is a (tn_z) x n_z matrix containing ({m}_1,  ... , {m}_t)^'.

s2
is the estimated variance in the end of the data set, \hat{\sigma}^2_t.

un
is an optional n_z x (n_{\delta} + 1) matrix containing {u}_t. The returned value is {u}_0.

vun
is an optional n_z x n_z matrix containing {u}_t. The returned value is {u}_0.

The KALDFS call returns the following values:

sm
is a t x n_z matrix containing smoothed state vectors ({z}_{1| t},  ... , {z}_{t| t})^'.

vsm
is a tn_z x n_z matrix containing mean square error matrices of smoothed state vectors ({p}_{1| t},  ... , {p}_{t| t})^'.

Given the one-step forecast and mean square error matrix in the KALDFF call, the KALDFS call computes a smoothed state vector and its mean square error matrix. Then the KALDFS subroutine produces an estimate of the smoothed state vector at time t - that is, the conditional expectation of the state vector {z}_t given all observations. Using the notations and results from the KALDFF section, the backward recursion algorithm for smoothing is denoted for t = t, t-1,  ... , 1,
{e}_t & = & ({x}_t {b},  {y}_t - {x}_t {b}) - {h}_t {a}_t    \    {d}_t & = & {h}_...   ...}}_{t-1} {m}_t) +    {c}_{t(\delta)} \hat{\sigma}_{\delta,t}    {c}^'_{t(\delta)}
where the initial values are {u}_t = 0 and {u}_t = 0, and {c}_{t(\delta)} is the last-column-deleted submatrix of {c}_t. Refer to De Jong (1991) for details about smoothing in the diffuse Kalman filter.

The KALDFS call is accompanied by the KALDFF call as shown in the following code:

  
    ny = ncol(y); 
    nz = ncol(coef); 
    nb = ncol(int); 
    nd = ncol(coefd); 
    at = j(nz,nd+1,.); 
    mt = j(nz,nz,.); 
    qt = j(nd+1,nd+1,.); 
    n0 = -1; 
    call kaldff(pred,vpred,initial,s2,y,0,int,coef,var,intd,coefd, 
                n0,at,mt,qt); 
    bvec = intd[nz+1:nz+nb,]; 
    bmat = coefd[nz+1:nz+nb,]; 
    call kaldfs(sm,vsm,x,int,coef,var,bvec,bmat,initial,at,mt,s2);
 
You can also compute the smoothed estimate and its covariance matrix observation by observation. When the SSM is time invariant, the following code performs smoothing. You should initialize UN and VUN as matrices of value 0. Here is the code:
  
    n  = nrow(y); 
    ny = ncol(y); 
    nz = ncol(coef); 
    nb = ncol(int); 
    nd = ncol(coefd); 
    at = j(nz,nd+1,.); 
    mt = j(nz,nz,.); 
    qt = j(nd+1,nd+1,.); 
    n0 = -1; 
    call kaldff(pred,vpred,initial,s2,y,0,int,coef,var,intd,coefd, 
                n0,at,mt,qt); 
    bvec = intd[nz+1:nz+nb,]; 
    bmat = coefd[nz+1:nz+nb,]; 
    un  = j(nz,nd+1,0); 
    vun = j(nz,nz,0); 
    do i = 1 to n; 
       call kaldfs(sm_i,vsm_i,y[n-i+1],int,coef,var,bvec,bmat, 
                   initial,at,mt,s2,un,vun); 
       sm  = sm_i // sm; 
       vsm = vsm_i // vsm; 
    end;
 

Previous Page | Next Page | Top of Page