LAMPSPUC/StateSpaceModels.jl

Local Level Model with Explanatory Variables?

Closed this issue · 9 comments

Is is possible to add a new model template: Local Level with Explanatory Variables model (i.e., one as described in Chapter 5 of Commandeur and Koopman, and laid out in matrix form in Section 8.1)?

In a previous version, I was able to put a simple one together on top of v0.3.0 (simply adjusting the Z, T and R matrices), giving a model that has a local level and then an arbitrary number of regressors. These could then coefficients that either varied in time or were fixed (by setting the relevant elements of R equal to 1 or 0).

So far, I have been unable to add a working model to v0.5 because I do not yet understand a) the new approach to hyperparameters or b) the filter to use (Univariate Kalman?) and probably some other things too! I can of course submit a pull request but would rather do so with working code. Any help would be much appreciated.

... and now have progressed a little, but keep getting a singular exception error.

Hi @PaulMainwood, we're aware that dealing with exogenous variables is a useful feature. We'd ideally want to have a general framework that allows adding exogenous variables to any given model, but that's a little challenging, hence why we haven't done it yet.

However, before we get to that point, we'll work on adding it to the current models for now so that this feature isn't missing anymore. We'll prioritize local level since that's what you're using.

Thanks for the feedback!

Thank you @raphaelsaavedra.

Would it help if I submitted my current attempt (as I say, it errors to a singular exception at present)?

Thanks! Although yours looks mostly good, @guilhermebodin did his own take of it and we'll probably go forward with his PR.

Yes, just been playing with @guilhermebodin 's version and it a) works! and b) does almost exactly what I want. All I need to do is put in a new R matrix to turn on and off the variable coefficients I am after.

I will add an interface for this in my own fork (just a optional bitarray argument that switches them from variable to fixed), but this may be a minority interest.

Thank you both for your help here.

Can you clarify what you mean by an R matrix to turn on and off the variable coefficients? Do you want the exogenous regressors not to be active in certain periods of time?

I just mean that I want to experiment with by being able to select some of the \betas holding constant values over time versus some being allowed to drift in a random walk. At present, @guilhermebodin's model has them all set as constant.

My use-case is that I have a reasonable selection of explanatory variables (8 - 10 in most cases). Some I very much want some to vary over time (e.g., price elasticities). But allowing them all vary, quickly leads to overfitting.

I think a simple way of doing this (now implemented) is to alter the Q matrix to an identity matrix of order m x m, and then change the R matrix to a diagonal matrix with a leading diagonal made up of either ones (for changing in time) or zeroes (for keeping constant over time).

Does that make sense?

Makes perfect sense! I agree this is a little too specific to implement as a predefined model. Maybe in a future version when we have a more flexible framework we might be able to do something along those lines.

#Closed by #215