I have just finished reading Time Series Analysis by State Space Methods: Second Edition by James Durbin and Siem Jan Koopman and would like to implement some of the examples in PyMC3.
I’ve just done that for the local level model and compared it against the example given by Chad Fulton in Estimating time series models by state space methods in Python: Statsmodels. Please look at my example notebook for details of the implementation.
First of all I wanted to provide a code example for others as a starting point in case somebody else would like to do something similar.
Second I’d like to have your feed-back if that’s the way to go or if there are other/better ways to do it. I noticed that on several runs with more tuning steps the r_hat of the estimated parameters got very high, sometimes above 1.5. In the one run that I saved that’s sadly not the case, but I ran the notebook several times and often the r_hat values would be high plus there were several/many divergencies. Therefore I guess there’s something not quite right with my implemenation.
As I’d like to implement several other models from Time Series Analysis by State Space Methods: Second Edition it would be good to have a solid starting point.
P.S.: it is on purpose that I did not use something like pm.GaussianRandomWalk(), because this implementation is more “transparent” (you see in detail what’s going on) and you can change it to something non-Gaussian if needed. I’d like to keep that level of transparency if possible.