Time Series Analysis Part 2: SARIMA
Time Series Analysis Part 2: SARIMA
This is part of a series of posts that aims to capture and compile the knowledge required in order to analyse time series data. This part will serve as a quick guide to analyse time series components.
Time series analysis is a powerful technique that can help you forecast future values based on historical data. To get started, you’ll want to analyse the components of your time series. Here’s a quick guide on how to do that:
Step 1: Check for stationarity
A stationary time series is one where the mean, variance, and autocorrelation structure do not change over time. A common way to check stationarity is to use the Augmented Dickey-Fuller (ADF) test or the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test.
Quick tip for adf test:
If p-value < 0.05(significance level) then reject null hypothesis ==> series is staionary.
If p-value > 0.05 then fail to reject the null hypothesis ==> series not stationary.
If it’s not stationary, it can be made stationary through techniques such as differencing, detrending, or deseasonalizing:
- Differencing involves subtracting the current observation from the previous observation, which removes the trend component.
- Detrending involves fitting a linear regression model to the time series and subtracting the trend component from the data.
- Deseasonalizing involves removing the seasonal component from the time series, which can be done through seasonal differencing or seasonal decomposition.
Step 2: Determine the type of process
Use ACF and PACF plots to determine the type of process: Autocorrelation Function (ACF) and Partial Autocorrelation Function (PACF) plots can help you determine whether your time series is an autoregressive (AR), moving average (MA), or a combination of both (ARMA) process.
TLDR;
Process AR(p) MA(q) ARMA(p,q) PACF Cuts-off (after pth lag) Infinite, Tails Off, Dominated by Damped Exponentials & Sinusoidal Infinite, Tails Off, Dominated by Damped Exponentials & Sinusoidal ACF Infinite, Tails Off, Damped Exponentials and/or Sinusoidal Cuts-off (after qth lag) Infinite, Tails Off, Damped Exponentials and/or Sinusoidal
-
For an AR process, the ACF plot will show a slowly decaying pattern (tails off), while the PACF plot will show a sharp cutoff after a certain lag. The lag where the PACF plot cuts off can help determine the order of the AR process. Significant spikes might be observed at Pth lag in PACF plot. Also note that the ACF might show a sinusoidal pattern.
-
For an MA process, the ACF plot will show a sharp cutoff after a certain lag, while the PACF plot will show a slowly decaying pattern (tails off). The lag where the ACF plot cuts off can help determine the order of the MA process. Significant spikes might be observed at Pth lag in ACF plot. Also note that the PACF might show a sinusoidal pattern.
-
If both plots show significant spikes at lag P and gradual decay, your time series may be an ARMA process. It’s important to note that sometimes the ACF or PACF plot may have a sinusoidal pattern, indicating a seasonal component in the time series. In such cases, it may be necessary to analyse the lags of the seasonal component separately using seasonal ACF and PACF plots.
Step 3: Analyse seasonal patterns
Analyse seasonal patterns: A seasonal pattern is a repeated pattern that occurs over a fixed time period, such as daily, weekly, or monthly. A common tool for analysing seasonal patterns is the seasonal decomposition plot, which breaks down the time series into its trend, seasonal, and residual components.
-
To create a seasonal decomposition plot, you can use the
seasonal_decompose
function from the statsmodels library in Python.This function decomposes the time series into its components and returns them in a convenient format. You can then plot these components using theplot
method to visualise the seasonal pattern in the data. -
You can then apply the same methodology\steps outlined in step 2 to analyse what kind of process the seasonal component follows.
By following these steps, you can quickly analyse the components of your time series and start building models to forecast future values. However, it’s important to note that further analysis and model selection may be necessary to accurately forecast the time series.
References: