Closed yonicd closed 7 years ago
As you found out, the contemporaneous estimates of states and their covariances are not given by the output of KFS
. They are of course computed as part of the Kalman filtering recursions, but they are are not stored in order to save some storage space and as the filtering part is more often used for prediction. I guess I could add an auxiliary function for computing them from the output of KFS
, which is quite easy using the equations
at|t = at + Pt * Zt' / Ft * vt Pt|t = Pt - Pt Zt' / Ft * Zt Pt
For multivariate model, the non-exported function mvInnovations
gives you the non-sequential v and F needed in above equations.
Of course if your system matrix Tt is invertible, you can also use equations
at|t = inv(Tt) * a(t+1) Pt|t = inv(Tt) * (Pt(t+1) - Rt * Qt * Rt') * inv(Tt')
I finally added this functionality, KFS now returns att
and Ptt
containing the contemporous filtered estimates as wll.
I am using the KFAS instead of MARSSkfss because my data is non-gaussian. in MARSSkfss i get as part of the output the state of the first moment condition on E[x(t):y(1:t)](there it is called xtt) whereas in the KFAS it gives the output of E[x(t):y(1:t-1)]. Is it possible to extract this expectation from the KFAS package? the output in the KFS it is also missing.