Time Series Analysis- Part II

Madhu Ramiah
3 min readAug 21, 2019

--

In the previous blog we learnt about what a time series looks like and how to know if the data is stationary or not. In this blog we will look into methods to convert the non stationary data into stationary data.

  1. Moving Average Differencing:

We can subtract the moving average from the data. This way generally helps in making the data stationary. In the airline data, when we do the differencing using moving average, we get the below graph.

Airline passenger data after differencing moving average

When we compute the rolling mean and standard deviation of this difference data, we get the following graph.

Moving average and standard deviation after moving average difference data

Now, the mean seems to be almost constant. When we run the dicky-fuller test, we get the following statistics

Results of Dickey-Fuller Test:
Test Statistic -3.151207
p-value 0.022988
#Lags Used 13.000000
Number of Observations Used 118.000000
Critical Value (1%) -3.487022
Critical Value (5%) -2.886363
Critical Value (10%) -2.580009
dtype: float64

Here, the p-value is less that the 5% critical values (0.05), so we can say with 95% confidence that the series is stationary.

2. Eliminating trend and seasonality by differencing:

We can also compute the difference in another way. Since there seems to be a trend, we would need to eliminate the trend to get a constant mean. We can do this by computing the difference between the number of passengers today and the previous time stamp(month here). By doing so, we get the following graph.

Rolling mean and standard deviation by differencing t and t-1

When we perform the Dickey-Fuller test, we get the following statistics.

Results of Dickey-Fuller Test:
Test Statistic -2.829267
p-value 0.054213
#Lags Used 12.000000
Number of Observations Used 130.000000
Critical Value (1%) -3.481682
Critical Value (5%) -2.884042
Critical Value (10%) -2.578770
dtype: float64

Here, the p-value is grater than the 5% critical values but less than the 10% critical values. So we can say with 90% confidence that the series is stationary. Compared to the previous approach, this approach gives us less confidence that the series is stationary. So, for this data the previous moving average differencing would work better.

3. Seasonal Decomposing:

While using the decomposing technique, the trend and seasonality are separated from the time series. Decomposing techniques are of 2 types- Additive and Multiplicative.

In additive approach,

Observed= Trend+Seasonality+Residual

In multiplicative approach,

Observed=Trend*Seasonality*Residual

Below is the graph for additive and multiplicative decompose. As you can see from the graph, the trend and seasonality are separated from the data. The remaining is the residual. We need to run the ARIMA model on the residual part of this data.

Additive vs Multiplicative decompose of airline data

When we check the residual part of this data for stationarity, we get the following results.

Results of Dickey-Fuller Test:
Test Statistic -7.590191e+00
p-value 2.543486e-11
#Lags Used 7.000000e+00
Number of Observations Used 1.360000e+02
Critical Value (1%) -3.479372e+00
Critical Value (5%) -2.883037e+00
Critical Value (10%) -2.578234e+00
dtype: float64

Now you can see that the residual part of the data is stationary with 99% confidence.

With any of the above techniques, we can convert any non-stationary data into stationary data and proceed to the next steps. The next step is to find the auto-correlation factor and partial auto correlation factor. We will talk about this in the next blog post.

Thanks for reading through. If you liked my blog, click the clap icon! Leave your comments below or contact me via LinkedIn.

--

--