Considering that there are several packages in R to run the Kalman filter
(see for instance Tusell, 2011 and the documentation in package KFKSDS)
and that the optim
function in the stats package provides
and interface to the L-BFGS-B and to other optimization algorithms,
fitting a structural time series model may seem a simple procedure that
requires little more than translating the matrices of the state space form of
the model into the syntax of the chosen interface.
In practice, the process is not always that straightforward.
As stated in the documentation of StructTS
,
optimization of structural models is a lot harder than many of the
references admit.
There are several details that should be taken into account
when implementing the procedure described above,
(López-de-Lacalle, 2013).
There are not many packages in R that provide alternative procedures to fit structural models. It is probably a consequence of the widespread believe that all that is needed to carry out and analysis with structural time series models is an implementation of the Kalman filter together with a general purpose optimization algorithm.
The package stsm implements specific algorithms to fit models in the framework of the basic structural time series model. The following enhancements to general purpose optimization algorithms are implemented: scoring algorithm based on analytical derivatives, maximization of the time or frequency domain likelihood function, automatic choice of the optimal step size, concentration of a parameter, implementation of the original and a modified version of the expectation-maximization algorithm.