-** Implemented the code in the stan chapter of "Basics of Time Series Analysis and State Space Models R and Stan Theory and Implementation" using pystan **
-** I read Hayabusa because I wanted to know time series analysis, but I only understand python! Write in python! Person **
Whenever you look up an introductory book on time series analysis, you will always find "Basics of time series analysis and state-space models: theory and implementation learned with R and Stan", so-called Hayabusa. In this book, "time series analysis such as AR model and MA model", "Gauss linear state space model", and "state space model by Bayesian estimation" are explained in a very detailed manner. ** The R and stan languages are used in the book, which is a bit of a pain for someone like me who can only use python. ** **
However, you can also use stan in python, so you can implement the same thing as introduced in the book. ** Therefore, I will introduce the Bayesian estimation by Hayashimoto's stan, which was actually implemented using python. ** **
Implementation is done using google colab. In google colab, it can be used only by importing by pystan. In other words, no initial settings are required, which is very convenient. ** Click here for the code. ** ** https://github.com/nakanakana12/hayabusa-bon
As for the code, refer to github, but here I will briefly introduce only the result.
The result of estimating the state space of the local level model (random walk with noise added) is as follows.
Blue is the state and orange is the observed value. The 95% section of the state estimated using stan is a blue net. Compared to the graph in the book, it seems to be implemented correctly.
In the next chapter, we will model a slightly more complex equation. The blue line is the observed value, and the orange line is the value when there is no process error. This is also implemented correctly.
--Implemented Hayabusa's stan part using python. --Compare with the results of the book and confirm that it seems to be implemented correctly.
I hope it helps you even a little.
--Hayamoto Support Page: https://logics-of-blue.com/tsa-ssm-book-support/ --R and stan code and data: https://github.com/logics-of-blue/book-tsa-ssm-foundation
Recommended Posts