# [PYTHON] Time series analysis 2 Stationary, ARMA / ARIMA model

Aidemy　2020/10/29

# Introduction

Hello, it is Yope! I am a liberal arts student, but I was interested in the possibilities of AI, so I went to the AI-specialized school "Aidemy" to study. I would like to share the knowledge gained here with you, and I am summarizing it on Qiita. I am very happy that many people have read the previous summary article. Thank you! This is the second post of time series analysis. Nice to meet you.

What to learn this time ・ About stationarity ・ About ARMA / ARIMA model

# Stationarity

## What is stationarity?

-In time-series data, __ "always fluctuates and changes with a constant value around a constant value regardless of the passage of time" __ is expressed as __ stationarity . -It is necessary to visually check whether the data has the above characteristics by visualizing the data once to check whether it has stationarity. -In time series analysis, if a time series without stationarity is treated as it is, a meaningless correlation ( spurious correlation ) may be detected, so it is converted to a time series with stationarity. There is a need.

## Weak stationarity / strong stationarity

-__Weak stationarity __ means that the __expected value and autocovariance of time series data are always constant __. ・ Since the expected value is constant, it can be said that "always a constant value is the axis", and since the autocovariance is constant, it can be said that "it fluctuates and changes within the same range", so it is stationary. It can be said that there is a certain state.

## White noise

-White noise means that the expected value is 0, the variance is constant, and the covariance is 0 at all __ (weak stationarity). -Of the patterns of the time series model, __irregular fluctuation (error) __ is difficult to express mathematically, so white noise is used to deal with it.

# ARMA / ARIMA / SARIMA model

## About ARMA / ARIMA / SARIMA model

-__ ARMA / ARIMA model __ is a model used when performing time series analysis. -There is also a model called __SARIMA __ in these two types of developments, and finally the SARIMA model will be used for time series analysis. -The ARMA / ARIMA model is a combination of the models __ "AR" and "MA" __. This will be described in detail in the following sections.

• Refer to "Time Series Analysis 4" to actually build these models.

## AR model

-In the AR model, an autocorrelation is created by expressing __the time-series data "yk" at a certain point in time k using the data "yk-1" at the previous point in time __. -Since the data value is regressively estimated from the past value in this way, the AR model is also called __ "autoregressive model" __. At this time, when the next data is predicted using the past p data, it is expressed as __AR (p) __.

## MA model

-In the MA model, an autocorrelation is created by __ expressing the white noise "εk" in the time series data at a certain point in time using the previous white noise "εk-1". -Since white noise shows irregular fluctuations (errors), it can be said that the MA model is __ a model that is affected by past errors. At this time, when predicting the next data using the past q errors, it is expressed as __MA (q) __.

## ARMA model

-As mentioned above, the ARMA model is a model made by combining the AR model and the MA model. -When AR (p) and MA (q) are combined, it is expressed as __ARMA (p, q) __.

## ARIMA model

-The ARIMA model is an "ARMA model that converts the data passed in the original series into a difference series". -The ARMA model to which the original series is passed can handle only stationary data and processes, but the ARIMA model that converts to a difference series can also handle non-stationary data and processes.

-When the model is ARMA (p, q) and the difference at the time of conversion is d (the difference is taken before the d point), it is expressed as __ARIMA (p, d, q) __. -At this time, "p" is called __autocorrelation degree __, "d" is called __induction __, and "q" is called __moving average __.

# Summary

-Weak stationarity means that the __expected value and autocovariance of time series data are always constant. -White noise means that the expected value is 0, the variance is constant, and the covariance is 0 at all __. -There are ARMA model and ARIMA model as models used when performing time series analysis. These models are made by combining the AR model and the MA model, and since the ARIMA model converts the data into a step difference series, it can handle non-stationary data.

This time is over. Thank you for reading until the end.