helske / KFAS

KFAS: R Package for Exponential Family State Space Models
64 stars 17 forks source link

state first moment condition on y(1:t) output missing from KFAS #8

Closed yonicd closed 7 years ago

yonicd commented 9 years ago

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.

helske commented 9 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')

helske commented 7 years ago

I finally added this functionality, KFS now returns att and Pttcontaining the contemporous filtered estimates as wll.