statespace_smoother#

The state and disturbance smoother (DK §4.4, §4.5), with the exact initial smoother for diffuse periods (DK §5.3).

The backward recursion computes \(r_{t-1}\) and \(N_{t-1}\) (DK eqs. 4.39, 4.43), then

\[\hat\alpha_t = a_t + P_t r_{t-1}, \qquad V_t = P_t - P_t N_{t-1} P_t,\]

and the smoothed disturbances \(\hat\varepsilon_t = H_t u_t\) and \(\hat\eta_t = Q_t R_t' r_t\) (DK eq. 4.63) with their variances. In diffuse periods it adds the recursions for \(r^{(1)}, N^{(1)}, N^{(2)}\), element by element or in the multivariate form, matching how the filter processed the period.

smoother_result_t#

type :: smoother_result_t
  integer :: k_endog, k_states, k_posdef, nobs
  real(dp), allocatable :: alphahat(:, :)   ! (m, n)       E(alpha_t | Y_n)
  real(dp), allocatable :: V(:, :, :)       ! (m, m, n)    Var(alpha_t | Y_n)
  real(dp), allocatable :: r(:, :)          ! (m, 0:n)
  real(dp), allocatable :: N(:, :, :)       ! (m, m, 0:n)
  real(dp), allocatable :: epshat(:, :)     ! (p, n)       E(eps_t | Y_n)
  real(dp), allocatable :: epsvar(:, :, :)  ! (p, p, n)
  real(dp), allocatable :: etahat(:, :)     ! (r, n)       E(eta_t | Y_n)
  real(dp), allocatable :: etavar(:, :, :)  ! (r, r, n)
end type

r and N use DK’s indexing: 0, …, n with \(r_n = 0\) and \(N_n = 0\); in diffuse periods they hold \(r^{(0)}, N^{(0)}\).

For a missing element of \(y_t\), epshat and epsvar are the conditional moments of that element of \(\varepsilon_t\) given the observed data, nonzero when \(H_t\) has correlations; statsmodels reports 0 and \(H_t\). EM needs the conditional moments (see Missing observations). The moments are in the original coordinates of \(y_t\) in every period.

state_smoother#

subroutine state_smoother(rep, fres, sres, info)
  type(ssm_rep_t), intent(in) :: rep
  type(filter_result_t), intent(in) :: fres
  type(smoother_result_t), intent(out) :: sres
  integer, intent(out) :: info

Smooth a filter run of rep (from kalman_filter). info is SS_ERR_DIM if fres does not match rep.

diffuse_mv_gains#

subroutine diffuse_mv_gains(rep, fres, t, Zo, vo, F1, F2, L0, L1)
  type(ssm_rep_t), intent(in) :: rep
  type(filter_result_t), intent(in) :: fres
  integer, intent(in) :: t
  real(dp), allocatable, intent(out) :: Zo(:, :), vo(:), F1(:, :), F2(:, :), L0(:, :), L1(:, :)

The quantities of the multivariate exact initial smoother at a period with \(F_\infty\) nonsingular over the observed elements o: \(F^{(1)} = F_\infty^{-1}\), \(F^{(2)} = -F^{(1)} F_* F^{(1)}\), \(L^{(0)} = T - K^{(0)} Z_o\) and \(L^{(1)} = -K^{(1)} Z_o\) (DK §5.2-5.3). Used by the smoothing extras (statespace_smoothing).