helske / KFAS

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

Requesting State Offset Term or Control Input specification #66

Closed baogorek closed 1 year ago

baogorek commented 3 years ago

The Wikipedia page on the Kalman Filter has the state equation including a "control input model" with matrix "B_k" multiplied by control input "u_k". Python's statsmodels package offers a state offset "d_t", which the user can then manually create according to B_k * u_k. KFAS has neither of these options, which has me going to statsmodels which I like much less. I believe this functionality is relatively simple to implement and would bring KFAS to above and beyond feature parity with statsmodels.

I may be able to help with this if you've got time to walk me through some of the more advanced code.

helske commented 3 years ago

Indeed, it is unfortunate that I didn't implement observation and state intercepts early on. Unfortunately, while in principle adding these should be straightforward, these would affect a very large number of functions both on R and Fortran side, so quite an extensive coding and testing would be needed to make everything consistent. But of course, if you are willing to contribute, pull requests are very welcome.

As an alternative way of handling the offset terms, you could also augment these terms to the state vector in various ways using SSMcustom. The downside of this approach is an increased computation time compared to proper offset terms due to the increased size of the state vector, but depending on the size of the model/data, this might be an ok approach. The last example in ?KFAS illustrates this approach (there are few alternative ways how these could be coded, here the offsets are unknown).

I have personally switched to my more recent package bssm in these cases, which supports the intercept terms in both state and observation equations, but with `bssm´.

baogorek commented 3 years ago

Thanks for filling me in on the situation. I do want to learn how to use and read Fortran code within R packages, so perhaps in the future I'll make KFAS the case study.

Glad to know it is possible to modify SSMcustom to use a state offset. Glancing at the example you referenced, I see it involves separate transition matrices for every time point.

I will check out bssm!