IKH

Non-Stationary to Stationary

In the previous segment, you learnt about the importance of stationarity and a couple of formal tests to detect it. In this segment, we will learn the ways to convert a non-stationary series into a stationary series to build an Auto Regressive model.

The two tools to convert a non-stationary series into stationary series are as follows:

  • Differencing
  • Transformation

Let’s study these tools in detail.

To remove the trend (to make the mean constant) in a time series you use the technique called differencing. As the name suggests, in differencing you compute the differences between consecutive observations. Differencing stabilises the mean of a time series by removing changes in the level of a time series and therefore eliminating (or reducing) trend and seasonality. 

For Example:

Original time seriesAfter 1st order differencingAfter 2nd order differencing
50
180130
420240110
770350110
1240470120
1820580110

Here 1st order differencing is calculated by the difference of two consecutive observations of the original time series. 2nd order differencing is calculated by the difference of two consecutive observations of the 1st order differenced series.

At the first difference level, it still has a linear trend but we have successfully removed the higher-order trend observed in the original time series. After the 2nd difference level, the series obtained is mostly a horizontal line. There is no overall visible trend in this series and thus you can say the series obtained is a stationary series.

The other method to introduce the stationarity is making the variance constant. There can be many transformation methods used to make a non-stationary series stationary but here, we are discussing the Box-Cox transformation. 

The mathematical formulae that Box-cox transformation is:

where y is the original time series and y(λ) is the transformed series. The procedure for the Box-Cox transformation is to find the optimal value of λ between -5 and 5 that minimizes the variance of the transformed data (The formula is not important to remember; the main thing you should know is how to implement this using Python which you will learn in the next video.).

Below is the time series data on which Box-Cox transformation is implemented with λ = 0.2 as shown in the demonstration above.

y(t)25411153028605611060120240200150
y(0.2)0.741.891.593.073.594.874.736.336.187.806.338.029.969.428.62

Here we clearly see after the Box-Cox transformation the variance has become more or less constant or stabilised but still has a trend. Again, this trend can be removed by differencing.

Now that you know the methods to convert a non-stationary series into a stationary series, let us convert the airline passenger dataset which is a non-stationary series into a stationary series.

In this segment, you studied the methods to convert a non-stationary series into a stationary series. Now, it is time for you to answer a few questions on these topics.