Language Reference

KALCVS Call

CALL KALCVS (sm, vsm, data, a, f, b, h, var, pred, vpred <, un> <, vun> ) ;

This subroutine is supported by the IML procedure and the iml action.

The KALCVS subroutine uses backward recursions to compute the smoothed estimate z Subscript t vertical-bar upper T and its covariance matrix, upper P Subscript t vertical-bar upper T, where T is the number of observations in the complete data set.

The input arguments to the KALCVS subroutine are as follows.

data

is a upper T times upper N Subscript y matrix that contains data left-parenthesis y 1 comma ellipsis comma y Subscript upper T Baseline right-parenthesis prime.

a

is an upper N Subscript z Baseline times 1 vector for a time-invariant input vector in the transition equation, or a upper T upper N Subscript z times 1 vector that contains input vectors in the transition equation.

f

is an upper N Subscript z Baseline times upper N Subscript z matrix for a time-invariant transition matrix in the transition equation, or a upper T upper N Subscript z times upper N Subscript z matrix that contains T transition matrices.

b

is an upper N Subscript y Baseline times 1 vector for a time-invariant input vector in the measurement equation, or a upper T upper N Subscript y times 1 vector that contains input vectors in the measurement equation.

h

is an upper N Subscript y Baseline times upper N Subscript z matrix for a time-invariant measurement matrix in the measurement equation, or a upper T upper N Subscript y times upper N Subscript z matrix that contains T time-variant upper H Subscript t matrices in the measurement equation.

var

is an left-parenthesis upper N Subscript z Baseline plus upper N Subscript y Baseline right-parenthesis times left-parenthesis upper N Subscript z Baseline plus upper N Subscript y Baseline right-parenthesis covariance matrix for the errors in the transition and the measurement equations, or a upper T left-parenthesis upper N Subscript z Baseline plus upper N Subscript y Baseline right-parenthesis times left-parenthesis upper N Subscript z Baseline plus upper N Subscript y Baseline right-parenthesis matrix that contains covariance matrices in the transition equation and measurement equation noises—that is, left-parenthesis eta prime Subscript t Baseline comma epsilon prime Subscript t right-parenthesis prime.

pred

is a upper T times upper N Subscript z matrix that contains one-step forecasts left-parenthesis z Subscript 1 vertical-bar 0 Baseline comma ellipsis comma z Subscript upper T vertical-bar upper T minus 1 Baseline right-parenthesis prime.

vpred

is a upper T upper N Subscript z times upper N Subscript z matrix that contains mean square error matrices of predicted state vectors left-parenthesis upper P Subscript 1 vertical-bar 0 Baseline comma ellipsis comma upper P Subscript upper T vertical-bar upper T minus 1 Baseline right-parenthesis prime.

un

is an optional 1 times upper N Subscript z vector that contains u Subscript upper T. The returned value is u 0.

vun

is an optional upper N Subscript z Baseline times upper N Subscript z matrix that contains upper U Subscript upper T. The returned value is upper U 0.

The KALCVS call returns the following values:

sm

is a upper T times upper N Subscript z matrix that contains smoothed state vectors left-parenthesis z Subscript 1 vertical-bar upper T Baseline comma ellipsis comma z Subscript upper T vertical-bar upper T Baseline right-parenthesis prime.

vsm

is a upper T upper N Subscript z times upper N Subscript z matrix that contains covariance matrices of smoothed state vectors left-parenthesis upper P Subscript 1 vertical-bar upper T Baseline comma ellipsis comma upper P Subscript upper T vertical-bar upper T Baseline right-parenthesis prime.

When the Kalman filtering is performed in the KALCVF call, the KALCVS call computes smoothed state vectors and their covariance matrices. The fixed-interval smoothing state vector at time t is obtained by the conditional expectation given all observations.

The smoothing algorithm uses one-step forecasts and their covariance matrices, which are given in the KALCVF call. For notation, z Subscript t vertical-bar upper T is the smoothed value of the state vector z Subscript t, and the mean square error matrix is denoted upper P Subscript t vertical-bar upper T. For smoothing,

StartLayout 1st Row 1st Column ModifyingAbove epsilon With caret Subscript t 2nd Column equals 3rd Column y Subscript t Baseline minus b Subscript t Baseline minus upper H Subscript t Baseline z Subscript t vertical-bar t minus 1 2nd Row 1st Column upper D Subscript t 2nd Column equals 3rd Column upper H Subscript t Baseline upper P Subscript t vertical-bar t minus 1 Baseline upper H prime Subscript t plus upper R Subscript t 3rd Row 1st Column upper K Subscript t 2nd Column equals 3rd Column left-parenthesis upper F Subscript t Baseline upper P Subscript t vertical-bar t minus 1 Baseline upper H prime Subscript t plus upper G Subscript t Baseline right-parenthesis upper D Subscript t Superscript minus 4th Row 1st Column upper L Subscript t 2nd Column equals 3rd Column upper F Subscript t Baseline minus upper K Subscript t Baseline upper H Subscript t 5th Row 1st Column u Subscript t minus 1 2nd Column equals 3rd Column upper H prime Subscript t Baseline upper D Subscript t Superscript minus Baseline ModifyingAbove epsilon With caret Subscript t plus upper L prime Subscript t Baseline u Subscript t 6th Row 1st Column upper U Subscript t minus 1 2nd Column equals 3rd Column upper H prime Subscript t Baseline upper D Subscript t Superscript minus Baseline upper H Subscript t plus upper L prime Subscript t Baseline upper U Subscript t Baseline upper L Subscript t 7th Row 1st Column z Subscript t vertical-bar upper T 2nd Column equals 3rd Column z Subscript t vertical-bar t minus 1 Baseline plus upper P Subscript t vertical-bar t minus 1 Baseline u Subscript t minus 1 8th Row 1st Column upper P Subscript t vertical-bar upper T 2nd Column equals 3rd Column upper P Subscript t vertical-bar t minus 1 Baseline minus upper P Subscript t vertical-bar t minus 1 Baseline upper U Subscript t minus 1 Baseline upper P Subscript t vertical-bar t minus 1 EndLayout

