[PYTHON] State space model using Pystan -Deleste event attack format 2001 rank border-
Overview
- I learned how to analyze a state-space model using Stan in a book, so I practiced it with actual data.
- This time I tried to move it with the following model for the time being
- Local level model
- Smoothing trend model
- Local linear trend model
- Time-varying coefficient model (explanatory variable is only the length of the event period)
- As a result, it still doesn't fit well at all
- Because trends and event lengths alone cannot explain
- I would like to make other features and analyze them with the time-varying coefficient model.
- The scripts created this time are c1 ~ c4 of here.
Preparation before using Pystan
pip install pystan
- A little addicted
- I got the error
pystan --Unable to find vcvarsall.bat
and fluttered
- Solutions
- As shown in here, I installed C ++ of Visual Stadio.
Data to use
Data acquired by here extracted only from the format of Attapon

Local level model
- A model that thinks that "the state follows a random walk, noise is added to that state, and output comes out."
- Formulas are [here](https://qiita.com/kazuya_minakuchi/items/09b010927688b322df9d#%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E3%83 See% AC% E3% 83% 99% E3% 83% AB% E3% 83% A2% E3% 83% 87% E3% 83% AB)

Impressions
- It is not in the range of 5% -95% at all, but for the time being, I feel that I can see the overall trend by passing through the center.
- The peak is around the latter half of 2018, and is it gradually decreasing?
Smoothing trend model
- A model that thinks that "the amount of change in the state follows a random walk, noise is added to that state, and the output comes out."
- Amount of change in state: Amount of change from the previous state to the current state
- Formulas are [here](https://qiita.com/kazuya_minakuchi/items/09b010927688b322df9d#%E5%B9%B3%E6%BB%91%E5%8C%96%E3%83%88%E3%83 % AC% E3% 83% B3% E3% 83% 89% E3% 83% A2% E3% 83% 87% E3% 83% AB)

Impressions
- This is also not in the range of 5% -95% at all, but it is still smooth
- Is the peak coming around the end of 2018?
Local linear trend model
- Add "drift component that changes with time" to the local level model
- Something like a combination of a local level model and a smoothing trend model
- When the change of the level component is almost 0, it is the same as the smoothing trend model.
- Formulas are [here](https://qiita.com/kazuya_minakuchi/items/09b010927688b322df9d#%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E7%B7 % 9A% E5% BD% A2% E3% 83% 88% E3% 83% AC% E3% 83% B3% E3% 83% 89% E3% 83% A2% E3% 83% 87% E3% 83% AB )

Impressions
- Again, this is not in the 5% -95% range at all.
- It is between the smoothness of the smoothing trend and the rattling of the local trend.
Time-varying coefficient model
- Add explanatory variables that may affect the objective variable. It is assumed that the coefficients of the explanatory variables also change over time.
- Formulas are [here](https://qiita.com/kazuya_minakuchi/items/09b010927688b322df9d#%E6%99%82%E5%A4%89%E4%BF%82%E6%95%B0%E3%83 % A2% E3% 83% 87% E3% 83% AB)
Local level + time system variable model
- Actual data and predicted value plot


Local linear trend + time system variable model
- Actual data and predicted value plot


Impressions
- Not yet in the 5% -95% range at all.
- The period coefficient is closer to minus
- Thinking normally, that shouldn't be the case (I don't think "the shorter the period, the more points you can earn")
- Seems to be pulled by changes due to other factors
Summary
- Not fit well yet
- Because the factors that affect the border are not fully reflected
- A list of things that came to mind as elements that seemed to be related
- Elements for each event
- Excitement of the event ≒ Popularity of idols who are ranking rewards ** (Everyone aims to be within 2000th place for this purpose, so it seems to have the strongest influence) **
- Elements that are likely to be included in the trend (It seems good to use a local linear trend because there are some that change gradually and some that change suddenly)
- Changes in the number of active users as the popularity of the game changes
- As the number of characters increases, the number of people who can form a neglected formation increases
- Increased time efficiency with grand live implementation
- I chose 2001 as the expected value, but it seems easier to predict the 1st place w
- 1st place is likely to be the value when you use your time to push the limits of human beings.
- However, since 2001 is the border of the highest reward for the event, there should be more demand for Kochi (I have never run the event properly, but I also want to know)