where t equals upper T comma upper T minus 1 comma ellipsis comma 1. The initial values are u Subscript upper T Baseline equals bold 0 and bold upper U Subscript upper T Baseline equals bold 0.

When the SSM is specified by using the alternative transition equation

z Subscript t Baseline equals a Subscript t Baseline plus upper F Subscript t Baseline z Subscript t minus 1 Baseline plus eta Subscript t

the fixed-interval smoothing is performed by using the following backward recursions:

StartLayout 1st Row 1st Column ModifyingAbove epsilon With caret Subscript t 2nd Column equals 3rd Column y Subscript t Baseline minus b Subscript t Baseline minus upper H Subscript t Baseline z Subscript t vertical-bar t minus 1 2nd Row 1st Column upper D Subscript t 2nd Column equals 3rd Column upper H Subscript t Baseline upper P Subscript t vertical-bar t minus 1 Baseline upper H prime Subscript t plus upper R Subscript t 3rd Row 1st Column upper K Subscript t 2nd Column equals 3rd Column upper F Subscript t plus 1 Baseline upper P Subscript t vertical-bar t minus 1 Baseline upper H prime Subscript t Baseline upper D Subscript t Superscript minus 4th Row 1st Column upper L Subscript t 2nd Column equals 3rd Column upper F Subscript t plus 1 Baseline minus upper K Subscript t Baseline upper H Subscript t 5th Row 1st Column u Subscript t minus 1 2nd Column equals 3rd Column upper H prime Subscript t Baseline upper D Subscript t Superscript minus Baseline ModifyingAbove epsilon With caret Subscript t plus upper L prime Subscript t Baseline u Subscript t 6th Row 1st Column upper U Subscript t minus 1 2nd Column equals 3rd Column upper H prime Subscript t Baseline upper D Subscript t Superscript minus Baseline upper H Subscript t plus upper L prime Subscript t Baseline upper U Subscript t Baseline upper L Subscript t 7th Row 1st Column z Subscript t vertical-bar upper T 2nd Column equals 3rd Column z Subscript t vertical-bar t minus 1 Baseline plus upper P Subscript t vertical-bar t minus 1 Baseline u Subscript t minus 1 8th Row 1st Column upper P Subscript t vertical-bar upper T 2nd Column equals 3rd Column upper P Subscript t vertical-bar t minus 1 Baseline minus upper P Subscript t vertical-bar t minus 1 Baseline upper U Subscript t minus 1 Baseline upper P Subscript t vertical-bar t minus 1 EndLayout

where it is assumed that upper G Subscript t Baseline equals bold 0.

You can use the KALCVS call regardless of the specification of the transition equation when upper G Subscript t Baseline equals bold 0. Harvey (1989) gives the following fixed-interval smoothing formula, which produces the same smoothed value:

StartLayout 1st Row 1st Column z Subscript t vertical-bar upper T 2nd Column equals 3rd Column z Subscript t vertical-bar t Baseline plus upper P Subscript t Superscript asterisk Baseline left-parenthesis z Subscript t plus 1 vertical-bar upper T Baseline minus z Subscript t plus 1 vertical-bar t Baseline right-parenthesis 2nd Row 1st Column upper P Subscript t vertical-bar upper T 2nd Column equals 3rd Column upper P Subscript t vertical-bar t Baseline plus upper P Subscript t Superscript asterisk Baseline left-parenthesis upper P Subscript t plus 1 vertical-bar upper T Baseline minus upper P Subscript t plus 1 vertical-bar t Baseline right-parenthesis upper P Subscript t Superscript asterisk prime EndLayout

where

upper P Subscript t Superscript asterisk Baseline equals upper P Subscript t vertical-bar t Baseline upper F prime Subscript t Baseline upper P Subscript t plus 1 vertical-bar t Superscript minus

under the shifted transition equation, but

upper P Subscript t Superscript asterisk Baseline equals upper P Subscript t vertical-bar t Baseline upper F prime Subscript t plus 1 Baseline upper P Subscript t plus 1 vertical-bar t Superscript minus

under the alternative transition equation.

The KALCVS call is accompanied by the KALCVF call, as shown in the following statements. Note that you do not need to specify UN and VUN.

call kalcvf(pred, vpred, filt, vfilt, y, 0, a, f, b, h, var);
call kalcvs(sm, vsm, y, a, f, b, h, var, pred, vpred);

You can also compute the smoothed estimate and its covariance matrix on an observation-by-observation basis. When the SSM is time invariant, the following example performs smoothing. In this situation, you should initialize UN and VUN as matrices of value 0, as shown in the following statements:

call kalcvf(pred, vpred, filt, vfilt, y, 0, a, f, b, h, var);
n = nrow(y);
nz = ncol(f);
un = j(1, nz, 0);
vun = j(nz, nz, 0);

do i = 1 to n;
   y_i = y[n-i+1,];
   pred_i  = pred[n-i+1,];
   vpred_i = vpred[(n-i)*nz+1:(n-i+1)*nz,];
   call kalcvs(sm_i, vsm_i, y_i, a, f, b, h, var,
               pred_i, vpred_i, un, vun);
   sm  = sm_i // sm;
   vsm = vsm_i // vsm;
end;

The KALCVF call has an example program that includes the KALCVS call.

Last updated: July 20, 2026